safari cookie issue - php

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?

Related

Lost PHP sessions with Internet Explorer and Lighttpd webserver

I'm having trouble with PHP sessions with IE11 and Edge (Windows 10) connecting to a Lighttpd web-server.
Consider this code:
if (PHP_SESSION_NONE === session_status()) {
session_start();
}
$x = isset($_SESSION['bob'])? $_SESSION['bob'] : 'nothing';
echo 'The Session has started, bob is set to ' . $x .'<br/>';
$_SESSION['bob'] = 'hope';
echo 'The Session ID is ' . session_id() .'<br/>';
When I browse to test.php - containing the above code - using Chrome, shut down Chrome, reopen Chrome, and then browse back to this page it displays:
The Session has started, bob is set to hope
The Session ID is 6d2jbpmrrlrqt96h2nd19ua160
IE11 and Edge will however display:
The Session has started, bob is set to nothing
The Session ID is 35k87vgdt7t41q4lkphq815hq1
Why are IE11 and Edge dropping the session?
**This problem is also happening on WAMP Apache, so although I've seen references to Lighttpd being a potential cause (Internet Explorer, jQuery, session lost php, ) I'm not convinced.
** Also, Fiddler shows a new session ID with each IE\Edge connection.
Any thoughts?
Adding a cookie lifetime to the session using session_set_cookie_params like:
if (PHP_SESSION_NONE === session_status()) {
session_set_cookie_params(60*60*24*7);
session_start();
}
solves the problem: the session persists after the browser is closed and reopened.
The php documentation http://php.net/manual/en/session.configuration.php#ini.session.cookie-lifetime states:
session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to
http://php.net/manual/en/function.session-set-cookie-params.php
Which raises the question of why it works in Chrome (45.0.2454.101 m)? But that's another question...
Footnote: Although the max lifetime value for a session cookie would appear to be 2,147,483,647 the max value for "session.gc_maxlifetime" seems to be 65535; and setting lifetime to larger values stopped my sessions from working.

session not working in chrome and working in firefox

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.

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.

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