Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



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!


Sponsored Content

 

 
 

Photo
- - - - -

Checking For Cookies


  • Please log in to reply
3 replies to this topic

#1 Gatorhardware

Gatorhardware

    Web Hoster

  • Active Members
  • PipPipPipPipPip
  • 315 posts

Posted 24 January 2005 - 11:52 AM

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?

#2 Gatorhardware

Gatorhardware

    Web Hoster

  • Active Members
  • PipPipPipPipPip
  • 315 posts

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?

#3 sherri

sherri

    Perceptum et Invenio

  • Active Members
  • PipPipPip
  • 89 posts
  • Location:Lost in Canada

Posted 24 January 2005 - 01:02 PM

Try something like this BEFORE you send any output to the browser:

CODE
<?
$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 Gatorhardware

Gatorhardware

    Web Hoster

  • Active Members
  • PipPipPipPipPip
  • 315 posts

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