473,404 Members | 2,213 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,404 software developers and data experts.

setcookie issue

I'm going to try to simplify this issue as much as possible.

In my public_html/ directory, I have a login script that sets a cookie to be
used for authentication purposes. To set the cookie, it has something like
this:

<?php
setcookie('code',$value, time + $lifetime, '/', '.example.com');
?>

This, to my knowledge, is supposed to set a cookie named code with a value
of $value and an expiration date of time + $lifetime. Additionally, it is
to be read in public_html and all subdirectories over the entire domain of
*.example.com

Yet if I'm trying to get the value of the cookie, as in:

<?php
$cookie = $_COOKIE['code'];
echo $cookie;
?>

in a subdirectory, say public_html/auth/, the result of the second script is
nothing. If I put that same script in the public_html/ directory, it'll
print out my $value.

I'm using php 4.3

Any thoughts?

GregoryD
Oct 8 '06 #1
6 2054
GregoryD wrote:
I'm going to try to simplify this issue as much as possible.

In my public_html/ directory, I have a login script that sets a cookie to be
used for authentication purposes. To set the cookie, it has something like
this:

<?php
setcookie('code',$value, time + $lifetime, '/', '.example.com');
?>

This, to my knowledge, is supposed to set a cookie named code with a value
of $value and an expiration date of time + $lifetime. Additionally, it is
to be read in public_html and all subdirectories over the entire domain of
*.example.com

Yet if I'm trying to get the value of the cookie, as in:

<?php
$cookie = $_COOKIE['code'];
echo $cookie;
?>

in a subdirectory, say public_html/auth/, the result of the second script is
nothing. If I put that same script in the public_html/ directory, it'll
print out my $value.

I'm using php 4.3

Any thoughts?

GregoryD

Which browser are you using, and what are the security settings?
Cookies have to be received from the browser before your code can access
them.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Oct 8 '06 #2
On Sun, 8 Oct 2006 14:19:38 -0500, "GregoryD" <de**********@gmail.comwrote:
>I'm going to try to simplify this issue as much as possible.

In my public_html/ directory, I have a login script that sets a cookie to be
used for authentication purposes. To set the cookie, it has something like
this:

<?php
setcookie('code',$value, time + $lifetime, '/', '.example.com');
?>
That would raise a warning "use of undefined constant 'time', assumed string"
if you have PHP error reporting set to a sensible level, and your expiry time
is likely to be way in the past - "time" should be "time()". But that might
just be a typo in your post.
>This, to my knowledge, is supposed to set a cookie named code with a value
of $value and an expiration date of time + $lifetime. Additionally, it is
to be read in public_html and all subdirectories over the entire domain of
*.example.com

Yet if I'm trying to get the value of the cookie, as in:

<?php
$cookie = $_COOKIE['code'];
echo $cookie;
?>

in a subdirectory, say public_html/auth/, the result of the second script is
nothing. If I put that same script in the public_html/ directory, it'll
print out my $value.

I'm using php 4.3

Any thoughts?
Does the browser already have a more specific cookie set with the same name
but for the /auth directory? If so, your first setcookie won't override it, and
this other cookie will be the one that's read.

