Forum Moderators: coopster
setcookie("user", $username, $time+3600, '/');
This Cookie is very easily accessible by all the files which are in the root directories..
but when i try to access them from
www.example.com/discussions
These are not accessible.
But on my local server (Apache), it works fine..
Any suggestions?
The way I set up my cookie..from the file : www.example.com/login.php
setcookie("user", $username, $time+3600, '/', '.example.com');
session_register("password");
Now, there is a forum kind of a thing in : www.example.com/discussion
and the following is a part for navigation settings in the header file in the discussion folder :
if ( (isset($_COOKIE['user'])) && (session_is_registered("password"))) {
echo "
<li>
<a href='../main.php' title='See your portfolio status as on today'>Portfolio</a>
</li>....
Well, if I login and then open this...there is no change in the navigation area...
I even tried print_r($_COOKIE)..nothing was echoed...
All my files in the discussion are to be accessible only if the user is logged in...and as it is..i can't access anything...please help..its driving me nuts!
Thanks.
Ayush
be sure that the session_is_registered call is returning true
try changing the name of your cookie to see if there is a conflict
check the config differences between local and web
aside form that, don't worry about that test, just get the cookie set. Once you can confirm it is being set properly.
always remember
Cookies will not become visible until the next loading of a page that the cookie should be visible for. To test if a cookie was successfully set, check for the cookie on a next loading page before the cookie expires. Expire time is set via the expire parameter. A nice way to debug the existence of cookies is by simply calling print_r($_COOKIE);.
it echoed the set cookie and a PHPSESSID..but this phpsessid does not have the value, i want to have.
however, i wrote print_r($_COOKIE); in the header.php which is included in the index.php in the following way :
ob_start();
session_start();
include('../mysql.php');
//declare header variables
$title = 'Discussion Board';
$script = 'js.js';
include('header.php');
It echoed :
Array ( [PHPSESSID] => 057f6a4dedb0d2e057a4554abf98b9fa [user] => ayush )
But, when I ran header.php individually, it echoed :
Array ( [PHPSESSID] => c52de6392ae187719ac9a782e618be35 [user] => ayush )
The value of second PHPSESSID is correct but i dont know where the first one is from..
I am not sure why you are setting one value in the session and one in the cookie
why not put both values in the session? (makes me think logic confusion is causing the issue here)