Jump to content

[SOLVED] $PHP_SELF + header("Location:");


chocopi

Recommended Posts

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

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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");
}

?>

Link to comment
Share on other sites

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");
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.