From what I understand you can't use "header ("Location: addess");" to redirect to a new page after you have output anything to the browser. Is this correct?
If this is the case how would I redirect half way through some code, for example in the code below?
<?php
session_start();
require_once ('../../mysql_connect_bargain.php'); // Connect to the database.
if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
{
die("You need to supply a username and password.");
}
// Create query
$query = "SELECT * FROM `users` "
."WHERE `username`='".$_POST["username"]."' "
."AND `password`=PASSWORD('".$_POST["password"]."') "
."LIMIT 1";
// Run query
$result = mysql_query($query);
$result2 = mysql_query("SELECT * FROM `users` "
."WHERE `username`='".$_POST["username"]."' "
."AND `password`=PASSWORD('".$_POST["password"]."') "
."LIMIT 1");
$myrow = mysql_fetch_array($result2);
if ( $obj = @mysql_fetch_object($result) )
{
// Login O.K., create session variables
$_SESSION["valid_id"] = $myrow[0];
// $_SESSION["user_group"] = $myrow[4];
$_SESSION["valid_user"] = $_POST["username"];
$_SESSION["valid_time"] = time();
echo "You are now logged in!";
if (isset($url)) {
$url = $_POST['url'];
header ("Location: $url"); }
}
else
{
// Login not successful
die("Sorry, could not log you in. Wrong login information.");
}
}
else
{
echo "<form action=\"?op=login&url=$url\" method=\"POST\">";
echo "Username:<br>";
echo "<input name=\"username\" size=\"15\"><br>";
echo "Password:<br>";
echo "<input type=\"password\" name=\"password\" size=\"15\"><br>";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}
?>