Jump to content

sessions with cookies


makka

Recommended Posts

hay i need to make a page that i can included that will to check if there is a session set but how can i do it what about setting a cookie with the session id to resume the session but if the ip is different it will fail the cookie will expire after 12 hours also i would like it hashed or some sort of string encryption that i can just undo to read i got up to here then didn't know were witch path to take from here :S

 

function checkcookies() {

    include('config.php');

    if (isset($_COOKIE["game"])) {

}
}

 

also i would like to know how to make a email verification system so when you make a new account you will need to have a working email and then you would click on the link and the account would become useable

 

also is this a way of checking if the email is actual a email

 

if (! is_email($email1)) { $errors++; $errorlist .= "Email isn't valid.<br />"; }

 

 

Link to comment
https://forums.phpfreaks.com/topic/50542-sessions-with-cookies/
Share on other sites

Sessions are set as cookies by default.

 

You can store the sessionid in a cookie to restore it later if you choose. As for the IP check something like this might work

 

<?php
session_start();
function checkCookies() {
     if (isset($_COOKIE["game"])) {
          session_id($_COOKIE["game"]);
          if ($_SESSION['IP'] != $_SERVER['REMOTE_ADDR']) 
               session_destroy();

          // start a new session here.
     }
}

 

as for the is_email check, as long as is_email is a defined function there is no problems there.

Link to comment
https://forums.phpfreaks.com/topic/50542-sessions-with-cookies/#findComment-248347
Share on other sites

cool there is only a few things i wish to ask now apart from my other question

[code=php:0]
<?php
session_start();
function checkCookies() {
     if (isset($_COOKIE["game"])) {
          session_id($_COOKIE["game"]);
          if ($_SESSION['IP'] != $_SERVER['REMOTE_ADDR']) 
               session_destroy();

          // start a new session here.
     }
}

[/code]

1 is how can i get it to set the session cookie to that name i mean it ain't that by default and what would i do for the sesion ip to set it in the first place?

Link to comment
https://forums.phpfreaks.com/topic/50542-sessions-with-cookies/#findComment-248355
Share on other sites

<?php
session_start();
function checkCookies() {
     if (isset($_COOKIE["game"])) {
          session_id($_COOKIE["game"]);
          if ($_SESSION['IP'] != $_SERVER['REMOTE_ADDR']) 
               session_destroy();
               // not sure if a new session_start() is needed here probably review www.php.net/session_destroy
               $_SESSION['IP']  = $_SERVER['REMOTE_ADDR'];
               setcookie('game', session_id(), time()+3600); 
          }
}

Link to comment
https://forums.phpfreaks.com/topic/50542-sessions-with-cookies/#findComment-248362
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.