Try clearing all cookies for the domain and trying again, and also using a
cookie viewer tool to see what you actually have set (e.g.
http://addneditcookies.mozdev.org/) and/or an HTTP headers viewer to see what
cookies the browser is really sending (http://livehttpheaders.mozdev.org/ or
http://www.fiddlertool.com/fiddler/).

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 8 '06 #3

"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:Wo******************************@comcast.com. ..
GregoryD wrote:
>I'm going to try to simplify this issue as much as possible.

In my public_html/ directory, I have a login script that sets a cookie to
be used for authentication purposes. To set the cookie, it has something
like this:

<?php
setcookie('code',$value, time + $lifetime, '/', '.example.com');
?>

This, to my knowledge, is supposed to set a cookie named code with a
value of $value and an expiration date of time + $lifetime.
Additionally, it is to be read in public_html and all subdirectories over
the entire domain of *.example.com

Yet if I'm trying to get the value of the cookie, as in:

<?php
$cookie = $_COOKIE['code'];
echo $cookie;
?>

in a subdirectory, say public_html/auth/, the result of the second script
is nothing. If I put that same script in the public_html/ directory,
it'll print out my $value.

I'm using php 4.3

Any thoughts?

GregoryD


Which browser are you using, and what are the security settings? Cookies
have to be received from the browser before your code can access them.
I've tried this on firefox 1.5, ie 6, and Opera 9, and all my security
permissions in the browsers are set to accept cookies. And yeah, I know
that cookies have to be received by the browser, which is why I specifically
pointed out that the code to receive the value in the cookie is in a second
script. One page has the setcookie, the second page (after a header
redirect) authenticates it. Sorry if that was a bit confusing.

GregoryD
Oct 8 '06 #4


GregoryD wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:Wo******************************@comcast.com. ..
>GregoryD wrote:
>>I'm going to try to simplify this issue as much as possible.

In my public_html/ directory, I have a login script that sets a cookie to
be used for authentication purposes. To set the cookie, it has something
like this:

<?php
setcookie('code',$value, time + $lifetime, '/', '.example.com');
?>

This, to my knowledge, is supposed to set a cookie named code with a
value of $value and an expiration date of time + $lifetime.
Additionally, it is to be read in public_html and all subdirectories over
the entire domain of *.example.com

Yet if I'm trying to get the value of the cookie, as in:

<?php
$cookie = $_COOKIE['code'];
echo $cookie;
?>

in a subdirectory, say public_html/auth/, the result of the second script
is nothing. If I put that same script in the public_html/ directory,
it'll print out my $value.

I'm using php 4.3

Any thoughts?

GregoryD

Which browser are you using, and what are the security settings? Cookies
have to be received from the browser before your code can access them.

I've tried this on firefox 1.5, ie 6, and Opera 9, and all my security
permissions in the browsers are set to accept cookies. And yeah, I know
that cookies have to be received by the browser, which is why I specifically
pointed out that the code to receive the value in the cookie is in a second
script. One page has the setcookie, the second page (after a header
redirect) authenticates it. Sorry if that was a bit confusing.

GregoryD

Hi,

When you use a header redirect, the just set cookie will not be known in the
redirect page.
You have to use another way to set the cookie before the redirect. Use this
little function to set the cookie and it will work!

function set_cookie($name, $value = '', $expires = 0, $path = '', $domain = '',
$secure = false, $http_only = false)
{
header('Set-Cookie: ' . rawurlencode($name) . '=' . rawurlencode($value)
. (empty($expires) ? '' : '; expires=' . gmdate('D,
d-M-Y H:i:s \\G\\M\\T', $expires))
. (empty($path) ? '' : '; path=' . $path)
. (empty($domain) ? '' : '; domain=' . $domain)
. (!$secure ? '' : '; secure')
. (!$http_only ? '' : '; HttpOnly'), false);
}
Oct 8 '06 #5


GregoryD wrote:
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:Wo******************************@comcast.com. ..
>GregoryD wrote:
>>I'm going to try to simplify this issue as much as possible.

In my public_html/ directory, I have a login script that sets a cookie to
be used for authentication purposes. To set the cookie, it has something
like this:

<?php
setcookie('code',$value, time + $lifetime, '/', '.example.com');
?>

This, to my knowledge, is supposed to set a cookie named code with a
value of $value and an expiration date of time + $lifetime.
Additionally, it is to be read in public_html and all subdirectories over
the entire domain of *.example.com

Yet if I'm trying to get the value of the cookie, as in:

<?php
$cookie = $_COOKIE['code'];
echo $cookie;
?>

in a subdirectory, say public_html/auth/, the result of the second script
is nothing. If I put that same script in the public_html/ directory,
it'll print out my $value.

I'm using php 4.3

Any thoughts?

GregoryD

Which browser are you using, and what are the security settings? Cookies
have to be received from the browser before your code can access them.

I've tried this on firefox 1.5, ie 6, and Opera 9, and all my security
permissions in the browsers are set to accept cookies. And yeah, I know
that cookies have to be received by the browser, which is why I specifically
pointed out that the code to receive the value in the cookie is in a second
script. One page has the setcookie, the second page (after a header
redirect) authenticates it. Sorry if that was a bit confusing.

GregoryD

PS... found this solution is the user comments at php.net in the setcookie part! ;)
Oct 8 '06 #6

"Snef" <s.******@snefit.comwrote in message
news:9b***************************@news.chello.nl. ..
>

GregoryD wrote:
>"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:Wo******************************@comcast.com ...
>>GregoryD wrote:
I'm going to try to simplify this issue as much as possible.

In my public_html/ directory, I have a login script that sets a cookie
to be used for authentication purposes. To set the cookie, it has
something like this:

<?php
setcookie('code',$value, time + $lifetime, '/', '.example.com');
?>

This, to my knowledge, is supposed to set a cookie named code with a
value of $value and an expiration date of time + $lifetime.
Additionally, it is to be read in public_html and all subdirectories
over the entire domain of *.example.com

Yet if I'm trying to get the value of the cookie, as in:

<?php
$cookie = $_COOKIE['code'];
echo $cookie;
?>

in a subdirectory, say public_html/auth/, the result of the second
script is nothing. If I put that same script in the public_html/
directory, it'll print out my $value.

I'm using php 4.3

Any thoughts?

GregoryD
Which browser are you using, and what are the security settings? Cookies
have to be received from the browser before your code can access them.

I've tried this on firefox 1.5, ie 6, and Opera 9, and all my security
permissions in the browsers are set to accept cookies. And yeah, I know
that cookies have to be received by the browser, which is why I
specifically pointed out that the code to receive the value in the cookie
is in a second script. One page has the setcookie, the second page
(after a header redirect) authenticates it. Sorry if that was a bit
confusing.

GregoryD
PS... found this solution is the user comments at php.net in the setcookie
part! ;)
Thanks, I'll give it a try tomorrow.

GregoryD
Oct 8 '06 #7

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

Similar topics

16
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...
3
by: RotterdamStudents | last post by:
For registering a user to one of my sportleagues i use a little part of undeneath script to set a cookie. but this returns the next fault when a new user registers: Warning: setcookie()expects...
5
by: Ben | last post by:
Hi all, In my .php file, I'm using both session_start() and setcookie() before <html> tag. It gives me following warning message: Warning: Cannot modify header information - headers already...
3
by: Cmaza | last post by:
Hi, I've been dealing with PHP for a few years now and I've never encountered a problem quite like this. I've searched the net for an answer to my problem hoping somebody else may have...
6
by: knkk | last post by:
I am not able to locate the cookies created by the setCookie function. They are not in the standard IE folder where temporary Internet files and cookies are placed. Does anyone know where I search,...
9
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000."...
8
by: SupraFast | last post by:
I have two hosting accounts. On one, my setcookie script works fine; cookies are created. On the other, the same script doesn't work. The function returns TRUE, but no cookies is created. I...
9
by: wangers16 | last post by:
Hi, I am quite new to PHP and recently I have been attempting to create a login script, just one problem, the setcookie function isn't working. I have tried a basic php file with nothing other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...
0
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,...
0
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...

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.