Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:32:27+00:00 2026-05-24T10:32:27+00:00

This little PHP snippet is used to set a cookie that lets me determine

  • 0

This little PHP snippet is used to set a cookie that lets me determine whether or not a user is logged in. For some reason, after I use the javascript to redirect, none of my cookies are set any more. Any reason why this would be happening?

I may not be giving you enough info so let me know if so.

...some database queries...
<?php 
    $expire=time()+(7 * 24 * 60 * 60);
    $row = mysql_fetch_array($query);
    $email = $row['email'];
    $userinfo['name'] = $name;
    $userinfo['email'] = $email;
    $userinfo = serialize($userinfo);
    setcookie("user", $userinfo, $expire);
    echo '<script type="text/javascript">
        window.location = "../index.php";
    </script>';

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:32:27+00:00Added an answer on May 24, 2026 at 10:32 am

    Function setcookie returns true or false, depending on whether cookie was set successfully. You could try this to test:

    if(!setcookie("user", $userinfo, $expire)) {
        echo 'Could not set cookie!';
    }
    

    If this returns false, then Kumar is right. Otherwise there has to be some other reason.

    EDIT setcookie can be called with more parameters, like this:

    setcookie(name,value,expire,path,domain,secure)
    

    Notice the path and domain values. I have had problems in the past with two different pages not find each other’s cookies because of different paths/domains.

    I noticed that You redirect to “../index.php”. Try redirecting to “index.php” and see if the cookies exist there. If yes, then You should use a common “path” variable to set cookies.

    From http://www.php.net/setcookie about “path” variable:

    The path on the server in which the cookie will be available on. If set to ‘/’, the cookie will be available within the entire domain. If set to ‘/foo/’, the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found this little script in PHP that send a simple request to
I have this little php snippet: // $test='test'; $test='just a test'; echo <a href=javascript:myfunction($number,$src_req,\.$test.\)><img
I'd like to have a little php module. This module would have methods that
I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
This is a little tricky so bear with me: I have a PHP script
My php is a little rusty but this is boggling my mind right now.
This is my first question :). Im writing a little twitter app in PHP
its a little bit hard to understand. in the header.php i have this code:
Ok, this situation is a little weird but anyway. This PHP code generates several
I made this little Cocoa app with a WebView that displays Google Maps in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.