ygrouk
04-17-2003, 10:17 PM
Hi guys
i want to protect an admin area of a website. how would i do this.
what do you reccomend...sessions or cookies??
how would i start a session / cookie??
could you please reply with some code?
cheers
pete:thumbsup:
missing-score
04-17-2003, 10:31 PM
I would do both.
setcookie('username','matt',time()+3600);
// Sets a cookie called username, with the value matt, that lasts
// for 3600 seconds after the current time.
// To get the value of that cookie, use...
echo $_COOKIE['username']; // Displays the value matt.
session_start();
// Starts a PHP session
$_SESSION['user'] = 'matt';
// Sets the session variable user, with the value matt.
echo $_SESSION['user']; // Displays the value matt.
// You could check someone being logged in by:
if(isset($_SESSION['admin']))
{
// Do admin
}
else
{
echo "Do you really think im stupid?";
}
Hope that helps you.
Lets hope krycek turns up with his so_secure scripts. :D
ASAAKI
04-17-2003, 10:32 PM
http://codingforums.com/showthread.php?s=&threadid=17023
a 3-page thread to hopefully help you:)
don't forget this site's got a Search feature :p;)
Nightfire
04-18-2003, 03:20 PM
session_start();
// Starts a PHP session
$_SESSION['user'] = 'matt';
echo $_COOKIE['username']; // Displays the value matt.
Would have to be that way round, or you'll get an error saying headers already sent or something daft
missing-score
04-18-2003, 03:39 PM
They were meant to be separate examples, I should have made that clear. Thanks Nightfire.