session not working in chrome and working in firefox - php

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.

Related

PHP Session issue on browser close

Here running into problem where I have requirement to clear user session when closing the browser. I have tried all the various option like setting session.cookie_lifetime=0 or session_destroy on browser close using onunload function. But nothing seems to destroy session when I open the browser next time.
I just googled a bit and I saw that in Chrome browser there is setting called ''Allow local data to be set' that has to be changed to 'Keep local data only until I quit my browser', when I do this it does not retain my session.
The real problem is I cannot ask each user to change the settings of the browser and then it would work accordingly, is there a way I can handle it in code using php or javascript. Any option is fine.
Have you tried checking for both cookie and session when your page loads? Something like this:
1) destroy cookie on unload
2) on page load check for both
if(isset($_COOKIE['user'] && $isset($_SESSION['user'] {
//user is logged in
} else {
//your code should fall here after user closes browser
//because the cookie doesn't exist anymore. Maybe you can even destroy the session too
[session_destroy();]
...
...
}

chrome drops sessions

Hi
I have problems with Google Chrome, while developing a PHP website.
I start a session, and store a flag inside it. But when I reload the page, the session value is not recognized.
What can be wrong? Thanks for reply.
session_start();
if (isset($_SESSION['chrome'])) {
echo 'SESSION OK';
}
else {
$_SESSION['chrome'] = 'yes';
}
This is simple code, but it doesn't work...
I had the exact same problem with Chrome not persisting php sessions on a login system. Found the following article: https://secure.kitserve.org.uk/content/php-session-cookie-problems-google-chrome-and-internet-explorer which says:
When testing a local site in Chromium, you must either access it via IP address (e.g. 127.0.0.1) or set the cookie domain parameter to the empty string.
I hope this helps.
I had exact same problem, but on IIS and ASP.Net Mvc. An F5 would make the session recover, but moving to another page caused the problem again. I posted the answer for another SO question. Try it out and see if works.
I think the answer to this is to use session_name before session_set_cookie_params. For example...
session_name('MySession');
session_set_cookie_params( 3600*24, '/', $_SERVER['HTTP_HOST'], is_https() );
session_cache_expire(60*24); // cache expire 60 mins
Check to see if you deactivated cookies in your browser.

safari cookie issue

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?

Firefox drops the session variable

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.

php session doesn't work in safari

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

Categories