473,791 Members | 2,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2077
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*******@attgl obal.net
=============== ===
Oct 8 '06 #2
On Sun, 8 Oct 2006 14:19:38 -0500, "GregoryD" <de**********@g mail.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('cod e',$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.co m

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.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 8 '06 #3

"Jerry Stuckle" <js*******@attg lobal.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('cod e',$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*******@attg lobal.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('co de',$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.
Additionall y, 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($nam e, $value = '', $expires = 0, $path = '', $domain = '',
$secure = false, $http_only = false)
{
header('Set-Cookie: ' . rawurlencode($n ame) . '=' . rawurlencode($v alue)
. (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*******@attg lobal.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('co de',$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.
Additionall y, 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.******@snefi t.comwrote in message
news:9b******** *************** ****@news.chell o.nl...
>

GregoryD wrote:
>"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:Wo******* *************** ********@comcas t.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('c ode',$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
11320
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);
3
3406
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 parameter 2 to be string object given in *.php on line 21 21: while (!setcookie("USER",$User, time()+3600)) { 22: $errmsg = $Unable_to_register_txt; 23: LogMsg($errmsg);
5
6463
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 sent by (output started at D:\Apache Group\Apache2\htdocs\YC\songs.php:4) in D:\Apache Group\Apache2\htdocs\YC\ycphpfunc.php on line 148 My .php file looks like this:
3
2296
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 encountered this, but without any luck, so I now resolve to pose the question myself. Code: <?php $somedata="Lorem Ipsum";
6
2675
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, or how I trace them? Also, I created cookies using this command: $string_to_check = $type."_".$pid; setCookie("$string_to_check", "1", time()+30*1); The cookie doesn't expire in 30 seconds - in fact, it doesn't seem to expire at all.
9
2298
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." 4. Display last modified date of doc. Here is my attempt. What a headache :-(
8
5873
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 checked to make sure that the variables have values and that the proper expire time is set and etc. Any ideas? <?php foreach($_POST as $name => $value){ if($name == 'hItem'){ $item = $value;
9
26259
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 than a function to set and retrieve the cookie but still nothing. Why is this happening?
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7537
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4110
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
3
2916
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.