Jump to content

login script not redirecting sometimes......


cougarreddy

Recommended Posts

hi, I have a login page on an application im doing... login script works fine, but strangely some times when I click the submit button, the page is not redirected to the home page. I have tried to add some "echo " stmts  in the redirecting part of the code and I can see that part being executed, seems like just the  "" header("Location:itachome.php")""""" is not working. When I give wrong credentials errors are displayed properly, like "No username registered" etc....

 

here is php script

$error=0;
require_once('config.php');
if(isset($_POST['submit'] )&& $_POST['submit']=="Log In")
{
	session_start();
	//echo "hmm";
	//qry the databse for the given username and password
	$user=mysql_query("SELECT * from users where `userid`='".$_POST['username']."'");
	if(mysql_num_rows($user)==0)
		$error=2;
	else
	{

		$user_det=mysql_fetch_row($user);	
		$password=$_POST['password'];
		if($user_det[3]!=$password)
		{	
			$error=1;
			//echo "123";
		}
		else
		{
			//echo "123";
			$_SESSION['SESSION_User_ID'] = $user_det[2];
			$_SESSION['SESSION_First_Name'] = $user_det[0];
			$_SESSION['SESSION_Last_Name'] = $user_det[1];
			session_write_close();
			header("Location:itachome.php");

			exit();
		}

	}
}

Link to comment
Share on other sites

yes, as expected my login page did not redirect me to home page this morning..... then I willingly entered wrong password my user id, and it displayed error saying wrong password...... then i entered correct password and then..magic, it redirected me to home page.  Still I didnt get why it didnt redirect me in the first place?????  appreciate any help guys......

Link to comment
Share on other sites

Are you doing this on a system that has error_reporting set to E_ALL and display_errors set to ON so that all php detected errors would be displayed?

 

Is your log in form and the form processing code being included into other code or are they stand-a-lone pages? Does the form have any php code on it that could be affecting how/what it submits? Are all the files involved in the same folder? Is the home page perhaps redirecting back to the log in page and it just looks like the redirect to the home page does not work? Are the hostname(subdomain) (www. and no www.) and/or paths in the URL changing between the pages?

 

Basically, we need to see all the relevant code and know everything that you know about the situation in order to have a chance at finding why something that would normally work behaves the way it is on your system and with your code.

Link to comment
Share on other sites

This is my hole login.php page.. PHP code is also in the same page. when user clicks submit button, basically page submits to itself and by checking "isset($_POST['submit'])", php code for login is processed and then redirected to home page.

 

here is "itaclogin.php" page

*****************************************************

[code=php:0]

<?php
$error=0;
require_once('config.php');
if((isset($_POST['submit']))&& ($_POST['submit']=="Log In"))
{
	session_start();
	//echo "hmm";
	//qry the databse for the given username and password
	$user=mysql_query("SELECT * from users where `userid`='".$_POST['username']."'");
	if(mysql_num_rows($user)==0)
		$error=2;
	else
	{

		$user_det=mysql_fetch_row($user);	
		$password=$_POST['password'];
		if($user_det[3]!=$password)
		{	
			$error=1;
			//echo "123";
		}
		else
		{
			$_SESSION['SESSION_User_ID'] = $user_det[2];
			$_SESSION['SESSION_First_Name'] = $user_det[0];
			$_SESSION['SESSION_Last_Name'] = $user_det[1];
			session_write_close();
			header("Location:itachome.php");
			echo "123";
			exit();
		}

	}
}
?>


<html>
<head>
	<title>Data Center/Remote Locations Access Request Form - ITAC</title>
	<link rel=stylesheet href="request.css" type="text/css">
	<SCRIPT LANGUAGE="JAVASCRIPT" SRC="access.js"></SCRIPT>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 www.spicescripts.com scripts for your business php perl mysql">
</head>
<body>
	<div id="header">
	<?php require_once('header.php');?>
	</div>
	<hr size="4" color="#000000"/>
	<div id="maincontent">
		<form name="itaclogin" method="POST" action="" onsubmit="return blankTextField();" >
			<p> </p><p> </p><p> </p>
			<div id="fieldWrap">
					<label for="logintext"><span class="label">Please Enter your Log In details.</label>
					<?php
								if($error==1)
									echo "<p align='left'>Invalid userid/password combination</p>";
								if($error==2)
									echo "<p align='left'>UserID is not registered</p>";
							?>
					<p>	
						<label for="username"><span class="label">Username<br/></label>
						<input type="text" size="20" value="" class="input" id="user_login" name="username"/></span><br>
						<label for="password"><span class="label">Password<br/></label>
						<input type="password" size="20" value="" class="input" id="user_pass" name="password"/></span>
					</p>
					<p class="submit">
						<input type="submit" value="Log In" id="submit" name="submit"/>
					</p>
			</div> 
			<p> </p><p> </p><p> </p>
		</form>
	</div>
	<hr size="4" color="#000000"/>		
    </body>
</html>

Link to comment
Share on other sites

im sure execution flow is reaching the the "header()" statement, because, when I have added two echo stmts up above n below the header line,

 

echo "123";
header("Location:itachome.php");
echo "456";

 

browser displayed,

********

123

warning: cannot modify header information - headers already sent by (output started at d:\ITAC\DCAR\itaclogin.php:32) in d:\ITAC\DCAR\itaclogin.php on line 33

456

********

 

and when I commented first echo, i.e. "echo '123' ".. nothing happened, no warnings no redirection, and also no "456" being rendered to the browser....

 

 

 

******

Link to comment
Share on other sites

what is surprising me the most is... when I give wrong credentials i get error message and then immediately I give correct credentials and I am being redirected :confused:.... I guess this will be one of the strangest things u'll see on this forum...or my code just sucks.......

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.