ryanwood4 Posted February 22, 2009 Share Posted February 22, 2009 Im not sure if this is a PHP problem or something is wrong with the HTML, but after users login they are redirected to the members page. However, it says it can't open the page because there are too many redirects. This is the code... //Checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs you in and directes you to the members page { $email = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE email = '$email'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($pass != $info['password']) { } else { header("Location: members.php"); } } } //if the login form is submitted if (isset($_POST['submit'])) { // if form has been submitted // makes sure they filled it in if(!$_POST['email'] | !$_POST['pass']) { die('You did not fill in a required field.'); } // checks it against the database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE email = '".$_POST['email']."'")or die(mysql_error()); //Gives error if user dosen't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die('That user does not exist in our database. <a href=www.rawtees.co.uk/loginpage.php>Click Here to Register</a>'); } while($info = mysql_fetch_array( $check )) { $_POST['pass'] = stripslashes($_POST['pass']); $info['password'] = stripslashes($info['password']); $_POST['pass'] = md5($_POST['pass']); //gives error if the password is wrong if ($_POST['pass'] != $info['password']) { die('Incorrect password, please try again.'); } else { // if login is ok then we add a cookie $_POST['email'] = stripslashes($_POST['email']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['email'], $hour); setcookie(Key_my_site, $_POST['pass'], $hour); //then redirect them to the members area header("Location: members.php"); } } } else { I have 2 redirects to the members page. header("Location: members.php"); any idea why this is happening? Link to comment https://forums.phpfreaks.com/topic/146419-solved-php-redirect-help-needed/ Share on other sites More sharing options...
jackpf Posted February 22, 2009 Share Posted February 22, 2009 Maybe you haven't set up the redirect from the members page to the login page correctly. As in, when you login, it redirects you to the members page, which wrongly redirects to the login page, and repeats until the browser gets tired. Try taking out any other redirects. Link to comment https://forums.phpfreaks.com/topic/146419-solved-php-redirect-help-needed/#findComment-768749 Share on other sites More sharing options...
ryanwood4 Posted February 22, 2009 Author Share Posted February 22, 2009 I think I have solved it, but thanks anyway. I have taken the space out between Location: and the address and it seems to have worked. Link to comment https://forums.phpfreaks.com/topic/146419-solved-php-redirect-help-needed/#findComment-768761 Share on other sites More sharing options...
jackpf Posted February 22, 2009 Share Posted February 22, 2009 That's odd...I always leave the space and my stuff works. Ahh well, if it works, it works. Link to comment https://forums.phpfreaks.com/topic/146419-solved-php-redirect-help-needed/#findComment-768764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.