Jump to content

Archived

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

brown2005

using php sessions and cookies.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[code]<?php
session_start();

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

?>[/code]

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.

Share this post


Link to post
Share on other sites
sorry i mean, how can i set the cookie if a check box is ticked..... that can be used with php sessions

Share this post


Link to post
Share on other sites
[code]
<lable><input type='checkbox' name='rem_me' value='on' />Remember Me</label>
<?php
//then in your code

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

[/code]

Share this post


Link to post
Share on other sites

×

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.