chocopi Posted May 23, 2007 Share Posted May 23, 2007 Is it possible to user $PHP_SELF and then in if($_POST) can i use header("Location:"blah.php); as i really cant get it to work <?php print("<form name=\"login\" method=\"post\" action=\"$PHP_SELF\"> \n"); if($_POST) { // check info is good to go header("Location:"blah.php); } ?> Thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/ Share on other sites More sharing options...
per1os Posted May 23, 2007 Share Posted May 23, 2007 <?php print("<form name=\"login\" method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\"> \n"); if(isset($_POST['login']))) { // check info is good to go header("Location:blah.php"); } ?> It is with the right syntax. Use the $_SERVER call as the way you were doing is assuming register_globals is on which is a security flaw in php and should be off. Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-260213 Share on other sites More sharing options...
chigley Posted May 23, 2007 Share Posted May 23, 2007 Register Globals may be causing you problems. <?php print("<form name=\"login\" method=\"post\" action=\"$_SERVER[php_SELF]\"> \n"); if(isset($_POST["submit"]) { // check info is good to go header("Location: blah.php"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-260214 Share on other sites More sharing options...
eric1235711 Posted May 23, 2007 Share Posted May 23, 2007 yeah, frost solved a problem: the file name must be inside the string given to header function but there's another problem, you it won't redirect because you are trying to send the headers before printing... look at this: <?php if(isset($_POST['login']))) { // check info is good to go $filename = "blah.php" header("Location:".$filename); die(); } print("<form name=\"login\" method=\"post\" action=\"" . $_SERVER['PHP_SELF'] . "\"> \n"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-260221 Share on other sites More sharing options...
chocopi Posted May 23, 2007 Author Share Posted May 23, 2007 Cheers, but using <?php if(isset($_POST["submit"]) { // Start Session session_start(); $_SESSION['id'] = "$id"; $_SESSION['username'] = "$username"; $_SESSION['password'] = "$password"; header("Location: login_check.php"); }?> i get this error: Parse error: syntax error, unexpected '{' ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-260222 Share on other sites More sharing options...
Glyde Posted May 23, 2007 Share Posted May 23, 2007 You need another closing parenthesis at the end of if (isset($_POST['submit']) Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-260229 Share on other sites More sharing options...
chocopi Posted May 23, 2007 Author Share Posted May 23, 2007 oh yea thanks, ill sort that out tommorrow THANKS Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-260230 Share on other sites More sharing options...
chocopi Posted May 26, 2007 Author Share Posted May 26, 2007 for some reason the page still isnt redirecting. Here is the whole code: <?php // Login.php require_once('page_header.php'); // Declare Variables // User Defined $username = $_POST['username']; $raw_password = $_POST['password']; // Automatic $title = 'Chocopi :: Login'; $password = md5($raw_password); $date = date('Ymd'); $last_login = "UPDATE Mark SET last_login='$date' WHERE username='$username' && password='$password'"; $login = mysql_query("SELECT id FROM Mark WHERE username='$username' && password='$password'"); $login_check = mysql_num_rows($login); $get_date = "SELECT DATE_FORMAT(last_login, '%d %M %Y') as date FROM Mark"; $reg_date = mysql_query($get_date) or die (mysql_error()); $age = mysql_query("SELECT (TO_DAYS(last_login) - TO_DAYS(reg_date)) as daysreg FROM Mark"); $errors = 0; $error_msg = 'Sorry, but your username and password combination is incorrect.'; // Html Code print("<html> \n"); print(" <head> \n"); print(" <title>$title</title> \n"); print(" </head> \n"); print("<body> \n"); if(isset($_POST["submit"])) { // Start Session session_start(); $_SESSION['id'] = "$id"; $_SESSION['username'] = "$username"; $_SESSION['password'] = "$password"; $filename = "login_check.php"; header("Location:".$filename); } print("<form name=\"login\" method=\"post\" action=\"$_SERVER[php_SELF]\"> \n"); print("<center> \n"); print("<table width=\"70%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"> \n"); print(" <th align=\"center\">Login</th> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" Username: \n"); print(" <input type=\"text\" name=\"username\" value=\"$username\" maxlength=\"20\" /> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" Password: \n"); print(" <input type=\"password\" name=\"password\" value=\"$raw_password\" maxlength=\"20\" /> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" <input type=\"submit\" name=\"submit\" value=\"Login\" /> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print("<font color=\"#ff0000\"> \n"); // Error Message if ($errors > 0) { echo $error_msg ; } // Finish Html Page print("</font> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" <br /><a href=\"register.php\">Register</a> \n"); print(" </td> \n"); print(" </tr> \n"); print("</table> \n"); print("</center> \n"); print("</form> \n"); print("</body> \n"); print("</html> \n"); ?> Gracias, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-262024 Share on other sites More sharing options...
MadTechie Posted May 26, 2007 Share Posted May 26, 2007 try this <?php ob_start(); // Start Session session_start(); // Login.php require_once('page_header.php'); // Declare Variables // User Defined $username = $_POST['username']; $raw_password = $_POST['password']; // Automatic $title = 'Chocopi :: Login'; $password = md5($raw_password); $date = date('Ymd'); $last_login = "UPDATE Mark SET last_login='$date' WHERE username='$username' && password='$password'"; $login = mysql_query("SELECT id FROM Mark WHERE username='$username' && password='$password'"); $login_check = mysql_num_rows($login); $get_date = "SELECT DATE_FORMAT(last_login, '%d %M %Y') as date FROM Mark"; $reg_date = mysql_query($get_date) or die (mysql_error()); $age = mysql_query("SELECT (TO_DAYS(last_login) - TO_DAYS(reg_date)) as daysreg FROM Mark"); $errors = 0; $error_msg = 'Sorry, but your username and password combination is incorrect.'; // Html Code print("<html> \n"); print(" <head> \n"); print(" <title>$title</title> \n"); print(" </head> \n"); print("<body> \n"); if(isset($_POST["submit"])) { $_SESSION['id'] = "$id"; $_SESSION['username'] = "$username"; $_SESSION['password'] = "$password"; $filename = "login_check.php"; ob_end_clean(); header("Location: ".$filename); } print("<form name=\"login\" method=\"post\" action=\"$_SERVER[php_SELF]\"> \n"); print("<center> \n"); print("<table width=\"70%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"> \n"); print(" <th align=\"center\">Login</th> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" Username: \n"); print(" <input type=\"text\" name=\"username\" value=\"$username\" maxlength=\"20\" /> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" Password: \n"); print(" <input type=\"password\" name=\"password\" value=\"$raw_password\" maxlength=\"20\" /> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" <input type=\"submit\" name=\"submit\" value=\"Login\" /> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print("<font color=\"#ff0000\"> \n"); // Error Message if ($errors > 0) { echo $error_msg ; } // Finish Html Page print("</font> \n"); print(" </td> \n"); print(" </tr> \n"); print(" <tr> \n"); print(" <td align=\"center\"> \n"); print(" <br /><a href=\"register.php\">Register</a> \n"); print(" </td> \n"); print(" </tr> \n"); print("</table> \n"); print("</center> \n"); print("</form> \n"); print("</body> \n"); print("</html> \n"); ob_flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-262040 Share on other sites More sharing options...
chocopi Posted May 26, 2007 Author Share Posted May 26, 2007 Thanks, MadTechie and everyone else thats help. Tis sorted, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/52701-solved-php_self-headerlocation/#findComment-262043 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.