iPhone web app, not storing cookie
I am working on a web app for the iOS. When the app is opened, it check's to see if the user has a cookie with the users email stored in it, then either lets the user proceed to the homepage, or redirects the user to the authentication page.
This works perfectly when using safari. The problem I am experiencing occurs only when the app is stored on the home screen. It seems like the home-screen web app deletes the cookie right when the user exits the application.
Any advice on forcing the app to st开发者_运维技巧ore that cookie would greatly appreciated.
Thanks, Peter
The reason its not sticking around is because the timeout parameter is not set.. if it is blank or 0, then the cookie will be deleted when the uiwebview is closed..
so you can do as the other poster suggested..
setcookie("TestCookie", $value, time()+3600, "/");
,but the reason that works is because of the timeout value being set
There is a parameter path
for the setcookie
function which you might want to use so that cookie is created just about from any page:
The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.
So try adding '/'
as the fourth argument to the setcookie
function eg:
setcookie("TestCookie", $value, time()+3600, "/");
In case it helps anyone else; I was saving the cookie via an unload
event, which worked fine on desktop, just not on the iPhone.
Nothing to do with cookies, just had to save-as-I-go...
You are not able to get the session on the iPhone because cookie is disabled.
Please go to Safari>Settings>Accept Cookies in your iPhone and set it to accept from Visited.
Then you will be able to create the session in PHP.
精彩评论