473,549 Members | 5,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cookie dos not expire. Why?

Hello!
I made the code below.

<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test 6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test 6",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 2033
Carlos Marangon wrote:
Hello!
I made the code below.

<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test 6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test 6",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.582 042$ts4.45214@p d7tw3no>...
Carlos Marangon wrote:
Hello!
I made the code below.

<?php
if ($Test6 != '') {
$Test6++;
setcookie("Test 6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test 6",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************ *************@p osting.google.c om> 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($GLOBAL S['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("Test 6",$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("Test 6",$Test6, time()+10); // select cookie name
} else {
setcookie("Test 6",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************ *************@p osting.google.c om> 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($GLOBAL S['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
2442
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)) setcookie("adagame-5q24h",$_POST,time()+60*60*24,"/","",0); else setcookie("adagame-5q24h",$_POST);
16
11292
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 ($hasLoggedIn && ($row = mysql_fetch_row($query))) { setcookie('nordicnet_registration', $row, 0, '/'); @mysql_free_result($query);
2
5552
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 want to override the last value set in the onunload event, it has no effect. The next onload still has the old value. Any ideas? The following code...
12
17958
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 home page during their time using the browser. However, if the user closes the browser, then reopens, the pop-up should appear again. (you may...
4
3798
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"> if(document.cookie.indexOf("beenHere1=true")!=-1) else
7
1665
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 cookie is gone, ans there is nothing in $_COOKIE dor the next time. The cookie is not shown in the cookies folder.
15
3633
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 HttpCookie.Expires property, but property value is the time of day on the client. How can I possibly know client local time ?
4
9665
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 // NOTE THAT IF YOU SET days TO -1 THE COOKIE WILL BE SET TO YESTERDAY
23
3165
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) { var today = new Date(); var expire = new Date(); if (days == null || isNaN(days) || days == 0) days = 1; if (days >= 1 || days < 0)...
2
2697
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"/> </forms> </authentication> </system.web>
0
7962
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7480
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5373
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
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 we have to send another system
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
769
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.