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.
Related
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');
?>
Please see the below code this is work perfectly in PHP. Can anyone explain me how this code works. Because in the below code i have declared $caregory_id without semicolon and without any value deceleration. Then also this code work perfectly without any error and var_dump($category_id) returns me an null value.
How php execute this code without semicolon??
<?php
$category_id= //No semicolon
var_dump($category_id); //returns NULL
?>
It works because PHP treats your code like this:
$category_id = var_dump($category_id);
The return value of var_dump() gets assigned to $category_id. Undefined variables in PHP are implicitly set to null, which is what you see in the output of var_dump(). However, you would also get a notice about $category_id not being defined; if you don't see it, you should use this code in your script:
error_reporting(-1);
ini_set('display_errors', 'On');
These settings are also recommended during development as they can catch issues that would otherwise have gone unnoticed on a production machine.
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.
I'm trying to use PHP variables to load certain elements from a XML file, so if index.php?id=1 is loaded it would pull the information from $projects->project[1]. No errors come up in the following code, but nothing gets displayed. Any help is appreciated :)
<?php
$projects = simplexml_load_file('portfolio.xml');
$id = $_GET["id"];
echo $projects->project[$id]->title;
?>
It may be one of two things (or both):
echo doesn't show anything if there is nothing to show.
there has been an error, but your server is not reporting it, try checking logs if there are any. Also check if error reporting is enabled.
That said, try using print_r or var_dump to get the data.
print_r($_GET); die;
to check if u are getting the data in get or not .
error_reporting(~0); // show me everything i do wrong
$projects = simplexml_load_file('portfolio.xml');
var_dump($projects); // make sure $projects actually has something
var_dump($_GET['id']); // are you getting the request data?
$id = (int) $_GET["id"]; // cast to int for good measure
// i'm assuming it's numeric, don't if its not
echo $projects->project[$id]->title; // still not showing anything?
var_dump($projects->project[$id]->title); // dump it for good measure
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);