Jump to content


Photo

using php sessions and cookies.


  • Please log in to reply
5 replies to this topic

#1 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 30 August 2006 - 03:49 PM

Hi, Can I use both together....

i mean i have now

login_process.php

i have lines like

$_SESSION['MemberID'] = $login_array['members_id'];

session_register('MemberID');

and in session.php which calls all the information i have

$session_sql = "SELECT * FROM members WHERE members_id = '$_SESSION[MemberID]'";
$session_result = mysql_query($session_sql) or die(mysql_error());
$session_array = mysql_fetch_array($session_result);

$session_id = $session_array['members_id'];
$session_member = $session_array['members_username'];

now obviously when u close ur browser it deletes the session... but i want to know if i can have say a tick box on the login form which people can tick to stay logged in and set a cookie to be used with the above, or any better ideas...

thanks

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 30 August 2006 - 05:00 PM

yes

I do the same
Most sites, with remember me does

On mine, if they log in (checked and details ok) then session is created
if the have ticked the remember me box then a cookie is placed for 10 days
Tell me the problem, I will try tell you the solution

#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 31 August 2006 - 11:14 AM

can u show me how to do it then please?

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 31 August 2006 - 11:51 AM

<?php
session_start();

$_SESSION['variable'] = 'foobar';

?>

That's all you need to start a session and to assign a session variable, php does the rest for you.

Just remember to have session_start(); at the top of every page before _any_ output is produced, and the session data, if still valid, will be accessible via $_SESSION superglobal.

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 31 August 2006 - 12:47 PM

sorry i mean, how can i set the cookie if a check box is ticked..... that can be used with php sessions

#6 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 31 August 2006 - 12:52 PM

<lable><input type='checkbox' name='rem_me' value='on' />Remember Me</label>
<?php
//then in your code

if($_POST["rem_me"]){
set_cookie(.....
}


Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users