For Programmers: Free Programming Magazines  


Home > Archive > PHP on Windows > October 2004 > [PHP-WIN] Cookies!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [PHP-WIN] Cookies!
James Nunnerley

2004-10-07, 8:58 am

I'm trying to create a simple login script for user to the web application I'm
writing. I previously wrote it for using PHP4 & Apache, however I've recently
had to move to IIS5, and also upgraded to PHP5.
[script]
if (isset($_POST["username"]) AND isset($_POST["password"])) {
$res=mysql_query('SELECT username, password, agent_id FROM user where
username="'.$_POST["username"].'"');
if (mysql_num_rows($res)==0) {
$message="Username does not exist.";
} elseif (mysql_num_rows($res)==1) {
while ($user=mysql_fetch_array($res)) {
if (strtolower($user["password"])!=strtolower($_POST["password"])) {
$message="Incorrect Password.";
} else {
setcookie("username",$user["username"],time()+31449600,"/");
setcookie("agent_ID",$user["agent_id"],time()+31449600,"/");
setcookie("logged_in",time(),time()+60*60*12,"/");
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
exit;
}
}
}
}
[/script]

The above works fine on Apache, but on IIS, it would seem no cookie is set.
I've found something suggesting I change php.exe to nph-php.exe - is this true,
does it work - it seems a little drastic - is there another way around it?

Cheers as ever
Nunners
Sudeep Zamudra

2004-10-09, 8:55 am

Hi James,

Php on IIS or PWS are known to have problems with session and cookie. Try using session instead of cookie. That's the safest way. Also anyone can disable cookies on the client side where by your login authentcation may fail. So best way is us
e session instead of cookie. For details pls refer "php session handling" in the php Manual.

.....SuDeEp....

James Nunnerley <webmaster@jnsolutions.co.uk> wrote:
I'm trying to create a simple login script for user to the web application I'm
writing. I previously wrote it for using PHP4 & Apache, however I've recently
had to move to IIS5, and also upgraded to PHP5.
[script]
if (isset($_POST["username"]) AND isset($_POST["password"])) {
$res=mysql_query('SELECT username, password, agent_id FROM user where
username="'.$_POST["username"].'"');
if (mysql_num_rows($res)==0) {
$message="Username does not exist.";
} elseif (mysql_num_rows($res)==1) {
while ($user=mysql_fetch_array($res)) {
if (strtolower($user["password"])!=strtolower($_POST["password"])) {
$message="Incorrect Password.";
} else {
setcookie("username",$user["username"],time()+31449600,"/");
setcookie("agent_ID",$user["agent_id"],time()+31449600,"/");
setcookie("logged_in",time(),time()+60*60*12,"/");
header("Location: http://".$_SERVER["HTTP_HOST"]."/");
exit;
}
}
}
}
[/script]

The above works fine on Apache, but on IIS, it would seem no cookie is set.
I've found something suggesting I change php.exe to nph-php.exe - is this true,
does it work - it seems a little drastic - is there another way around it?

Cheers as ever
Nunners

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


________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Nunners

2004-10-11, 8:55 am

If I'm going to use sessions, I understand how to start them etc, but is it
possible to have them "alive" for 24 hours?

With the cookies, I was able to, once the user logged in, keep them logged
in for 24 hours.

As it's an application we are providing for our customers, one of the things
I'm able to stipulate is that they have IE6 & Cookies turned on!

Any thoughts?

Cheers
James

> -----Original Message-----
> From: Sudeep Zamudra [mailto:sudeep_zamudra@yahoo.com]
> Sent: 09 October 2004 09:14
> To: James Nunnerley
> Cc: php-windows@lists.php.net
> Subject: Re: [PHP-WIN] Cookies!
>
> Hi James,
>
> Php on IIS or PWS are known to have problems with session and
> cookie. Try using session instead of cookie. That's the safest way. Also
> anyone can disable cookies on the client side where by your login
> authentcation may fail. So best way is use session instead of cookie. For
> details pls refer "php session handling" in the php Manual.
>
> ....SuDeEp....
>
> James Nunnerley <webmaster@jnsolutions.co.uk> wrote:
> I'm trying to create a simple login script for user to the web application
> I'm
> writing. I previously wrote it for using PHP4 & Apache, however I've
> recently
> had to move to IIS5, and also upgraded to PHP5.
> [script]
> if (isset($_POST["username"]) AND isset($_POST["password"])) {
> $res=mysql_query('SELECT username, password, agent_id FROM user where
> username="'.$_POST["username"].'"');
> if (mysql_num_rows($res)==0) {
> $message="Username does not exist.";
> } elseif (mysql_num_rows($res)==1) {
> while ($user=mysql_fetch_array($res)) {
> if (strtolower($user["password"])!=strtolower($_POST["password"])) {
> $message="Incorrect Password.";
> } else {
> setcookie("username",$user["username"],time()+31449600,"/");
> setcookie("agent_ID",$user["agent_id"],time()+31449600,"/");
> setcookie("logged_in",time(),time()+60*60*12,"/");
> header("Location: http://".$_SERVER["HTTP_HOST"]."/");
> exit;
> }
> }
> }
> }
> [/script]
>
> The above works fine on Apache, but on IIS, it would seem no cookie is
> set.
> I've found something suggesting I change php.exe to nph-php.exe - is this
> true,
> does it work - it seems a little drastic - is there another way around it?
>
> Cheers as ever
> Nunners
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> ________________________________________
__________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com

Nunners

2004-10-26, 3:56 pm

Hi Dale,

Sorry for emailing you again (and anyone else who can help) - but I'm
getting a bit desperate!

I've got to finish this project today - 2 hours to go!!!!

I need to sort out the user authentication into the application - I'm using
IIS & PHP5 - which is proving a bit of a nightmare. I've decided cookies
are a no go, because of the cookie problems with IIS... so sessions it is!

However, I've looked at all sorts of things on the net, and can't find
anything that will help me write an user authentication setup for my web
pages....

Please please please can someone assist me!

Thanks
James


> -----Original Message-----
> From: Dale Attree [mailto:dale@kwikitsolutions.co.za]
> Sent: 12 October 2004 18:23
> To: Nunners
> Subject: RE: [PHP-WIN] Cookies!
>
> Yes, same concept, different implementation.
>
> -----Original Message-----
> From: Nunners [mailto:webmaster@jnsolutions.co.uk]
> Sent: 12 October 2004 16:34
> To: dale@kwikitsolutions.co.za
> Subject: RE: [PHP-WIN] Cookies!
>
>
> Could I also do this, using a link to mysql instead of the file? If so,
> then this might be a good option?!!!
>
> Cheers
> Nunners
>
> have
> logged
> Also
>
>
>
>
>
>

Zareef Ahmed

2004-10-27, 3:55 am

Hi,
Visit
http://www.phpclasses.org/browse/class/21.html

You may search the site for more classes.

http://pear.php.net is also a good site in this category.


Zareef ahmed

-----Original Message-----
From: Nunners [mailto:webmaster@jnsolutions.co.uk]
Sent: Tuesday, October 26, 2004 7:35 PM
To: dale@kwikitsolutions.co.za
Cc: php-windows@lists.php.net
Subject: RE: [PHP-WIN] Cookies!


Hi Dale,

Sorry for emailing you again (and anyone else who can help) - but I'm
getting a bit desperate!

I've got to finish this project today - 2 hours to go!!!!

I need to sort out the user authentication into the application - I'm
using IIS & PHP5 - which is proving a bit of a nightmare. I've decided
cookies are a no go, because of the cookie problems with IIS... so
sessions it is!

However, I've looked at all sorts of things on the net, and can't find
anything that will help me write an user authentication setup for my web
pages....

Please please please can someone assist me!

Thanks
James


> -----Original Message-----
> From: Dale Attree [mailto:dale@kwikitsolutions.co.za]
> Sent: 12 October 2004 18:23
> To: Nunners
> Subject: RE: [PHP-WIN] Cookies!
>
> Yes, same concept, different implementation.
>
> -----Original Message-----
> From: Nunners [mailto:webmaster@jnsolutions.co.uk]
> Sent: 12 October 2004 16:34
> To: dale@kwikitsolutions.co.za
> Subject: RE: [PHP-WIN] Cookies!
>
>
> Could I also do this, using a link to mysql instead of the file? If
> so, then this might be a good option?!!!
>
> Cheers
> Nunners
>
[color=darkred]
> have
> logged
> Also
where[color=darkred]
{[color=darkred]
[color=darkred]
>

------------------------------------------------------------------------
--
Zareef Ahmed :: A PHP develoepr in Delhi ( India )
Homepage :: http://www.zasaifi.com

Sudeep

2004-10-27, 3:55 am

Hi James,

While using sessions the timeout period can be set in the php.ini file(not sure). The other option is that once you authenticate the user and he is logged in, simultaneously create a session - say $_SESSSION[''logged_in"]=1. And include a s
cript at the top of every file he visits after logging in. That script should update...i.e again create $_SESSION["logged_in"]=1. This should repeat at the begining of each php file after logging in. Where by the session will be alive as long as the user
visits different pages on the site.(But what happens when he is idle with a particular pahe open for a long time........)....I don't know whether u got my idea or not. Don't lose hope. Make a wild search on the net regarding this. Also look for archives o
f the mailing list. You'll defenitely get a solution for this ....GOOD LUCK
Atlast my sincere advise to u....Go for Apcahe server for php.....not IIS or PWS.

.....SuDeEp......

Nunners <webmaster@jnsolutions.co.uk> wrote:
Hi Dale,

Sorry for emailing you again (and anyone else who can help) - but I'm
getting a bit desperate!

I've got to finish this project today - 2 hours to go!!!!

I need to sort out the user authentication into the application - I'm using
IIS & PHP5 - which is proving a bit of a nightmare. I've decided cookies
are a no go, because of the cookie problems with IIS... so sessions it is!

However, I've looked at all sorts of things on the net, and can't find
anything that will help me write an user authentication setup for my web
pages....

Please please please can someone assist me!

Thanks
James


> -----Original Message-----
> From: Dale Attree [mailto:dale@kwikitsolutions.co.za]
> Sent: 12 October 2004 18:23
> To: Nunners
> Subject: RE: [PHP-WIN] Cookies!
>
> Yes, same concept, different implementation.
>
> -----Original Message-----
> From: Nunners [mailto:webmaster@jnsolutions.co.uk]
> Sent: 12 October 2004 16:34
> To: dale@kwikitsolutions.co.za
> Subject: RE: [PHP-WIN] Cookies!
>
>
> Could I also do this, using a link to mysql instead of the file? If so,
> then this might be a good option?!!!
>
> Cheers
> Nunners
>
> have
> logged
> Also
>
>
>
>
>
>


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



---------------------------------
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com