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!
I try to read the cookie like this : i also printed out what is going in to the array with print_r($_COOKIES) which tells me :
"Array ( [PHPSESSID] => 9876bfe982aec20028ca3f6ed61daceb )" But only after i refresh that page(does it come ebcause of session start)
That should set a cookie with the name "in" and a value of "TRUE", and an expiry time 1 hour in the future. Note that 'TRUE' is just a word and not a boolean value. You could also do the following:
In this case, your cookie name 'in' would have a value of 1.
If you're using Firefox, get the Web Developer extension. Among other things, you can view cookies and their values immediately as they are set by a given page.
ok,thanks man. so to acces it on another page,i would just use the $_COOKIES['in'] in order to check it? and if i still use the value true, i would do osmething like this:
if($_COOKIE['in'] == 1 ) {
echo '<font color=green>You are logged in,please go <a href="http://avi.aerohostale.com/admin/main.php">Here</a> to see the main page.</font>';
}
else {
if(($you == '***') && ($me == '***')) {
setcookie('in',TRUE,time()+3600,"/");
echo 'You are in,please go <a href="http://avi.aerohostale.com/admin/main.php">Here</a>';
}
this is how im tryin and the print_r($_COOKIE) is still only givin nothing now because i removed using sessions. I login,my script says im in,then i clik the main link and it says im not in.The webdeveloper util tells me this :
Name in
Value 1
Host xxx.yyy.zzzzzz.com
Path /admin
Secure No
Expires Saturday, June 03, 2006 3:24:30 PM
if($_COOKIE['in'] == 1 ) {
echo '<font color=green>You are logged in,please go <a href="http://avi.aerohostale.com/admin/main.php">Here</a> to see the main page.</font>';
}
That's fine, checking for TRUE or 1 makes no real difference since they are both "true" in this case.
if(($you == '***') && ($me == '***')) {
setcookie('in',TRUE,time()+3600,"/");
echo 'You are in,please go <a href="http://avi.aerohostale.com/admin/main.php">Here</a>';
}
this is how im tryin and the print_r($_COOKIE) is still only givin nothing now because i removed using sessions. I login,my script says im in,then i clik the main link and it says im not in.The webdeveloper util tells me this :
Name in
Value 1
Host xxx.yyy.zzzzzz.com
Path /admin
Secure No
Expires Saturday, June 03, 2006 3:24:30 PM
All of the details provided by the utility appear to be correct and the cookie is properly set. Where is print_r($_COOKIE) being called? If it's on the page which initially set the cookie, it will be empty until a new page request is made (or forced with header()). What's the code at /admin/main.php?
<?PHP
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Main Admin Page</title>
</head>
<body>
<?PHP
print_r($_COOKIE);
if($_COOKIE['in'] != 'TRUE') {
echo 'You are not logged in,please go to <a href="***">Here</a> to login';
}
else {
echo 'Welcome to the admin page. This is the basic layout so far.<br>Please use one of the links below to do what you would like to.';
echo '<br>';
echo '<br>';
echo '<a href="***">Add An Offer</a>';
echo '<br>';
echo '<a href="***">View Pending and Completed Offers</a>';
echo '<br>';
echo '<a href="***">Make a Payment to Someone</a>';
//}
?>
</body>
</html>
i don't really understand why you used that "session_start();" at the beginneing... but since you used it, you might as well use sessions for your auth: #_SESSION['in']=true;