Jump to content


Photo

Not redirecting properly.


  • Please log in to reply
23 replies to this topic

#21 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 15 July 2006 - 03:41 AM

What error are you getting? Or are you just wanting for us to look at it and see if it's right?


Disregard it. I like your logic for checking if it's not there. Seems it would cause less trouble. Will try...

#22 pixy

pixy
  • Members
  • PipPipPip
  • Advanced Member
  • 295 posts

Posted 15 July 2006 - 03:44 AM

Anything to help, dear. Let me know if it works.

This is a .44 Caliber Loveletter straight through my heart.

Tabulas + Threadless + Hire Me!


#23 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 15 July 2006 - 03:45 AM

try something along these lines in index2.php.  keep in mind this is a semantic writeup only, you'll have to replace it with the actual code you're using:

<?php

// check if the user's credentials check out
if (cookie is set)
{
  // grab the credentials (hint: when the query is only grabbing one row, you don't need a while() loop)
  if (credentials dont match)
  {
    // send them to the logout (since they have a cookie set but have wrong credentials, don't want them keeping the cookie)
  }
}
else
{
  // the cookie isn't set, so we can send them to the login right away with header()
}

?>

note that the script doesn't do anything if the credentials match, only if they do NOT match.  that's exactly what you want.  it will let the page that index2.php is being included on display if their credentials check out, but will boot them if they don't.  just include index2.php on all pages to be "protected" in this manner.

#24 treilad

treilad
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 15 July 2006 - 04:08 AM

I filled in the code the best I could, but there might be errors. It looks like it will run alright.

<?php

// check if the user's credentials check out
if(isset($_COOKIE['ID_my_site']))
 // grab the credentials (hint: when the query is only grabbing one row, you don't need a while() loop)
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check )){
 
  if (!isset($_COOKIE['ID_my_site']))
  {
    header('./logout.php')
  }
}
else
{
  header('./loginpage.php')
}

?>

Now that we've got past the looping issue you brought up, I'd like to know how to make that script run everytime the page is refreshed. Force refresh possibly? I dunno. Ya'll have been a big help tonight so thanks a ton. I've been working on this for over 15 hours straight, so I'm gonna get some shut-eye. I'll wake up in a few hours and check what you post so the board doesn't disappear on me. Thanks again and you probably haven't seen the last of me...

:D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users