Differeneces between session and cookie
Posted: Thu Nov 04, 2004 11:47 am
hello all, this may be a stupid question, but I'm curious as to the differences/advantages/disadvantages to using session vars instead of cookies?
I currently build all of my php sites that require logins etc to use cookies and I'm wondering if I should be using some kind of session vars instead.
for example, I create a file called app.php and in that file I have something like this:
I include that file on all pages that I want to be part of my "application" so that if a user tries to hit that page and they're not "logged in" it redirects them to a log in page where I check their credentials..if the credentials pass, I set the cookie for them.
Should I be doing this same thing in some form of session format? If so, could someone please advise as to how sessions work exactly?
thx,
Burrito
I currently build all of my php sites that require logins etc to use cookies and I'm wondering if I should be using some kind of session vars instead.
for example, I create a file called app.php and in that file I have something like this:
Code: Select all
<?php
if(!isset($_COOKIE["loggedin"])){
$location = "http://".$_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"].(isset($_SERVER['QUERY_STRING']) ? '?' . $_SERVER['QUERY_STRING'] : '');
?>
<script>
location = "http://www.myserver.com/login/login.php?message=notloggedin&ol=<?=urlencode($location);?>";
</script>Should I be doing this same thing in some form of session format? If so, could someone please advise as to how sessions work exactly?
thx,
Burrito