Jump to content

[SOLVED] header(Location:) problems


mazman13

Recommended Posts

It seems like this script isn't working with header(Location:)

 

You can see what I mean www.collisionspecialiststx.com/fleetportal

 

u-michael

p-test

 

Here is the script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        
                <meta http-equiv="Content-Language" content="en-us">
                <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
                <title>Fleet Portal</title>
              	<link rel="stylesheet" type="text/css" href="../pagestyle.css">
</head>

<body>

<div id="wrapper">
<div id="header">
<p> </p>
</div>
	<div id="tabs">
                        <ul>
                                
<li><a href="../index.html"><span> Home </span></a></li>
<li><a href="../contactus.htm"><span>Contact Us</span></a></li>
<li><a href="../checkvehicle.htm"><span>Check Vehicle</span></a></li>
<li><a href="../agents.htm"><span>Agents</span></a></li>
<li><a href="../repairsteps.htm"><span>Repair Steps</span></a></li>
<li><a href="../shoptour.htm"><span>Shop Tour</span></a></li>
<li><a href="../employment.cfm"><span>Jobs</span></a></li>
<li><a href="../commitment.htm"><span>Our Commitment</span></a></li>
<li><a href="../warranty.htm"><span>Warranty</span></a></li>
<li><a href="../fleet.htm"><span>Fleet</span></a></li>

                        </ul>
</div>
<div id="content">

<table align="center" border="0" width="350" bgcolor="#99CCFF" cellspacing="0" cellpadding="0" style="border: 2px solid #6699FF; margin: 20px auto 20px auto;">
      <tr>
        <td bgcolor="#6699FF" height="30" colspan="5">
          <p align="center"><font face="Verdana" size="2" color="#FFFFFF"><b>Login</b></font></td>
      </tr>
  <td>
<?php
    session_start();
$_SESSION['username'];

    $errorMessage = '';

    if (isset($_POST['txtUserId']))
    {
        $userID = htmlentities($_POST['txtUserId']);
        $userPass = htmlentities($_POST['txtPassword']);

        //replace the following with your MySQL values
        //*********************
	include('includes/connection.php');

        // check if the user id and password combination exist in database
        $query = "SELECT * FROM company WHERE `username` = '$userID' AND `password` = '$userPass' AND `enabled`=1";


        $result = mysql_query($query) or die('Query failed. ' . mysql_error());

       if (mysql_num_rows($result) == 1)
       {
          // the user id and password match,
          // set the session
            $_SESSION['test_logged_in'] = true;
            $_SESSION['user']=$userID;

         // after login we move to the main page

	 header('Location:main.php?username=$userID');

         exit;
       }
       else $errorMessage = 'Sorry, wrong user id / password';
    }

    if ($errorMessage != '') {
    ?>
            <p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
            <?php
    }
?>

<form id="frmLogin" name="frmLogin" method="post">
    <table width="350" cellspacing="2" cellpadding="2" border="0" align="center">
        <tbody>
            <tr>
                <td width>Username: </td>
                <td><input type="text" id="txtUserId" name="txtUserId" /></td>
            </tr>
            <tr>
                <td width>Password: </td>
                <td><input type="password" id="txtPassword" name="txtPassword" /></td>
            </tr>
            <tr>
                <td width> </td>
                <td><input type="submit" value="Login" name="btnLogin" /></td>
            </tr>
        </tbody>
    </table>
</form>
</td>
</tr>
</table>
</div>
<div id="footer">
<!--webbot bot="Include" U-Include="footer.htm" TAG="BODY" startspan -->
<p class="style1">

<font color="#C0C0C0"><a target="_blank" href="http://www.ase.com"><img border="0" src="../images/ase.gif" width="49" height="45" align="middle"></a></font><font color="#FFFFFF"><a target="_blank" href="http://www.i-car.com"><img border="0" src="../images/footer2.gif" align="middle" width="46" height="59"></a></font><font color="#000000"><a target="_blank" href="http://www.hertz.com"><img height="32" src="../images/Hertzlogo-Transparent.gif" width="72" border="0" align="middle"></a></font></p>

<!--webbot bot="Include" i-checksum="47141" endspan --></div>
</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/141958-solved-headerlocation-problems/
Share on other sites

header() will only work if nothing has been sent to the browser already.  For example:

<?php
echo 'blah';

// THIS WILL NEVER WORK
header('blah');
?>

 

If you turn on errors, you will notice you are getting an 'headers already sent' error.

 

http://us3.php.net/header

 

Move your PHP code to the top of your script, before you output any HTML.

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.