www.webdeveloper.com
Results 1 to 9 of 9

Thread: Sessions and Cookies not global among all pages

  1. #1
    Join Date
    Jul 2012
    Posts
    13

    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?

  2. #2
    Join Date
    Jan 2009
    Posts
    3,346
    Different domains with the requests? i.e. sub.domain.com verses www.domain.com or domain.com?

  3. #3
    Join Date
    Jul 2012
    Posts
    13
    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...

  4. #4
    Join Date
    Jul 2012
    Posts
    13
    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']);

  5. #5
    Join Date
    Jan 2009
    Posts
    3,346
    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.

  6. #6
    Join Date
    Jul 2012
    Posts
    13
    It is as simple as... for now... I just want to have it working...

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

    index.php
    if (isset($_COOKIE['test'])) {
    echo('test');
    }

  7. #7
    Join Date
    Jul 2012
    Posts
    13
    I also get the following error message in login.php...

    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

  8. #8
    Join Date
    Jul 2012
    Posts
    13
    on lines 10 - 12 in the login.php page I have

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <?php include('includes/variables.php'); ?>
    <?php include('includes/imports.php'); ?>

  9. #9
    Join Date
    Jul 2012
    Posts
    13
    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...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles