I am having an issue with the session variables.
I am having a simple signup php page that uses ajax calls to verify username and email address if they already exist. It also has an ajax image uploader that gives a preview of the selected image.
Now this is how I am setting the session variable :-
session_start();
session_unset();
$_SESSION = array();
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
session_start();
$_SESSION['avurl'] = $filename;
$filename is valid as it is echoed in the above code just after this snippet.
In the page where I need to use this session variable I have this :-
session_start();
$av_url = $_SESSION['avurl'];
Now the weird thing is that whenever this runs the first time the session variable doesn’t have any value. But the second time it works.
How I came to check this is that I created a test.php which just echos $_SESSION[‘avurl’] and the first time it never shows anything but the second time it does.
What I figured out from this is that once it echoes this session variable it starts working to store the value.
And all that code that I am using to set that variable is edited from just :-
session_start();
$_SESSION['avurl'] = $filename;
to that as this also didn’t work and I thought that this could be a problem with already existing sessions.
Thankyou
Hope this is enough information for solving my problem !!
This code delete Your session… Why You doing this?