[PHP] Cookie header and location header.

2003-07-09 Thread Ns_Andy
In PHP4.3.x
If I set a cookie with setcookie and send a location header immediately.
I find no problem for the task.

That is,

And testcookie can be found in the latter page.

However, I can't In PHP4.1.x

What's the problem?
A compromised method of using meta refresh of zero second is used.



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



Re: [PHP] Cookie, header, output problems

2003-01-14 Thread Vahan Yerkanian
You should not add any output after doing a "Location:" redirect. It's
recommended to add an exit() after the header(). Proper browsers should
halt their renderer and redirect when they find a Location: header.

HTH,
Vahan

J. Alden Gillespy wrote:

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";
		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




Re: [PHP] Cookie, header, output problems

2003-01-14 Thread Chris Shiflett
--- "J. Alden Gillespy" <[EMAIL PROTECTED]> wrote:
> I'm creating an e-commerce website, and I just need
> clarification as to whether a MySQL query is
> considered as "browser output". 

It is not. However, a MySQL error is indeed output. Make
sure your query is successful.

My suggestion would be to simplify your code. Test your
queries independently of setting cookies and redirecting.
You have too many potential cases for error as it is, and
that makes things difficult.

> mysql_query("select * from `$cart->user_table` where
> username=\"$username\" and userpass=\"$userpass\"",
> $cart->dblink)

I'm not sure if it is just formatting or my eyes, but it
looks like you have backticks in your query. Also, you
should consider using single quotes around your values
rather than escaped double quotes.

> setcookie("jackloren_user", "$username:$userpass", time()
> + 2592000);
> header("Location: http://www.jackloren.com/";);

You should test this combination separately. Depending on
several factors, your cookie may not be getting set due to
the Location header redirect. The combination works fine
with most modern Web agents, but it has been known to pose
problems for developers.

Chris

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




[PHP] Cookie, header, output problems

2003-01-14 Thread J. Alden Gillespy
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";
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




Re: [PHP] COOKIE HEADER????

2002-02-15 Thread Michael Sims

At 02:33 PM 2/15/2002 +0100, marcbey wrote:
>i dont know how i have to send it back, because i dont kown where and how to
>put the
>ASPSESSIONIDKJHKJHHKJH=HJVHJGHJGJGHJGJHGKJ information (in the header?)

This document may help:

http://developer.netscape.com:80/docs/manuals/js/client/jsref/cookies.htm


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




[PHP] COOKIE HEADER????

2002-02-15 Thread marcbey

hey php guys,

i have a problem:
i have extracted cookie information from the header of an ASP site in an PHP
script,
and now i want to send these session information back to an ASP site in
order that the ASP site
remember me.
i dont know how i have to send it back, because i dont kown where and how to
put the
ASPSESSIONIDKJHKJHHKJH=HJVHJGHJGJGHJGJHGKJ information (in the header?)



any idea???
greetings marc




--
---
magic garden GmbH - Agentur für Informationsarchitektur

Hermannstr. 15 - 70178 Stuttgart (Am Feuersee)

www.magic-garden.de ¦ [EMAIL PROTECTED]

Tel. (07 11) 619 57-42 ¦ Fax (07 11) 615 01 38




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