Jump to content

[SOLVED] Header/Redirect Problem


overlordofevil

Recommended Posts

I just moved hosting company and having problems getting my login script to work.

 

I know the php and mysql is working fine. I have tested the scripts by changing up what happens when I select to login. Such as I changed it to just verify that my login name and password exists.

 

So I think my problem is with my redirect to another page but I can't see the problem. When i log in it just stops and doesn't redirect.

I have changed the redirect from header(Location: home.php) to header(Location:http://testdb.nerowi.com/page.php) to see if using the entire path might help but it hasn't helped.

 

here is the current code

 

<?php session_start(); ?>

<html>
<body>
<?php

//process.php - Takes care of login and logout scripts

include ("login.inc"); //holds the variables for the db login

$user = $_POST ['user'];
$pass = $_POST ['pass'];

	$query = "SELECT * FROM id WHERE username='$user' AND password='$pass'";
	$result = mysql_query($query) or die (mysql_error());

	if ($result) 
	{
		$line = mysql_fetch_array($result);
		{

			$_SESSION['user_id'] = $line['id'];
			$_SESSION['user_name'] = $line['username'];
			$_SESSION['user_pass'] = $line['password'];
			$_SESSION['user_rights'] = $line['accesslvl'];
			$_SESSION['chapter_id'] = $line['chid'];
      		        header("Location: http://testdb.nerowi.com/home.php");								
		}	
	}
?>
</body>
</html>

 

This works fine on my test server I have here at the office and it worked fine on my old host company problem is it just won't respond tothe new host.

 

Any suggestions would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/101230-solved-headerredirect-problem/
Share on other sites

I'm very new at this, and since I experiment with everything even if I don't know what it is for, in this situation for curiosity sake, I would test it using ob_start(); at the very top of the page and ob_flush(); at the very bottom. Or perhaps getting rid of those html tags and spaces at the beginning of your code. Maybe I'm just talking nonsense and the session_start() does the same thing...

You're outputting before you do the header(). Big mistake :) Since you don't need the body or html tags, try:

 

<?php session_start();

//process.php - Takes care of login and logout scripts

include ("login.inc"); //holds the variables for the db login

$user = $_POST ['user'];
$pass = $_POST ['pass'];

	$query = "SELECT * FROM id WHERE username='$user' AND password='$pass'";
	$result = mysql_query($query) or die (mysql_error());

	if ($result) 
	{
		$line = mysql_fetch_array($result);
		{

			$_SESSION['user_id'] = $line['id'];
			$_SESSION['user_name'] = $line['username'];
			$_SESSION['user_pass'] = $line['password'];
			$_SESSION['user_rights'] = $line['accesslvl'];
			$_SESSION['chapter_id'] = $line['chid'];
      		        header("Location: http://testdb.nerowi.com/home.php");								
		}	
	}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.