dkoolgeek Posted January 12, 2007 Share Posted January 12, 2007 I want to make a script redirect the user back to the Index.php page if it found that the login was correct. What is the best way to do this?Thanks.[pre]if(mysql_affected_rows()==0){ $_SESSION['in'] = 0; //BACK TO LOGIN.PHP}else { $_SESSION['in'} = 1; //REDIRECT TO INDEX.PHP HERE}[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/33916-another-noobie-question/ Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 header(); Quote Link to comment https://forums.phpfreaks.com/topic/33916-another-noobie-question/#findComment-159232 Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 [url=http://www.php.net/header]header[/url]as long as nothing has been output to the browser previously, then this should work:[code]<?phpheader("Location: /login.php");exit;?>[/code]using header alone like this does not IMMEDIATELY redirect, hence my 'exit' the line after.cheers Quote Link to comment https://forums.phpfreaks.com/topic/33916-another-noobie-question/#findComment-159233 Share on other sites More sharing options...
dkoolgeek Posted January 12, 2007 Author Share Posted January 12, 2007 I've already sent something to the browser I think.The header isn't working. Its giving me the usual "headers already sent."Here is the whole form[code]<? session_start(); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>CheckLogin</title></head><body><?php@mysql_connect("localhost","allan","ah1018$") or die("Cannot Connect to DB!");@mysql_select_db("trademymedia")or die("Cannot select DB"); $Email = $_POST["uEmail"];$Password = $_POST["uPassword"];$r = mysql_query("SELECT * FROM customerinfo WHERE Email = '".$Email."' AND Password = '".$Password."'");if(!$r) {$err=mysql_error();print $err;exit();}if(mysql_affected_rows()==0){ $_SESSION['in'] = 0;}else { $_SESSION['in'] = 1; header("index.php");}?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33916-another-noobie-question/#findComment-159235 Share on other sites More sharing options...
redbullmarky Posted January 12, 2007 Share Posted January 12, 2007 move all your php code up to the top, above the HTML. i cant see any specific reason for it to be there, so you should be fine.and you need header("Location: index.php"), not header("index.php"), followed by an 'exit'[code]<?phpsession_start();@mysql_connect("localhost","allan","ah1018$") or die("Cannot Connect to DB!");@mysql_select_db("trademymedia")or die("Cannot select DB"); $Email = $_POST["uEmail"];$Password = $_POST["uPassword"];$r = mysql_query("SELECT * FROM customerinfo WHERE Email = '".$Email."' AND Password = '".$Password."'");if(!$r) {$err=mysql_error();print $err;exit();}if(mysql_affected_rows()==0){ $_SESSION['in'] = 0;}else { $_SESSION['in'] = 1; header("Location: index.php"); exit;}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>CheckLogin</title></head><body></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/33916-another-noobie-question/#findComment-159236 Share on other sites More sharing options...
dkoolgeek Posted January 12, 2007 Author Share Posted January 12, 2007 Yea I'd already fixed the header, after I posted it.But thanks a lot, its working now. Quote Link to comment https://forums.phpfreaks.com/topic/33916-another-noobie-question/#findComment-159237 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.