ok so this is what i have, i have a login script that checks an imap server for a user, if the user has an account then he gets access to the private pages, here is the first part;

this is the script that gets hit by the login form;

Code:

<?php
// setup the connection here

$server = "your ip"; // your IMAP ip address

$user = $_POST['user']; // this will get the name field of your form in this case "user"

$password = $_POST['pass']; // this will get the name field of your form in this case "pass"

$conn = @imap_open("\{$server/imap}INBOX", $user, $pass) // here we go amigo, create the imap connection

or die("<img src=\"images/stop_24.gif\"> no account found with that information <a href=\"login.php\">click here to try again</a>"); // if the account was not found-error message

// if the passwod match the password on the imap server validate and login
if ($pass == $pass) {
       session_register("user");
        header("Location: index.php");

}
?>

and this is the index.php file (the file that the user logged in to)

Code:

<?php
    if (!$PHPSESSID) {
        header("Location: login.php");
        exit(0);
    } else {
        session_start();
        session_register("user");
    }

html goes below
?>

so this is were i need to set a cookie so they don't have to login every time they return to the index.php page, how would i do that, i tried

setcookie("PHPSESSID",$_COOKIE['PHPSESSID'],time()+999999999);

but that didn't work

if im doing something wrong please let me know, im a newbie working hard to learn 🙂

    Have a look at the session_set_cookie_params() function...

    By the way, using session_register() is deprecated... you should use the $_SESSION array instead... have a look at sessions in PHP.net documentation...

      suntra wrote:

      Have a look at the session_set_cookie_params() function...

      By the way, using session_register() is deprecated... you should use the $_SESSION array instead... have a look at sessions in PHP.net documentation...

      ok, just in case anybody else has the same issue sometime, i fix the issue by calling the Session_set_cookie_params () function before the session start() like below;

      //sets cookie to 1200 seconds or 20 mins
      session_set_cookie_params(1200);
              session_start();
      

      thanks for the help suntra 🙂

        That will keep the session cookie alive, but not necessarily the session data. Check to see what the value of session.gc_maxlifetime is (the default is 1400 seconds). If it's shorter than the max time you want to keep your sessions alive, then you need to set it to that longer time. Also, if you are on a shared server or if there's any possibility any other PHP scripts will be running with a different session.gc_maxlifetime value, then you need to use session_save_path() before you session_start(), too, so that your session data is stored in a separate directory that won't be touched by the "garbage collector" when those other scripts do a session_start().

          Thanks for the info NogDog, im going to check on that and try it, thanks for the help 🙂

            Write a Reply...