473,486 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Cookie dos not expire. Why?

Hello!
I made the code below.

<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test6",1, time()+10); //Create value 1
$Test6 = 1;
}
$numvisits = $Test6;
if ($numvisits<6)
{
print("ACCESS");
}

else
{
print("DENIED");
}
It works fine in my localhost and after 10 seconds,
if I reload It grant access, but it does not work on
my server.
Why?

[]

CAlos
Jul 17 '05 #1
5 2026
Carlos Marangon wrote:
Hello!
I made the code below.

<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test6",1, time()+10); //Create value 1
$Test6 = 1;
}
$numvisits = $Test6;
if ($numvisits<6)
{
print("ACCESS");
}

else
{
print("DENIED");
}
It works fine in my localhost and after 10 seconds,
if I reload It grant access, but it does not work on
my server.
Why?

[]

CAlos


Everytime you refresh the page $Test6 will never have a value... your
cookie is available in $_COOKIE['Test6'], not $Test6... Thus, before
your 'if' conditional statement at line 1, put in something like

$Test6=$_COOKIE['Test6'];

See if that helps you - if not, let me know and if I'll do my best to
help...

randelld
Jul 17 '05 #2
Hello!

It just works on localhost.

I am trying to make a code that deny user access when it typethe
incorrect password 3 times. The code works fine in my localhost but at
the server it alwauys says DENIED.

If you have any idea please reply me.
[]

Carlos
Reply via newsgroup <re****************@please.com> wrote in message news:<2pCZb.582042$ts4.45214@pd7tw3no>...
Carlos Marangon wrote:
Hello!
I made the code below.

<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test6",1, time()+10); //Create value 1
$Test6 = 1;
}
$numvisits = $Test6;
if ($numvisits<6)
{
print("ACCESS");
}

else
{
print("DENIED");
}
It works fine in my localhost and after 10 seconds,
if I reload It grant access, but it does not work on
my server.
Why?

[]

CAlos


Everytime you refresh the page $Test6 will never have a value... your
cookie is available in $_COOKIE['Test6'], not $Test6... Thus, before
your 'if' conditional statement at line 1, put in something like

$Test6=$_COOKIE['Test6'];

See if that helps you - if not, let me know and if I'll do my best to
help...

randelld

Jul 17 '05 #3
I noticed that Message-ID:
<2c*************************@posting.google.com> from Carlos Marangon
contained the following:
I am trying to make a code that deny user access when it typethe
incorrect password 3 times. The code works fine in my localhost but at
the server it alwauys says DENIED.

If you have any idea please reply me.


I use this - just include it at the beginning of any file you want to
protect.

<?php
// Check to see if $PHP_AUTH_USER already contains info

if (!isset($GLOBALS['PHP_AUTH_USER'])) {

// If empty, send header causing dialog box to appear

header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;

} else if (isset($GLOBALS['PHP_AUTH_USER'])) {

if (($GLOBALS['PHP_AUTH_USER'] != "Username") ||
($GLOBALS['PHP_AUTH_PW'] != "Password")) {

header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;

} else {
echo "
<P>You're authorized!</p>
";
}
}
?>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #4
Carlos Marangon wrote:
Hello!

It just works on localhost.

I am trying to make a code that deny user access when it typethe
incorrect password 3 times. The code works fine in my localhost but at
the server it alwauys says DENIED.

If you have any idea please reply me.
[]

Carlos


I'm sorry - I'm lost - I don't see how it would work since $Test6 should
never have a value everytime it starts, thus

$Test6++;
setcookie("Test6",$Test6, time()+10); // select cookie name

will mean $Test6 will always equal 1 everytime the browser refreshes...
and the cookie that is set will also be always set to 1 on that basis.
Thus, $Test6 (or $numvisits) will always be less than 6, therefore
always giving you access... Is there a time, when run locally, that you
get access denied? My guess is not...

I've relooked at your code and find it will not work as designed, even
if $Test6 had values... Hears why...

