PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
hey all,
i am making use of php $_SESSION[]; the problem i am having that i cannot find any solid documentation on is the session variables are randomly being destroyed or reset. Randomly moving from page to page or reloading the same page all the session variables i set on the site will be reset. Any ideas on what may be causing this? is this a server thing, is it my browser; let me know what any of [s]u[/s] you would need to trouble shoot this with me.. thanks in advance...
Are you getting a session cookie? Are you calling session start before output on every sessioned page? When you say the session data is reset do you mean the session array is empty?
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i am using session cookies, but not using $_COOKIE[], i'm using $_SESSION[]
Yes, i am including the same sessioncheck.php file at the very top of every page:
by session data reset, i mean that all the session variables and arrays that i set no longer have values. the above code makes use of a single userName; i also have arrays I'm using for items in a shopping cart. all the variables and session arrays i use go empty =="" at the same time. and whats weird is how random it is, i could reload the same page a few times and it'll reset...
Help!!! the sooner i can get this resolved the better!!!!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Save the following two scripts as session-test-page1.php and session-test-page2.php. Place them on the server you are having trouble with. Load page1 then follow the links posting back what is echoed on each page please.
<?php
//Session start
session_start();
//Set session vars
if (!isset($_SESSION['username']) && !isset($_SESSION['password']))
{
$_SESSION['username'] = 'testusername';
$_SESSION['password'] = 'testpassword';
//header('Location: session-test-page2.php');
//exit;
}
else
{
// Quick error checking
echo '<pre>'; var_dump($_SESSION); echo '</pre>';
echo '<p>You user name is already set to ' . $_SESSION['username'] . '</p>';
echo '<p>And your password is already set to ' . $_SESSION['password'] . '</p>';
}
if (isset($_GET['clear']))
{
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();
echo '<p>Even though you see the information above, the session has already been terminated.
<a href="' . basename($_SERVER['SCRIPT_FILENAME']) . '">Refresh the page</a> and you will see nothing as the page sets the session vars again.</p>';
}
echo '<p><a href="session-test-page2.php">Click here for page 2</a></p>';
echo '<p><a href="?clear=true">Click here to clear the session data</a></p>';
?>
<?php
//Session start
session_start();
// Quick error checking
echo '<pre>'; var_dump($_SESSION); echo '</pre>';
// Echo session vars
echo '<p>You user name is ' . $_SESSION['username'] . '</p>';
echo '<p>And your password is ' . $_SESSION['password'] . '</p>';
echo '<a href="session-test-page1.php">Click here to go back to page 1</a>';
?>
Man, that is tricky. What were the circumstances leading up to the clearing of the session array? Specifically, how did you wait before loading that page that showed empty? Did you move around very fast from click to click? Etc...