I just have a simple session start and assigned a session variable on login. However when I switch pages, the session variable does not stick in Firefox. I can still see the session is there but just not the variable. In IE7, IE8, Chrome, and Safari, it works and sticks. What is happening in Firefox and how can I fix it?
Here is a snippet of the code.
session_start();
if ($_POST['login']) :
$_SESSION['loggedin'] = 1;
endif;
Seems to be a client side issue. Probably Firefox does not send the session cookie.
Related
I'm having a problem with session not persisting after a redirect on my website when it's not being browsed through incognito. I've tried replacing the code with a simple script that sets the session variable "test" with "asdasd".
session_start();
session_regenerate_id(true);
$_SESSION['test'] = 'asdasd';
header("Location: ../results.php");
session_write_close();
The results page is as follows
session_start();
session_regenerate_id(true);
var_dump($_SESSION);
session_write_close();
But whenever I try to run the script that sets the session, the data does not persist on to the results page. But when I tried testing it in Chrome's incognito mode, it works. I've tried clearing cache and restarting the browser, the data is still not persisting. What could be the reason for this?
Edit: I'll happily provide any information regarding the configurations if it's going to help
It could be that the Set-Cookie header isn't process if the Location header is found in the same response.
It is browser-dependent, so it may be hard to tell.
My session is not working in chrome and safari browser and working in firefox. Can anyone explain why this is happening ?
<?php
session_start();
$sessionuser=$_SESSION['user'];
?>
If I print_r($sessionuser) it is not working in chrome or safari browsers bu working in firefox
I'd say that, other than your code has parsing errors, that you would have to use session_start(); before you use $_SESSION[]
It might be that you have forgotten an old session cookie in firefox. I think it is possible to check this with firebug.
Also check da5id's answer, it will fix the parsing error.
Try this
session_start();
$sessionuser=$_SESSION['user'];
echo $sessionuser;
try the following. It works on my chrome in LINUX.
session_start();
$_SESSION['user'] = "hithere";
$sessionuser=$_SESSION['user'];
print_r($sessionuser);
You have to check your browser cookie. Your session not a set If cookie is disabled. You have to go in browser setting and check cookie setting.
Just try
In my case I just reset chrome browser
Go to chrome://settings/ then click advanced then reset
Just clear the cookies in your Google Chrome in the Setting.
Privacy and Security -> Cookies and other site data -> See all cookies and site data
Search by the domain name or IP and delete the existing cookies.
I am pulling my hair out on this. It works on chrome and Firefox but not in safari. What am I doing wrong?
I am setting up a temp cookie and then check if it is set or not. When I clear all the cookies from safari, and then I run this file, it thinks that cookie is still there.
here is the code
setcookie("testcookie", 'cookiesetting temporary');
if(isset($_COOKIE['testcookie'])){
echo "cookie set":
}else{
echo "no cookie set";
}
In safari only, after disabling the cookies and removing all the cookies , when I run the code above, it still echoes cookie set.
Just to make sure, I also looked in the dev tools in safari under resources and I see no cookie there.
What am I missing here?
I had the same problem with Safari (couldn't unset a cookie).
You should solve setting the path
setcookie('testcookie', 'cookiesetting temporary', time()+3600, '/path/'); // set
setcookie('testcookie', '', time()-3600, '/path/'); // delete
Hope this works ;)
Simply clearing them client side isn't the proper way to test this .. Have you tried actually "unsetting" the cookie Server Side?
I have a simple login page. Everything works fine in Mozilla and IE. When I try to login in Safari, the session is empty, just a white page. If i check the session id, it gives me the id, but shows nothing else.
echo session_id();
If I copy the page URL and then go to another page, and paste the URL, the browser shows the page.If I refresh it, it disappears again.(but it always shows the session id)
Everything works in Mozilla and IE.
update: Thank you all for your help, yes, it was something on the page, I tried a simple page and it worked. Learned my lesson. Thanks again!
sessions in php use a session cookie, so check this:
is your safari browser allowing cookies?, by default the session cookie it's called "phpsessionid"
are you sure that you used a "session_start()"? (and its better if you use a "session_name()" too)
i hope this helps
Just check Safari's cookie policy.
It looks like your browser just do not send a session id cookie back.
If i check the session id, it gives me the id
It is not session id itself what ou have to check.
But rather if session id is the same as before
if it's the same, there is something with your code.
You have to start to debug it.
Start from running a test file with this code:
<?php
session_start();
if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
echo "Counter ".$_SESSION['counter']++." раз.<br>
reload";
if it works, make it
<?php
session_start();
if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
echo "Counter ".$_SESSION['counter']++." раз.<br>
reload";
and find a way to watch an HTTP interchange protocol. That's most important thing - to see what cookies going from server and back. I know no tool for safari but there is ought to be one
I have a simple code to check counter.
session_start();
if(!isset($_SESSION['footerimg']) || empty($_SESSION['footerimg']) ){
$_SESSION['footerimg']='sunset.jpg';
echo $_SESSION['footerimg'];
}
But all time this is printing "sinsut.jpg" when is page is loading my session is being destroy.
This is running well in FF but problem happeninig with IE and chrome.
This is most definitely because IE8 doesn't accept cookies from localhost. Check this question.