I'm creating an e-commerce website, and I just need clarification as to
whether a MySQL query is considered as "browser output".  I ask because
I have the following code, but the cookie isn't being set:

if ($op == "login") {
        if (!isset($username) && !isset($userpass)) {
        } else {
                if ($username == "" || $userpass == "") {
                        $errormsg = "Invalid username or password.
Please try again.";
                } else {
                        if (mysql_num_rows(mysql_query("select * from
`$cart->user_table` where username=\"$username\" and
userpass=\"$userpass\"", $cart->dblink)) == 1) {
                                setcookie("jackloren_user",
"$username:$userpass", time() + 2592000); // expires in 30 days
                                header("Location:
http://www.jackloren.com/";);
//                              echo "test";
/*                              if ($rd != "") {
                                        redirectURL($rd,"");
                                } else {
                                        redirectURL("","");
                                } */
                        } else {
                                $errormsg = "Invalid username or
password.  Please try again.";
                        }
                }
        }
}

However, if I comment out the header and uncomment the echo statement,
then the cookie is added, no problem.  It seems as if the browser is
freaking out when there isn't any output after a cookie is set and a
header is sent.

I'm also having another similar problem with this function:

function auth($redirect_url) {
        global $HTTP_COOKIE_VARS;
                
        if (!isset($HTTP_COOKIE_VARS['jackloren_user'])) {
                header("Location: http://www.jackloren.com/login.php";);
//              echo "test";
        } else {
                $userinfo = explode(":",
$HTTP_COOKIE_VARS['jackloren_user']);
                $username = $userinfo[0];
                $userpass = $userinfo[1];
                echo "$username | $userpass<br>";
                if (mysql_num_rows(mysql_query("select * from
`$cart->user_table` where username=\"$username\" and
userpass=\"$userpass\"", $cart->dblink)) != 1) {
                        redirectURL("login.php", $redirect_url);
                } else {
                        echo "success";
                        // nothing
                }
        }
}

If I leave the script the way it is, the browser isn't redirected no
matter what I put in the header() statement.  However, if I uncomment
the echo statement, giving the browser some output, then the redirect
works fine.

Has anyone experienced this?  And if so, how do I fix it?  Thanks.

J. Alden Gillespy (aka Dogga)
Microsoft Beta Tester:
- Office 11
- Content Management Server (CMS) 2002
- Systems Management Server (SMS) 2003


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to