Jump to content


Photo

Cookies does no work after first time


  • Please log in to reply
4 replies to this topic

#1 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 10 September 2006 - 04:15 PM

Hi guys!

I have a page (lets say index.php) where user choose language
On very top of it there is such php code:

<?php
if ( $_COOKIE['langSet'] == 'english')
header("Location: http://www.mysite1.com");
elseif ( $_COOKIE['langSet'] == 'german')
header("Location: http://www.mysite2.com");
?>

If choosing, for example, english, he would be sent to www.mysite1.com/main.php
where on very top is a code:

<?php
$lang = 'english';
setcookie("langSet", $lang, time() + (86400*30), "/");
?>

Idea is that next time user goes to the page where he must choose language, he is
redirected to the appropriate one he choose before.

Problems:
1) How do I make cookie not to dissapear after browser is closed?
2) How do I make possibility for user to still be able to go back to language selection page
after he choose language and the cookie is set? By now I have made a 'middle' page where cookie
is unset after what user gets redirected to language selection page. Is there another way?

3) How do I refresh the page which sets the cookie, so it's value can be used immediately?

Oh please... I am googling around trying to find answers, but can't find a solution on this one..
at least one that works :(

Thank you guys in advance!

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 10 September 2006 - 04:33 PM

Cookies dont work the first time, this information is stated on the php website

Cookies Send HTM headers
To view the cookies, you need to refresh your page
Tell me the problem, I will try tell you the solution

#3 ramzess

ramzess
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 10 September 2006 - 04:39 PM

So what you are saying is that there is no way to refresh page usinh php code so user don't have to press F5?

I can't believe it. So where is the point in using cookies for matter I have? No point? :(

#4 radalin

radalin
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 10 September 2006 - 04:44 PM

1)While you set the expire time, you select that cookies do not dissapear even they close the browser. They are kept, for your use till they expire.
2)Put a link which will return the user to the language selection part and add a onclick event on the link which will set do something like document.cookie = "langSet = ''; expires = 0;" and then will redirect user to the language selection page. with setting expires = 0 you say the cookie destroy itself after that second. (It could be " : " instead of " = " by the way)
3) you can use a javascript to refresh the page
Roy Simkes
Yet Another Parkyeri Developer

#5 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 10 September 2006 - 05:03 PM

refresh in php
Header("Location: ".$_SERVER["PHP_SELF"]);

Refresh in HTM
<meta http-equiv='refresh' content='5' />
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users