Which will be placed at first in a script session or cookie?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Which will be placed at first in a script session or coo

Post by social_experiment »

1skazi wrote:If i use session and cookie in the same script then which will be placed at first ?
You could end up with 2 cookies if your session uses cookies to keep track of sessions.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Which will be placed at first in a script session or coo

Post by flying_circus »

1skazi wrote:If i use session and cookie in the same script then which will be placed at first ?
Is it a valid code:

<?php session_start(); setcookie("user", "Roger", time()+3600); ?>
<html><body>
<?php
$_SESSION["name"]="Jone";
echo $_SESSION["name"]."<br/>";
echo $_COOKIE["user"];
?>
</body></html>
My money is on $_SESSION, because $_COOKIE won't be able available until the next page request.
Post Reply