/    Sign up×
Community /Pin to ProfileBookmark

Sessions and Cookies not global among all pages

Hi,
I run into a problem which didn’t occur to me until now. I have been using cookies and session global variables before and they always worked but right now on my login page, right after the user is validated, the cookie I set is displayed with the correct value while after I redirect the user to another page, the cookie value becomes null for some reason. The same thing happens with the session variables… Here’s the line of code for setting the cookie:

setcookie(“email”,$email, time()+3600);

Do you have any idea why this happens?

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Jul 11.2012 — Different domains with the requests? i.e. sub.domain.com verses www.domain.com or domain.com?
Copy linkTweet thisAlerts:
@paultimoceauthorJul 11.2012 — The server is located at www.eveduhamel.com ... it is not a subdomain... However, for the moment, the database is not hosted with the same host provider... The website will be moved to www.trendiac.com this week probably...
Copy linkTweet thisAlerts:
@paultimoceauthorJul 12.2012 — I just checked the cookie variable I have been setting yesterday by going to Firefox's Options menu in the Privacy tab and it is still there with the right values I gave them... The thing is that I cannot display them for the user to see... Is this syntax incorrect? echo($_COOKIE['test']);
Copy linkTweet thisAlerts:
@criterion9Jul 12.2012 — Can you show some more code? Like a sample page that sets the cookie and a sample page that reads the cookie with the minimum amount of code to reproduce the problem.
Copy linkTweet thisAlerts:
@paultimoceauthorJul 12.2012 — It is as simple as... for now... I just want to have it working...

[B]Login.php[/B]

<?php setcookie("test",'testing', time()+3600); ?> (this is placed in the body tag)

[B]index.php[/B]

if (isset($_COOKIE['test'])) {

echo('test');

}
Copy linkTweet thisAlerts:
@paultimoceauthorJul 12.2012 — [B]I also get the following error message in login.php...[/B]

Warning: Cannot modify header information - headers already sent by (output started at /home/eveduha/public_html/trendiac.com/dev/test/login.php:11) in /home/eveduha/public_html/trendiac.com/dev/test/login.php on line 32
Copy linkTweet thisAlerts:
@paultimoceauthorJul 12.2012 — [B]on lines 10 - 12 in the login.php page I have[/B]

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php include('includes/variables.php'); ?>

<?php include('includes/imports.php'); ?>
Copy linkTweet thisAlerts:
@paultimoceauthorJul 12.2012 — I think I found the solution to the cookie variable issue... It was only the fact that the cookie was set from the file include/login.php and the index.php file was not placed in the same folder... I have set the path parameter to "/" and it now works fine...
×

Success!

Help @paultimoce spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...