473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem to set a cookie

Hi!

I validate a user and set a cookie woht the following sentence:

setcookie("usNick",$nickN,time()+7776000);
setcookie("usPass",$passN,time()+7776000);

then I want to validate if the cookie is set with the following
sentence and it seems to enter in the "else", so the cookie was not
established.

if(isset($HTTP_COOKIE_VARS["usNick"]) &&
isset($HTTP_COOKIE_VARS["usPass"]))
{
$result = mysql_query("SELECT * FROM usuarios WHERE nick='".
$HTTP_COOKIE_VARS["usNick"]."' AND password='".
$HTTP_COOKIE_VARS["usPass"]."'");
}
else
{
setcookie("usNick","x",time()-3600);
setcookie("usPass","x",time()-3600);
}

Can anyone help me with this? I mena, setting the cookie correctly

Regards,

Ezequiel

Feb 4 '07 #1
1 1554
Rik
zek2005 <es*******@gmail.comwrote:
Hi!

I validate a user and set a cookie woht the following sentence:

setcookie("usNick",$nickN,time()+7776000);
setcookie("usPass",$passN,time()+7776000);

then I want to validate if the cookie is set with the following
sentence and it seems to enter in the "else", so the cookie was not
established.

if(isset($HTTP_COOKIE_VARS["usNick"]) &&
isset($HTTP_COOKIE_VARS["usPass"]))
{
$result = mysql_query("SELECT * FROM usuarios WHERE nick='".
$HTTP_COOKIE_VARS["usNick"]."' AND password='".
$HTTP_COOKIE_VARS["usPass"]."'");
}
else
{
setcookie("usNick","x",time()-3600);
setcookie("usPass","x",time()-3600);
}

Can anyone help me with this? I mena, setting the cookie correctly
First of all: never, never, never, never save a password in a cookie.
Second: use $_COOKIE.
Third: the cookie will only be set for future request, this request was
made without a cookie, so even if you set a cookie now it won't show up in
the $_COOKIE array automagically.

I suspect your more helped by just using sessions:
<http://www.php.net/session>
--
Rik Wasmus
Feb 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
0
by: pwldev | last post by:
Sorry if this isn't a good place for this question. I have a problem with losing cookie values whenever a user's local machine date/time is behind the date & time of the IIS machine. The login...
2
by: Syed Ghayas | last post by:
Hi, I've been having problem writing a cookie. Everything goes ok but when I supply the .Path property to "/" It just write the cookie when there is no cookie present, but when I try to update the...
7
by: Christoph Pieper | last post by:
Hi, we've the following problem : We have an asp-application which sets the cookie on first login. The cookie will never be touched during user access. The user can work the whole day, but...
1
by: Michal A. Valasek | last post by:
Hello, I have problem deleting cookies and cookies values (using framework version 1.1 on W2003). When I try to remove entire cookie, by calling Response.Cookies.Remove("Test"), nothing...
11
by: ElmoWatson | last post by:
I tried on the Security newgroup, as well as other places, and haven't gotten an answer yet - - I'm pulling my hair out over this one. I'm trying to get Forms Authentication working.....I can get...
1
by: Satinderpal Singh | last post by:
Hi everyone, We are using HttpWebRequest to create a request to a URI, which requires us to login first. In order to process all the transactions, first we have to login and get the cookie value...
3
by: rss | last post by:
SUMMARY: ========== I am unable to pass along a simple Cookie obtained from a HttpWebRequest call (Machine A's ASP.NET app) so that another Web Server (Machine B) recongnizes the cookie. I...
5
by: Bill Nicholson | last post by:
Maybe I don't understand cookies correctly. When some visits my site and logs in, they get a cookie that stores their login information. When they come back, that info is read from the cookie and...
3
by: sewen | last post by:
Dear all, I got a problem when i tried to access cookie in my project. There are 2 pages in the project:a.aspx and b.aspx. In a.aspx,i put the fololowing scripts: function SetCookie(name,value {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.