PHP header location - not displaying error? - wamp

When I echo something before header("LOCATION: page.php"); - I expect to show an error but it didnt, it just redirect to that page. What gone wrong?
Example:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo "Hello";
header("LOCATION: page.php");
?>
In the php.ini
output_buffering = off
error_reporting = E_ALL
display_errors = on
I am using Wamp, PHP 5.3.0

var_dump(ini_get('output_buffering'));
and what about this one
var_dump(ob_get_status(1));
?

Related

How to convert raw cookie into Netscape jar cookie and save to file?

I want to pass a cookie file to youtube-dl coming from a browser extension. The extension sends cookie in raw format i.e. like VISITOR_INFO1_LIVE=_SebbjYciU0; YSC=tSqadPjjfd8; PREF=f4=4000000
But youtube-dl takes netscape jar format cookies (as far as I know).
If I put the raw text cookie in a file and pass it to --cookies=file.txt argument youtube-dl raises an exception.
I cannot manage to to convert my raw cookies to jar cookies and save to a file in the disk. I have searched for a solution but did not find any acceptable solution.
I had very similar problem to convert "curl" cookies into wget one ...
Netscape CookieJar format is straight forward see *
so I took few minutes to write a quick perl script and generate a cookiejar
here is the code (downloadable here)
#!/usr/bin/perl
# usage
# perl cookiejar.pl {{url}} '{{cookie-string}}'
use YAML::Syck qw(Dump);
my $expires = $^T + 86400;
my $path = '/';
my $url = shift;
my $cookies = shift;
printf "--- # %s at %u\n",__FILE__,$^T;
my $domain;
my $p = index($url,'://')+3;
my $l = index($url,'/',$p);
$domain = substr($url,$p,$l-$p);
my $dots = () = $domain =~ /\./g;
printf "dots: %s\n",$dots;
if ($dots > 1) {
$domain = substr($domain,index($domain,'.'));
} else {
$domain = '.'.$domain;
}
printf "domain: %s\n",$domain;
printf "url: %s\n",$url;
local *F; open F,'>','cookiejar.txt' or warn $!;
print F <<EOT;
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file! Do not edit.
# domain: $domain
# url: $url
EOT
my #cookies = split'; ',$cookies;
printf "--- %s...\n",Dump(\#cookies);
foreach my $cookie (#cookies) {
my ($key,$value) = split('=',$cookie);
if (! $seen{$key}++) {
# domain access path sec expire cookie value
printf F "%s\t%s\t%s\t%s\t%s\t%s\t%s\n",$domain,'TRUE',$path,'FALSE',$expires,$key,$value;
}
}
close F;
print "info: cookiejar.txt created\n";
printf "cmd: wget --load-cookie-file cookiejar.txt --referer=%s -p %s\n",$domain,$url;
printf "cmd: youtube-dl --cookie cookiejar.txt -referer %s %s\n",$domain,$url;
exit $?;
1; # $Source: /my/perl/scripts/cookiejar.pl $
you run it as followed :
perl cookiejar.pl https://example.com/ 'cookie1=value1; cookie2=value2'
note:
You might need to install YAML::Syck with
cpan install YAML::Syck
or just comment out the Dump() call and the use YAML::Syck line.

Can't enable phar writing

I am actually using wamp 2.5 with PHP 5.5.12 and when I try to create a phar file it returns me the following message :
Uncaught exception 'UnexpectedValueException' with message 'creating archive "..." disabled by the php.ini setting phar.readonly'
even if I turn to off the phar.readonly option in php.ini.
So how can I enable the creation of phar files ?
I had this same problem and pieced together from info on this thread, here's what I did in over-simplified explanation:
in my PHP code that's generating this error, I added echo phpinfo(); (which displays a large table with all sort of PHP info) and in the first few rows verify the path of the php.ini file to make sure you're editing the correct php.ini.
locate on the phpinfo() table where it says phar.readonly and note that it is On.
open the php.ini file from step 1 and search for phar.readonly. Mine is on line 995 and reads ;phar.readonly = On
Change this line to phar.readonly = Off. Be sure that there is no semi-colon at the beginning of the line.
Restart your server
Confirm that you're phar project is now working as expected, and/or search on the phpinfo()table again to see that the phar.readonly setting has changed.
phar.readonly can only be disabled in php.ini due to security reasons.
If you want to check that it's is really not done using other method than php.ini then in terminal type this:-
$ php -r "ini_set('phar.readonly',0);print(ini_get('phar.readonly'));"
If it will give you 1 means phar.readonly is On.
More on phar.configuration
Need to disable in php.ini file
Type which php
Gives a different output depending on machine e.g.
/c/Apps/php/php-7.2.11/php
Then open the path given not the php file.
E.g. /c/Apps/php/php-7.2.11
Edit the php.ini file
could do
vi C:\Apps\php\php-7.2.11\php.ini
code C:\Apps\php\php-7.2.11\php.ini
[Phar]
; http://php.net/phar.readonly
phar.readonly = Off
; http://php.net/phar.require-hash
phar.require_hash = Off
Save
Using php-cli and a hashbang, we can set it on the fly without messing with the ini file.
testphar.php
#!/usr/bin/php -d phar.readonly=0
<?php
print(ini_get('phar.readonly')); // Must return 0
// make sure it doesn't exist
#unlink('brandnewphar.phar');
try {
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
} catch (Exception $e) {
echo 'Could not create phar:', $e;
}
echo 'The new phar has ' . $p->count() . " entries\n";
$p->startBuffering();
$p['file.txt'] = 'hi';
$p['file2.txt'] = 'there';
$p['file2.txt']->compress(Phar::GZ);
$p['file3.txt'] = 'babyface';
$p['file3.txt']->setMetadata(42);
$p->setStub('<?php
function __autoload($class)
{
include "phar://myphar.phar/" . str_replace("_", "/", $class) . ".php";
}
Phar::mapPhar("myphar.phar");
include "phar://myphar.phar/startup.php";
__HALT_COMPILER();');
$p->stopBuffering();
// Test
$m = file_get_contents("phar://brandnewphar.phar/file2.txt");
$m = explode("\n",$m);
var_dump($m);
/* Output:
* there
**/
✓ Must be set executable:
chmod +x testphar.php
✓ Must be called like this:
./testphar.php
// OUTPUT there
⚠️ Must not be called like this:
php testphar.php
// Exception, phar is read only...
⚠️ Won't work called from a CGI web server
php -S localhost:8785 testphar.php
// Exception, phar is read only...
For anyone who has changed the php.ini file, but just doesn't see any changes. Try to use the CLI version of the file. For me, it was in /etc/php/7.4/cli/php.ini
Quick Solution!
Check:
cat /etc/php/7.4/apache2/php.ini | grep phar.readonly
Fix:
sed -i 's/;phar.readonly = On/;phar.readonly = Off/g' /etc/php/7.4/apache2/php.ini

Perl Oneliner Regex

I need to log results from a file to the screen.
cat logfile.txt
=====================Installing Oracle========================
*** ERROR[Install023] Oracle is already installed in $VOL1.
Alert: There might be an issue, Please check!
=============================================
=====================File Set verification========================
Filesystem State 512-blocks Used Avail Capacity Mounted on
HOME STARTED 143372688 119516872 23855816 83% /home
BIN STOPPED - - - - /nfsT/nfsdata/common
ROOT STARTED 143372688 119516872 23855816 83% /
TEMP STARTED 143372688 118402344 24970344 83% /tmp
The Filset for home directory looks Ok.
The Filset for root directory looks Ok.
=============================================
I am doing:
perl -0777 -nle 'print $2 "\n" while m/^(={21})([\w\s]+)(+={24})/gm' logfile.txt
But it is not giving any result.
The out put needs to be.
Installing Oracle..... Alert
File Set verification.....Ok!
It's not clear what all the possible reasons for an alert could be, but the following works for your sample:
perl -ne 'undef $err, print "$1 ..." if /^={21}([^=]+)={24}/;
$err = 1 if /ERROR/;
print $err ? "Alert" : "Ok!", "\n" if /={45}/'

How can i perform a keyword search for all the public feeds in facebook via FB api?

A Keyword search which helps to give me all the recent feeds.
I found the graph api - search
https://developers.facebook.com/docs/reference/api/examples/
but i dont know to use them!
all i tried was
$keyword = $_POST['keyword'];
$graph_url = "https://graph.facebook.com/search?";
$graph_url .= "&type=post";
$graph_url .= "&q=$keyword";
$results = file_get_contents( $graph_url );
$json = json_decode($results);
foreach($json->data as $show ) {
echo $show->from->name . "<br />";
echo $show->message . "<br />";
echo $show->created_time . "<br />";
echo "<hr>";
}
Stilll i get errors like
Warning : failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden

[file-get-contents]: failed to open stream

I have the correct access_token, but when I call file_get_contents, I receive the following error:
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.1 400 Bad Request in..
Pasting the echo $fql_query_url in the browser gives the correct result?
Is it an encoding problem? I ask because other fql queries work fine. Here's the offending code:
<?php
require_once('facebook.php');
//GET access token
echo $uid = $facebook->getUser();
$access_token = $facebook->getAccessToken();
echo '<br>';
// Run fql query
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q=SELECT page_id from page_admin WHERE uid='.$uid.''
. '&access_token=' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
//display results of fql query
echo '<br><pre>';
print_r("query results:");
print_r($fql_query_obj);
echo '</pre>';