Reputation: 441
I'm trying to use Winappserver on my Win7 PC.
I have added
session.cookie_domain =
session.use_cookies = 1
session.save_path = "c:\wamp\tmp"
to my PHP.ini file to fix an eariler $_SESSION[] index error problem but now down lower in the same php file I am getting another similar error:
Undefined index: php_g_decrypted_mysqlpw_string in C:\wamp\www\ac.php on line 61
Line 61: $php_mysqlpw_string = $_SESSION["php_g_mysqlpw_string"];
Is there another php.ini setting I need to add?
Thanks...
Upvotes: 0
Views: 2591
Reputation: 94642
The SESSION concept is clever but not magic.
When a user first connects to your site (s)he has NO SESSION.
When that user first causes a piece of your PHP code to run and the first session_start()
is executed in your code, a session array is created and then PHP looks to see if a session for this user already exists. If this is the first time through your code no previous session will exists
so an empty $_SESSION array
is created.
This is what is happening in your code.
So you either have to code your script so this situation can never happen, or code it to manage this situation i.e. an empty $_SESSION array or a session variable $_SESSION["php_g_mysqlpw_string"]
that has not yet been created.
So on all your examinations of a session variable ( array occurance ) you need to test for its existance and have a default value in mind.
So for example on your line 61, you should code something like:
$php_mysqlpw_string = isset( $_SESSION["php_g_mysqlpw_string"] ) ? $_SESSION["php_g_mysqlpw_string"] : '';
Or if you prefer to code it in long hand:
if ( isset( $_SESSION["php_g_mysqlpw_string"] ) ) {
$php_mysqlpw_string = $_SESSION["php_g_mysqlpw_string"];
} else {
$php_mysqlpw_string = '';
}
This says, if the session array contains the index named "php_g_mysqlpw_string" use that value otherwise it has not yet been set to a value and I should use a default, in this case I have assumed an empty string.
If you are not using a PHP Debugger then use this statement just after your execute the session_start()
or just before you attempt to use a value from the array, so you can see whats in the session array at the time you try and access it. This should display the arrays contents on the browser.
echo '<pre>' . print_r( $_SESSION, TRUE ) . '</pre>';
Upvotes: 1