freddyw Posted September 4, 2009 Share Posted September 4, 2009 okay. So i had another topic. Ive changed my code and scrapped it. (will tick that topic as solved in a second) I got this code off a website. It seems to be working. However... its not taking me to protected.php like it should. heres my code <? session_start(); //initialize session mechanism if(!isset($_POST['ok'])) { // if the form is not completed, display it echo" <html> <head> <title>Authorization page</title> </head> <body> <table width='100%' height='100%'> <form method='POST' action='login.php'> <tr><td align=center> <table> <tr><td> <table> <tr><td>Login:</td><td><input type='text' name='login' size='15'></td></tr> <tr><td>Password:</td><td><input type='password' name='pass' size='15'></td></tr> </table> </td></tr> <tr><td align=center><input type='submit' name='ok' value='Enter'></td></tr> </table> </td></tr> </form> </table> </body> </html> "; } else{ //supposed that user data //is saved in database, in users table, that includes id, login, pass fields $db=mysql_pconnect('sql201.byethost11.com', '********', '********') or die(mysql_error()); mysql_select_db('b11_4059953_db1', $db) or die(mysql_error()); //check if there is a user with such login and password $res=mysql_query("SELECT * FROM user WHERE username='".$_POST['username']."' AND password='".$_POST['password']."'", $db); if(mysql_num_rows($res)!=1){ //such user doesn’t exist echo "Incorrect login and password"; } else{ //user is found $_SESSION['login']=$_POST['login']; //set login & pass $_SESSION['pass']=$_POST['pass']; header("Location: protected.php"); // redirect him to protected.php } mysql_close(); } ?> its taking me to another website, whether the log in is correct or not. you view it here as the site is live http://fredundant.byethost11.com/log.php username: php password: freak any ideas why its going to that website? Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/ Share on other sites More sharing options...
tom2oo8 Posted September 4, 2009 Share Posted September 4, 2009 Try: header("Location: protected.php"); in lower case h Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912769 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 thanks tom. but hasn't made a difference Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912771 Share on other sites More sharing options...
tom2oo8 Posted September 4, 2009 Share Posted September 4, 2009 thanks tom. but hasn't made a difference Hmm, where exactly is it redirecting? or is it just not redirecting at all? If you got the page name wrong and if you are using a free host they dont normally take you to a 404 error and instead a random page with ads. Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912772 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 look at it for yourself http://fredundant.byethost11.com/log.php log in with username: php and password: freak it should go here http://fredundant.byethost11.com/protected.php Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912774 Share on other sites More sharing options...
tom2oo8 Posted September 4, 2009 Share Posted September 4, 2009 look at it for yourself http://fredundant.byethost11.com/log.php log in with username: php and password: freak it should go here http://fredundant.byethost11.com/protected.php Hmm unfortunatly i just cant get off the login to even see protected.php So i cant help you any more, ill read over your code and if i can help ill post but at the moment i cant sorry. Yep the page p Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912780 Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Can't log in. Using Username: "php" Password: "freak" Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912784 Share on other sites More sharing options...
samshel Posted September 4, 2009 Share Posted September 4, 2009 ur form action is going to login.php and you have written the code in log.php, try posting the form to log.php Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912786 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 ive edited the original code. I had careless mistakes. the code is now <? session_start(); //initialize session mechanism if(!isset($_POST['ok'])) { // if the form is not completed, display it echo" <html> <head> <title>Authorization page</title> </head> <body> <table width='100%' height='100%'> <form method='POST' action='log.php'> <tr><td align=center> <table> <tr><td> <table> <tr><td>Login:</td><td><input type='text' name='username' size='15'></td></tr> <tr><td>Password:</td><td><input type='password' name='password' size='15'></td></tr> </table> </td></tr> <tr><td align=center><input type='submit' name='ok' value='Enter'></td></tr> </table> </td></tr> </form> </table> </body> </html> "; } else{ //supposed that user data //is saved in database, in users table, that includes id, login, pass fields $db=mysql_pconnect('sql201.byethost11.com', '********', '********') or die(mysql_error()); mysql_select_db('b11_4059953_db1', $db) or die(mysql_error()); //check if there is a user with such login and password $res=mysql_query("SELECT * FROM user WHERE username='".$_POST['username']."' AND password='".$_POST['password']."'", $db); if(mysql_num_rows($res)!=1){ //such user doesn’t exist echo "Incorrect login and password"; } else{ //user is found $_SESSION['username']=$_POST['username']; //set login & pass $_SESSION['password']=$_POST['password']; header("Location: protected.php"); // redirect him to protected.php } mysql_close(); } ?> so now if a username and password are entered the page resets itself. and if an incorrect username and pass are entered it echo's as it should. any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912789 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 ur form action is going to login.php and you have written the code in log.php, try posting the form to log.php Thanks sam i noticed that. Along with a few other mistakes. try logging in for me with any username you want. then try again with php and freak. can see why that is happenning? As this is a new problem, does it require a new topic. I just dont want to hog the board too much Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912791 Share on other sites More sharing options...
samshel Posted September 4, 2009 Share Posted September 4, 2009 post ur code from protected.php , i think it is going there and redirecting back to log.php Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912796 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 session_start(); //this checks to see if the $_SESSION variable has been not set //or if the $_SESSION variable has been not set to true //and if one or the other is not set then the user gets //sent to the login page if(!isset($_SESSION) || $_SESSION !== true){ header('Location: log.php'); } echo "You are currently logged in"; echo "welcome"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912800 Share on other sites More sharing options...
samshel Posted September 4, 2009 Share Posted September 4, 2009 if(!isset($_SESSION) || $_SESSION !== true){ header('Location: log.php'); } try changing to if(!isset($_SESSION)){ header('Location: log.php'); } Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912802 Share on other sites More sharing options...
tom2oo8 Posted September 4, 2009 Share Posted September 4, 2009 session_start(); //this checks to see if the $_SESSION variable has been not set //or if the $_SESSION variable has been not set to true //and if one or the other is not set then the user gets //sent to the login page if(!isset($_SESSION) || $_SESSION != true){ header('Location: log.php'); } echo "You are currently logged in"; echo "welcome"; ?> Ok i just cahnged your code, as ive never seen !== (is that meant to be there? ) try the code in the code box above Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912803 Share on other sites More sharing options...
samshel Posted September 4, 2009 Share Posted September 4, 2009 !== will compare the value as well as the data type. Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912806 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 thanks sam i owe you a beer Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912810 Share on other sites More sharing options...
tom2oo8 Posted September 4, 2009 Share Posted September 4, 2009 !== will compare the value as well as the data type. Ah thanks, (i never bothered to learn php using tutorials i learnt from source codes) I think i should actually bother reading the php doc's as im sure ive missed out on half the commands ^^ Quote Link to comment https://forums.phpfreaks.com/topic/173170-redirected-to-a-website-for-no-reason/#findComment-912812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.