print_r return BLANK PAGE - php

I have a weird problem, I am using print_r($obj) in Joomla YOOtheme ZOO extension and it returns a blank page. it just act as die() !
it should output the object but it does not.
Please note that print_r() is working fine with some other objects and variables.
I am using XAMPP on Windows.
Any help?
Upon executing print_r() and var_dump(), the page is just blank, no error, view source shows:
<html>
<head></head>
<body></body>
</html>
Error reporting is turned on.

It is posible that $obj is too big to load, and grabs a lot of memory after which the script stops to work.
Thanks

Is error reporting turned on?
If not add to your code:
ini_set("display_errors", "1");

If it's outputting nothing, $obj contains nothing. Try var_dump() instead. Also, make sure you're seeing all errors that PHP is producing:
ini_set('display_errors', 1);
error_reporting(-1);

Related

Insert Variable into file_get_contents from HTML form

I've used the answer given here (how do i insert a variable? from a form into a file_get_contents link) however, It is still not working for me.
But this is not working, I do not know why?
You need to place/assign your POST array and variable first, not after:
(Kind of like putting the horse after the wagon, as it were).
<?php
$code = $_POST['search'];
$json = file_get_contents("http://myurl.com/user=". $code);
$obj = json_decode($json);
?>
Because as it stands, you'd be getting an "Undefined index/variable..." notice, had you been checking for errors.
Add error reporting to the top of your file(s) which will help find errors.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
// rest of your code
Sidenote: Error reporting should only be done in staging, and never production.

Error reporting in PHP withi '.ini' files

So basically I have tried to setup an error reporting system that logs any PHP, HTML or any other error into a text file called 'errors.txt' located in a specific directory. However, the file is not being created.
Here is the code:
ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);
ini_set('log_errors',TRUE);
ini_set('error_log','/xampp/xampp-portable-win32-1.8.3-2-VC11/xampp/htdocs/EstateAgent/logs/errors.txt');
ini_set('display_errors',FALSE);
The errors are still be displayed to the user and they error log isn't being created inside of the directory specified.
I have also tried changing the standard values in my 'php.ini' file as suggested on other websites and I have still had no luck.
Any help would be greatly appreciated!
Thanks :)
For anyone who has similar problem - make sure you don't have any other error_reporting and ini_set in other files you use in your project. In those cases it may seem that error reporting is not working properly but in fact it this.
Try to change:
ini_set('log_errors',TRUE);
into
ini_set('log_errors','1');
and
ini_set('display_errors',FALSE);
into
ini_set('display_errors','0');
If it doesn't help, add at the very top beginning of your file:
<?php
error_reporting(0);
ini_set('display_errors','0');
echo $testVariable;
echo "Just testing";
?>
and check if any warning about this variable is displayed before "Just testing".
Now change above code into:
<?php
error_reporting(E_ALL);
ini_set('display_errors','1');
echo $testVariable;
echo "Just testing";
?>
and check if any warning about this variable id displayed before "Just testing".
As above 2 sample codes works as expacted, it's likely that those settings are change in other php files of user or php libraries used by user. You should scan your code and libraries code do track where changes are made and try to solve this issue either removing your code changing your desired reporting or commenting / setting properly (if there is such possibility in constructor or method) reporting in external library
You need to provide a fullpath for the 'error_log' property:
<?php
ini_set('error_log', 'c:/xampp/logs/php_error.log');
?>
You need to make sure that the following folder exists and is "writable": c:/xampp/logs/
If you're using Linux, then the fullpath will look like this: /xampp/logs/php_error.log
Also, use the following:
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
ini_set('log_errors', '1');
?>

Invisible Errors in PHP

