We are using cookies to store usernames that are logged on. On the top of each members page is the following:
<?php if (!isset($_COOKIE['cookie'])) die ("You are not logged in"); ?>
If the cookie is set then the pages loads. If it doesn't then the "die" is loaded. This works just fine. BUT I would like to forward the visitor to another page if the cookie is NOT present. I have tried different ideas in the die section of this line but I can not get anything to work. Any ideas on how I can do this?
Are you a Google Analytics enthusiast?
Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE!

www.CustomReportSharing.com
From the folks who brought you High Rankings!
More SEO Content
International SEM | Social Media | Search Friendly Design | SEO | Paid Search / PPC | Seminars | Forum Threads | Q&A | Copywriting | Keyword Research | Web Analytics / Conversions | Blogging | Dynamic Sites | Linking | SEO Services | Site Architecture | Search Engine Spam | Wrap-ups | Business Issues | HRA Questions | Online Courses
Checking For Cookies
Started by
Gatorhardware
, Jan 24 2005 11:52 AM
3 replies to this topic
#1
Posted 24 January 2005 - 11:52 AM
#2
Posted 24 January 2005 - 12:29 PM
Okay I found one way. I check the cookie for a string and if it does not match then I use a META REFRESH to the login screen.
<? $cookiedata = $HTTP_COOKIE_VARS["cookie"]; ?>
<? if ($cookiedata == "") { ?>
<meta http-equiv="REFRESH" content="0; URL=http://www.mydomain.com/login.php">
<? } else { ?>
HTML STUFF
<? } ?>
Any other ideas?
<? $cookiedata = $HTTP_COOKIE_VARS["cookie"]; ?>
<? if ($cookiedata == "") { ?>
<meta http-equiv="REFRESH" content="0; URL=http://www.mydomain.com/login.php">
<? } else { ?>
HTML STUFF
<? } ?>
Any other ideas?
#3
Posted 24 January 2005 - 01:02 PM
Try something like this BEFORE you send any output to the browser:
Note... you do not need to wrap php tags: <? ?> around every line of your script. Just at the start and end of a BLOCK of PHP. It is inefficient to escape in and out of php like that. Only leave php mode if you are outputting a block of html.
CODE
<?
$cookiedata = $HTTP_COOKIE_VARS["cookie"];
if ($cookiedata == "") {
header("Location: http://www.mydomain.com/login.php");
exit();
} else { ?>
HTML STUFF
<? } ?>
$cookiedata = $HTTP_COOKIE_VARS["cookie"];
if ($cookiedata == "") {
header("Location: http://www.mydomain.com/login.php");
exit();
} else { ?>
HTML STUFF
<? } ?>
Note... you do not need to wrap php tags: <? ?> around every line of your script. Just at the start and end of a BLOCK of PHP. It is inefficient to escape in and out of php like that. Only leave php mode if you are outputting a block of html.
#4
Posted 31 January 2005 - 01:39 PM
Thank yo sherri that worked great.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users








