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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.