Trying to figure out why a Wordpress site I moved is doing white screen of death.
Trying to turn on error dumping - but it isn't working. Absolutely nothing is showing up.
Here's sample code:
<?php
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);
$con = mysql_connect('localhost', 'groupasa', 'groupasa');
$selected = mysql_select_db("groupasa",$con)
Echo "Test";
?>
for a fatal error you can turn on errors in php code you have to turn them on in apache or htaccess level. You could also go and look in the error log for the errors.
Right click and check the source of your page, sometimes the html doesn't show the error but it's actually in the code.
Not sure if this is the case but hope it helps.
Try putting the Echo statement at the very top of the page and then an exit; if the echo displays then your PHP compiler is working fine and you know that the issue is with the code on the page.
next, add the missing semicolon at the end of mysql_select_db line
you could also check your PHP error logs.
Most times you can solve the 'white screen' by going into the database and using the following query to forcibly 'deactivate' all active plugins.
UPDATE wp_options SET option_value = '' WHERE option_name = 'active_plugins';
The core of WP is pretty solid, but it's the plugins and garbage that really mucks everything up.

error_reporting(0) throws 500 error

So - strange situation I got here.
The statement error_reporting(0); has been giving me a server 500 error.
However, error_reporting(1); works just fine..
And its killing me, too many warnings for some of my URL validators. What's up with this? Any idea on how this can be fixed?
First of all, I'm sorry if I behave "smartass", but I have to tell you that if there are warnings, you should consider to fix them instead of just reduce them to silence... :)
Junk PHP code let bad things happen, and you won't like it. I understand 80% of the PHP code around is junk, but really try to fix that library, if it's not huge.
We can however try to solve the problem if you just make a simple .php file, with only one line:
<?php
error_reporting(0);
?>
and test if it fires the error. If it doesn't, the problem is not caused by error_reporting, but just triggered by it, and there's some sick stuff going on elsewhere. :)
try error_reporting(E_ALL); and ini_set("display_errors","On"); and check the errors that occur. After you fix those, there shouldn't be any problem.
Good luck
Shai.
P.S. i would be guessing for almost 100% that you use Chrome, because for some reason chrome would sometimes just show its own error screen instead of showing error messages. So also try another browser just to check the errors.
error_reporting()'s value is defined with constants, so don't use direct value to set it.
If you had used the constants, you would have noticed that none of them have 0 as value.
If you want to report all errors, there is an exception to the rule : use the value -1 :
error_reporting(-1);
Source : http://us.php.net/manual/en/function.error-reporting.php
And consider fixing all warnings! (and even notices if possible)
Note : the -1 value is used to be sure that even if more error code are added, they are all included.

Unknown problem with PHP's XML parsing functions

I'm using a PHP4 implementation of SimpleXML, which uses the built-in xml_* functions from PHP 4. I have an odd problem that I'm unable to diagnose due to no error reporting on the server and not being able to turn on error_reporting.
I've modified the Parse() function to include this:
[stuff here to initialise the parser]
echo '<textarea rows="8" cols="50">', htmlspecialchars($this->xml), '</textarea>';
$parsed = xml_parse($this->parser, $this->xml) or die('error with xml_parse function');
The textarea displays the XML fine, and the XML itself is perfectly valid. But the page stops right after that and doesn't appear to call the xml_parse function, or output the 'die' message.
Should also add that this works fine on other pages, it just appears to be a problem with this particular page for some reason.
What could be happening here? Are there other ways to debug this?
Yes, you can debug this by adding this to your script:
error_reporting(E_ALL);
Thus will turn on error reporting.
Also, using ‘or die‘ only works if the function call before it returns a falsey value. In the event of fatal errors, it doesn't help.
Try to set the error reporting on and see what error comes though, it is likely there is some fatal error coming up:
ini_set('display_errors', true);
error_reporting(E_ALL);
Try getting the XML specific parser error message:
echo xml_error_string(xml_error_code($parser));
IIRC, these are not output by default no matter what your error reporting is set to.
Reference:
xml_get_error_code
xml_get_error_string
It seems that the problem was due to the XML being too big for the parser. Since we can't turn on error_reporting there was no way to get proper debugging info.
I decided to use a separate script the generate the HTML for the page, to avoid issues with the page going down occasionally.

Categories