Jump to content

using php sessions and cookies.


brown2005

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
Link to comment
https://forums.phpfreaks.com/topic/19170-using-php-sessions-and-cookies/
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.

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.