#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Pennsylvania, USA
    Posts
    37
    Rep Power
    15
    Help please!

    I am executing a cgi-script using a username and password sent via hidden
    fields from another location. This cgi-script simply creates database
    records (if the first time this user has visited), then needs to pass
    control to a static html page. By the time I get to the html page, I need to
    have a cookie set, but we don't want any screens to show up in between -
    basically the whole cgi-script processing is invisible. Once finished with
    the update, I send the username via a hidden field in an autosubmitted form
    to a php script in order to get the cookie set.

    Now, in order to get the cookie set, I execute a 'self-check' routine in php
    (this routine is right out of the Professional PHP Programming Book, by Wrox
    Press). This scripts sets the cookie then redirects to itself. The second
    time through this script, it checks to see if the cookie exists - if it
    doesn't, it gives a message "...Please enable cookies". If it does - it
    redirects to the static html page. The code is below.

    My problem is that the first time through this whole process (cgi-script to
    php script - in a new browser session), I get the error "...Please enable
    cookies" (which I DO have enabled). If I then send through a second username
    and password and go through the whole process (same browser session) - this
    time it works, and sets the cookie with the second username.

    Can someone help a newbie and tell me what I'm doing wrong?

    The php script (test.php3; passname is the hidden field from the
    cgi-script):

    <?php
    if (empty($check))
    {
    $page = "test.php3?check=1";

    setcookie("UserName", $passname);
    header ("Location: $page");
    }
    else
    {
    if (empty($UserName))
    {
    echo "Could not set cookie. Please enable cookies.";
    }
    else
    {
    header("Location: home.html");
    }
    }
    ?>

    Thanks in advance!
    Sharon


  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 1999
    Location
    London
    Posts
    110
    Rep Power
    0
    something funny with the $check, try this it worked for me
    <?
    if (!$check)
    {
    $page = "test3.php3?check=1";
    setcookie("UserName", $passname, time()+2678400);
    header ("Location: $page");
    }
    else
    {
    if (empty($UserName))
    {
    echo "Could not set cookie. Please enable cookies.";
    }
    else
    {
    header("Location: home.html");
    }
    }
    ?>

    hth

    tim


    ------------------
    cheers

Similar Threads

  1. Placing user-entered data into cookie
    By Tyrone in forum Perl Programming
    Replies: 2
    Last Post: February 17th, 2004, 05:31 PM
  2. Session Cookie Problem?
    By JHarp in forum PHP Development
    Replies: 1
    Last Post: February 17th, 2004, 02:43 PM
  3. re: Cookie - serves only one directory?
    By ellen in forum PHP Development
    Replies: 1
    Last Post: February 17th, 2004, 12:59 AM
  4. will PHP write over the same cookie?
    By xpatriot in forum PHP Development
    Replies: 5
    Last Post: February 2nd, 2004, 09:59 AM
  5. Odd COOKIE problem
    By rwreid in forum PHP Development
    Replies: 3
    Last Post: January 28th, 2004, 02:43 AM

IMN logo majestic logo threadwatch logo seochat tools logo