Vitamin Posted April 14, 2009 Share Posted April 14, 2009 <?php $link = mysql_connect('localhost', 'root', 'root'); $selectdb = mysql_select_db ('chfa', $link); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); if(isset($_POST['submitinfo'])) { if($username=="" || $password=="") { die("Please do not leave the username / password field blank!"); } $result = mysql_query("SELECT * FROM admin WHERE username='$username' AND pass='$password'"); $number = mysql_num_rows($result); if($number==0) { die("Your login details are not right. Please click the back button and correct them."); } setcookie ("auth", "yea", time()+3600); header ("location: main.php"); } ?> Everything works up to the point of the header statement. How can I get a redirect to a different page? Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/ Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 14, 2009 Share Posted April 14, 2009 Include the full URL in your header-location <?php ... header ("Location: http://www.site.com/main.php"); exit(); ... ?> And be sure not echoing anything before the header, including space or cariage return. And put a exit()/die() after the header because the page will be executed and the results may be returned to the browser. (not sure if the results is actually send to the browser but the page will be executed, including any SQL query, ....) http://www.php.net/manual/en/function.header.php Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810221 Share on other sites More sharing options...
Vitamin Posted April 14, 2009 Author Share Posted April 14, 2009 Thanks for the quick reply, but still not working Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810223 Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 is that part of the script being executed? replace the header with a echo and see if it comes up. Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810229 Share on other sites More sharing options...
gffg4574fghsDSGDGKJYM Posted April 14, 2009 Share Posted April 14, 2009 Does your script report any error ? What does it do ? nothing ? Did you set your error reporting like that : <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); ?> Use telnet yoursite.com 80 to see the exact output of your script OR use some website like http://web-sniffer.net/ Can show you the http header with http content your script output. Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810231 Share on other sites More sharing options...
Vitamin Posted April 14, 2009 Author Share Posted April 14, 2009 I get these errors when I do that Notice: Undefined index: username in C:\server\www\myserver.dev\public_html\test\do_login.php on line 7 Notice: Undefined index: password in C:\server\www\myserver.dev\public_html\test\do_login.php on line 8 which is the setting or username and password. but if I echo where the header line is insted of the header the echo works. Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810239 Share on other sites More sharing options...
Vitamin Posted April 14, 2009 Author Share Posted April 14, 2009 hmmm... if i do this header('Location: http://www.google.com/'); it goes to google not sure what id going on Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810243 Share on other sites More sharing options...
Vitamin Posted April 14, 2009 Author Share Posted April 14, 2009 Sigh... got it guys... Sorry my main.php page had a line in it to point back to that page. Thats why it appered to not be leaving that page. Link to comment https://forums.phpfreaks.com/topic/154131-solved-header-help/#findComment-810247 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.