- $Test6 will always equal nothing since you've not given it a value
meaning the code in the first brace will *always* run. It will set a
cookie called Test6 to 1 and the cookie will expire in ten seconds. You
have a remark statement that says "select cookie name" - setcookie()
sets a cookie, it does not select it.
- The 'else' part of your if conditional statement never runs since
$Test6 never has a value. If it were to run, it would continually set
the cookie to the number 1, and set $Test6 to 1.
- $numvisits gets the value of $Test6 meaning you've now copied a
variable (?) and it too now equals 1.
- Your last if conditional statement says if $numvisits is less than 6
(which it is) then to grant access.

Conclusion: Access is always given...

Therefore, can you confirm that you do at some point, either locally or
on your server sometime or other get an ACCESS DENIED? My guess is you
never do, at anytime, regardless where the script is hosted.

<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test6",1, time()+10); //Create value 1
$Test6 = 1;
}
$numvisits = $Test6;
if ($numvisits<6)
{
print("ACCESS");
}

else
{
print("DENIED");
}
?>
Jul 17 '05 #5
Geoff Berrow wrote:
I noticed that Message-ID:
<2c*************************@posting.google.com> from Carlos Marangon
contained the following:

I am trying to make a code that deny user access when it typethe
incorrect password 3 times. The code works fine in my localhost but at
the server it alwauys says DENIED.

If you have any idea please reply me.

I use this - just include it at the beginning of any file you want to
protect.

<?php
// Check to see if $PHP_AUTH_USER already contains info

if (!isset($GLOBALS['PHP_AUTH_USER'])) {

// If empty, send header causing dialog box to appear

header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;

} else if (isset($GLOBALS['PHP_AUTH_USER'])) {

if (($GLOBALS['PHP_AUTH_USER'] != "Username") ||
($GLOBALS['PHP_AUTH_PW'] != "Password")) {

header('WWW-Authenticate: Basic realm="My Private Stuff"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;

} else {
echo "
<P>You're authorized!</p>
";
}
}
?>


I don't see how the above would resolve his situation - You've not given
him any information as to how he could authorize other users...

randelld
Jul 17 '05 #6

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

Similar topics

2
2439
by: Alexander Ross | last post by:
referring to the code below, will the cookie expire 24 hours after its created, or will it expire 24 hours after the last time I add a variable to the cookie?? if ($_POST){ if (!($_COOKIE)) ...
16
11281
by: Phil Powell | last post by:
Fourth attempt.. it fails now in login, I check by printing $_COOKIE and there is no value there! Guys, what on earth do I do about this???? Here is the code that sets the cookie: if...
2
5534
by: Michael | last post by:
I am reading and setting a cookie using JavaScript in the BODY onload and onunload events respectively. This works fine. However when I use ASP to set the cookie under some condition where I...
12
17941
by: chrism | last post by:
Hello, I have a pop-up window that I would like to appear in front of the browser home page when a user opens IE. Problem is, I'd like it to never appear again if the user navigates back to the...
4
3785
by: socialism001 | last post by:
I'm trying to store a value in a cookie but its not working. Can anyone see what I might be doing wrong. Thanks, Chris ~~~~~~~~~~~~~~~~~~ <script language="javascript">...
7
1655
by: p2 | last post by:
Hi, I'm setting a cookie with setcookie, and as long as I'm not closing the browser - the cookie is kept and passed to the next page. But as soon as I leave the site or close the browser, the...
15
3625
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via...
4
9637
by: Phil Powell | last post by:
I thought this would work but it seems to not work neither in Netscape nor in IE: <script type="text/javascript"> <!-- // OBTAINED FROM http://www.javascripter.net/faq/settinga.htm //...
23
3153
by: Phil Powell | last post by:
// OBTAINED FROM http://www.javascripter.net/faq/settinga.htm // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY AND THUS EXPIRE function setCookie(name, value, days, docObj)...
2
2691
by: rn5a | last post by:
A web.config file has the following code: <configuration> <system.web> <authentication mode="Forms"> <forms name="NETConnectCookie" loginUrl="Login.aspx"> <credentials passwordFormat="SHA1"/>...
0
7099
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
6964
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
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5430
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4864
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.