Hi, I have been going round in circles for the past few hours and I need some help please with the following header location.

header("location: http://www.websitename/members/securecode/index.php");

I have a login script that works great until i get to line 81 ??
the above header location.

here is my script - I am successfully checking the database for values and showing error messages if the values are incorrect.

If all the values are correct Id like to take the user to a different page (line 81)
so they can enter thier secure code.

but..... when all values are correct, the page doesnt go to the header location?
header("location: http://www.websitename/members/securecode/index.php"); (line 81)

If someone could point me in the right direction as to where I am going wrong -

<?php
//start sessions and connect to db
session_start();
include('../includes/config.php');
//include_once "scripts/functions.php";
$error_message = isset($_GET['msg'])?($_GET['msg']):''; // check if we have an error message

if (@$_POST['login']) {

	$email = @$_POST['email'];
	$passwd = @$_POST['passwd'];
	//$remember = @$_POST['remember']; // Added for the remember me feature

	$email = strip_tags($email);
	$passwd = strip_tags($passwd);
	$email = mysql_real_escape_string($email);
	$passwd = mysql_real_escape_string($passwd);
	$email = eregi_replace("`", "", $email);
	$passwd = eregi_replace("`", "", $passwd);
	
	// check if the values were entered
	if ($email == ''){
		$error_message = 'Email address and Password Required';
		header("Location: l-test.php?msg=$error_message");
		exit;
	}

	if ($passwd == ''){
		$error_message = 'Email address and Password Required';
		header("Location: l-test.php?msg=$error_message");
		exit;
	}

	$passwd = sha1($passwd);

	// in order to check for the  the 'activated' field value later, and add more error checking
	// we need to change the query to 
	$res = mysql_query("SELECT * FROM memberst WHERE email='$email'") or die(mysql_error()); 

	$login_check = mysql_num_rows($res);

	if($login_check > 0){ 

		$row = mysql_fetch_array($res);
		$dbemail = $row['email'];
		$dbpassword = $row['passwd'];
		$activated = $row['activated'];
		$paidmember = $row['paidmember'];
		
		if ($dbpassword != $passwd){
			$error_message = "Email address and/or Password failed";
			header("Location: l-test.php?msg=$error_message");
			exit;
		}

		if ($activated == '0'){
			$error_message = "Your account requires activating<br>Check your email inbox and click our activation link.";
			header("Location: l-test.php?msg=$error_message");
			exit;
		}
		
		if ($paidmember == '0'){
			$error_message = "Registration fee required <a href='http://www.singleinn.com/members/payments/registration-fee.php'>make payment here</a>";
			header("Location: l-test.php?msg=$error_message");
			exit;
		}
		
		if ($dbpasswword == $passwd){

		    //$id = $row["id"];
        	//$_SESSION['id'] = $id;
       
			//$firstname = $row["firstname"];   
			//$_SESSION['firstname'] = $firstname;
		       
			//$email = $row["email"];
			//$_SESSION['email'] = $email;
         
		    //mysql_query("UPDATE memberst SET last_log_date=now() WHERE id='$id'");
			//header ("Location: userarea.php");
			header("location: http://www.websitename/members/securecode/index.php");
			exit();
		}
	}else{
		// the email address is not in the system
		$error_message = 'Unknown Email address';
		header("Location: l-test.php?msg=$error_message");
		exit;
	}
}

?>
<html>
<link href="../style/main.css" rel="stylesheet" type="text/css">
<head>

<style type="text/css">
<!--
.style5 {font-size: 14px; color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; }
-->
</style>
</head>

	<div align="center">
<table width="975" bgcolor="#2a4c79" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="7" height="7"><img src="../images/roundcornerslt.jpg" width="7" height="7" alt="" /></td>
		<td class="roundcornerstop"></td>
		<td><img src="../images/roundcornersrt.jpg" width="7" height="7" alt="" /></td>
	</tr>
	<tr>
		<td class="roundcornersleft"></td>
		<td>
	    <table width="975" border="0" cellspacing="0" cellpadding="0">
	    <tr>
	        <td><form action="l-test.php" method="POST">
    		
            <table bgcolor="#2a4c79"width="975" height="50" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="259"><div align="center" class="style5">email address: 
      <input type="text" name='email' value='<?php echo $email; ?>' class="login">
    </div></td>
    <td width="271"><div align="center" class="style5">Password: 
        <input type="password" name='passwd' class="login">
    </div></td>
    <td width=""><div align="center" class="style5">
      <div align="left">
        <input type="submit" name="login" value="login"> 
       </div>
    </div></td>
  </tr>
</table>
    </form></td>
	    </tr>
	    <tr>
	      <td align="center"><div align="center"><span style="color: #ffffff; font-weight: bold; font-size: 12px;"><?php echo $error_message; ?></span></div></td>
	      </tr>
	    </table>
		</td>
		<td class="roundcornersright"></td>
	</tr>
	<tr>
		<td><img src="../images/roundcornerslb.jpg" width="7" height="7" alt="" /></td>
		<td class="roundcornersbottom"></td>
		<td width="7" height="7"><img src="../images/roundcornersrb.jpg" width="7" height="7" alt="" /></td>
	</tr>
	</table>
</div>
</html>

Recommended Answers

All 8 Replies

maybe because in the first place it didn't satisfy your if statement

if($dbpasswword == $passwd)

because if it does, it should redirect... i don't see anything wrong on the php header() function

@Manuz & @vaultdweller123

Gents cheers for your input. I have tried everything you both have suggested but im still getting the same issue. The page just seems to refresh leaving the users email address in the email address field ?

Any (other) ideas

it doesn't matter if the letter "L" in location is in small caps... it will still redirect...

Problem solved - I hadnt set the session data correctly and started the session,

Marked as solved,

Many thanks for all your input

If you have a problem in header location than you have to set the session data will be correctly which it can be defined to started the session then your problem will might be solved .

hey i cant see anything wrong with that session_start();
me also getiing same problem in this header function... plz let me no how you debug this thing.... thnxxx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.