www.webdeveloper.com
Results 1 to 5 of 5

Thread: Cookie Problem

  1. #1
    Join Date
    Jan 2004
    Location
    Atlanta, GA
    Posts
    40

    Cookie Problem

    Hello:

    I have a login script in which I want to set a cookie. A cookie should be set only if a user checks the box, Remember Me.

    When I run my script, I'm receiving a blank page. I tried placing the code in different places within the script and the result is always the same.

    Can someone take a look at my script and help me set my cookie properly?

    Thank you very much.

    Here's the script:

    <?php
    session_start();
    header("Cache-control: private");
    include "conn.inc.php";
    switch($_REQUEST['req'])
    {
    case "validate":



    $validate = mysql_query("SELECT * FROM member WHERE
    username = '{$_POST['username']}' AND password = md5('{$_POST['password']}')") or
    die (mysql_error());

    if (mysql_num_rows($validate) == 1)
    {
    while($row = mysql_fetch_assoc($validate))
    {
    $_SESSION["status"] = "Logged";
    $_SESSION['memberid'] = $row['memberid'];
    $_SESSION['first_name'] = $row['first_name'];
    $_SESSION['last_name'] = $row['last_name'];
    $_SESSION['email'] = $row['email'];
    $_SESSION['phone1'] = $row['phone1'];
    $_SESSION['phone2'] = $row['phone2'];
    $_SESSION['username'] = $row['username'];
    $_SESSION['password'] = $row['password'];

    if ($_POST[remember] == "Yes")
    {
    setcookie("username", $_SESSION['username'], time()+(60*60*24), ".http://www.bridgemilltennis.com";
    setcookie("password", $_SESSION['password'], time()+(60*60*24), ".http://www.bridgemilltennis.com";
    }

    $login_time = mysql_query("UPDATE member SET last_login=now() where memberid='{$row['memberid']}'");

    }
    header("Location: http://www.bridgemilltennis.com/mem...r-area-main.php");
    }
    else
    {
    $_SESSION["status"] = "Not logged";
    $_SESSION['username'] = Guest;
    header("Location: http://www.bridgemilltennis.com/mem.../login_form.php");
    exit;
    }
    break;
    }
    ?>

  2. #2
    Join Date
    Oct 2003
    Posts
    379
    the only thing i can think of is on these two lines:

    setcookie("username", $_SESSION['username'], time()+(60*60*24), ".http://www.bridgemilltennis.com";
    setcookie("password", $_SESSION['password'], time()+(60*60*24), ".http://www.bridgemilltennis.com";

    you have ".http:blahblah";

    what it should be is either "http://blahblah"; or ".http://blahblah."; not sure which you are tring to do or which would be appropriate
    Only Those Who Listen Prosper
    ~GD~

  3. #3
    Join Date
    Jan 2004
    Location
    Atlanta, GA
    Posts
    40
    Hi,

    I tried your suggestion by fixing the domain and it still isn't working.

  4. #4
    Join Date
    Oct 2003
    Posts
    379
    try changing the redirect script with the html version
    Code:
    <meta http-equiv="refresh" content="1;pagetogoto">
    see if that works
    Only Those Who Listen Prosper
    ~GD~

  5. #5
    Join Date
    Jan 2004
    Location
    Atlanta, GA
    Posts
    40
    Hi,

    I was able to get the setting of the cookie to work.

    Here's what I want to do and I can't get this to work. On the login page, a user can check a box so that the next time they login they will be remembered. In the form, I have: <input type="checkbox" name="remember" value="Yes">.

    In theory, if I wrote the following statement, the information for the user should be remembered, but it's not:

    if ($_POST[remember] == "Yes")
    {
    setcookie('member', 'member', time()+24*3600*60);
    }

    How could I modify my script to make the above statement to work? Should I include a field in my database table that will flag who wants to or not wants to be remembered and then set the cookie? I'm not sure. The code on the bottom doesn't include the above statement because no matter where I stick it, it won't work.

    Thanks for the help.

    Here's the script:
    <?php
    session_start();
    header("Cache-control: private");
    include "conn.inc.php";

    switch($_REQUEST['req'])
    {
    case "validate":




    $validate = mysql_query("SELECT * FROM member WHERE
    username = '{$_POST['username']}' AND password = md5('{$_POST['password']}')") or
    die (mysql_error());

    if (mysql_num_rows($validate) == 1)
    {
    while($row = mysql_fetch_assoc($validate))
    {
    $_SESSION["status"] = "Logged";
    $_SESSION['memberid'] = $row['memberid'];
    $_SESSION['first_name'] = $row['first_name'];
    $_SESSION['last_name'] = $row['last_name'];
    $_SESSION['email'] = $row['email'];
    $_SESSION['phone1'] = $row['phone1'];
    $_SESSION['phone2'] = $row['phone2'];
    $_SESSION['username'] = $row['username'];
    $_SESSION['password'] = $row['password'];
    setcookie('member', 'member', time()+24*3600*60);



    $login_time = mysql_query("UPDATE member SET last_login=now() where memberid='{$row['memberid']}'");

    }
    header("Location: http://www.bridgemilltennis.com/members/secure/member-area-main.php");
    }
    else
    {
    $_SESSION["status"] = "Not logged";
    $_SESSION['username'] = Guest;
    header("Location: http://www.bridgemilltennis.com/members/secure/login_form.php");
    exit;
    }
    break;
    }
    ?>

Thread Information

Users Browsing this Thread

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

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