chriscloyd Posted January 1, 2007 Share Posted January 1, 2007 okay i made my login script and for whatever reason its not returning to any pageheres my code[code]<?phperror_reporting(E_ALL);ini_set('log_errors','1');ini_set('display_errors','0'); session_start();include("config.php");//login$username = $_POST['username'];$password = md5($_POST['password']);$timendate = date("n/j/Y g:i:s A");$get_user = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error());$numusers = mysql_num_rows($get_user) or die(mysql_error());$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);$ip = $_SERVER['REMOTE_ADDR'];$description = 'Login';if ($numusers > 0) { $user = mysql_fetch_array($get_user) or die(mysql_error()); if ($username == $user['username']) { //check_passwords now if ($password == $user['password']) { $_SESSION['ccloyd'] == $username; $status = 'Success'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../?page=home"); } else { $error = 'Wrong Login Info.'; $status = 'Failed'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../?false=$error"); } } else { $error = 'Wrong Login Info.'; $status = 'Failed'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../?false=$error"); } } else { $error = 'Wrong Login Info.'; $status = 'Failed'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../?false=$error");}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32486-redirecting/ Share on other sites More sharing options...
trq Posted January 1, 2007 Share Posted January 1, 2007 The location header requires a complete url. Link to comment https://forums.phpfreaks.com/topic/32486-redirecting/#findComment-150932 Share on other sites More sharing options...
chriscloyd Posted January 1, 2007 Author Share Posted January 1, 2007 [CODE]<?phpsession_start();include("config.php");error_reporting(E_ALL);ini_set('log_errors','1');ini_set('display_errors','0'); //login$username = $_POST['username'];$password = md5($_POST['password']);$timendate = date("n/j/Y g:i:s A");if (isset($_POST['username'])){ $get_user = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); $numusers = mysql_num_rows($get_user) or die(mysql_error()); $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); $ip = $_SERVER['REMOTE_ADDR']; $description = 'Login'; if ($numusers > 0) { $user = mysql_fetch_array($get_user) or die(mysql_error()); if ($username == $user['username']) { //check_passwords now if ($password == $user['password']) { $_SESSION['ccloyd'] == $username; $status = 'Success'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../index.php?page=home"); } else { $error = 'Wrong Login Info.'; $status = 'Failed'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../index.php?false=$error"); } } else { $error = 'Wrong Login Info.'; $status = 'Failed'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../index.php?false=$error"); } } else { $error = 'Wrong Login Info.'; $status = 'Failed'; mysql_query("INSERT INTO logs (`ip`,`hostname`,`description`,`timendate`,`status`) VALUES ('$ip','$hostname','$description','$timendate','$status')") or die(mysql_error()); header("Location: ../index.php?false=$error"); }}?>[/CODE]i just updated it and its still not redirecting Link to comment https://forums.phpfreaks.com/topic/32486-redirecting/#findComment-150934 Share on other sites More sharing options...
dcro2 Posted January 1, 2007 Share Posted January 1, 2007 You need to use complete addresses such as http://mydomain.com/index.php?false=$error, it doesn't support relative paths. Link to comment https://forums.phpfreaks.com/topic/32486-redirecting/#findComment-150938 Share on other sites More sharing options...
JasonLewis Posted January 1, 2007 Share Posted January 1, 2007 and just some proper php coding stuff that you should fix up.i personally dont like seeing variables used inside of strings unless surrounded by curly brackets...either of these is good:[code=php:0]header("Location: ../index.php?false={$error}");[/code]or:[code=php:0]header("Location: ../index.php?false=".$error);[/code]but yeh change the ../ to the EXACT url. Link to comment https://forums.phpfreaks.com/topic/32486-redirecting/#findComment-150982 Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 [quote]i personally dont like seeing variables used inside of strings unless surrounded by curly brackets.[/quote]That really [i]is[/i] just personal preference. Curly braces are only required around complex variables. eg arrays. Link to comment https://forums.phpfreaks.com/topic/32486-redirecting/#findComment-151076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.