Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 22nd, 2011, 05:42 AM
Authorized User
 
Join Date: Jul 2011
Posts: 49
Thanks: 0
Thanked 0 Times in 0 Posts
Default assigning a session to user

hi all,
i have written a code in php that will check whether the session exists
or not and it will generate the session id.
below is the code.....
PHP Code:
<?php 
session_start
();
mysql_connect("localhost","root","") or die("mysql_error()");
mysql_select_db("shopping") or die("mysql_error()");

if(!isset(
$_SESSION['username']))
{
 print 
"Your SessionID: ".time();
}
else
{
 print 
"Session does not exist";
}
?>
now i want that session id to be assigned to each user.
tell me how to do it....
 
Old November 12th, 2011, 02:49 PM
Authorized User
 
Join Date: Feb 2007
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by ravi951 View Post
hi all,
i have written a code in php that will check whether the session exists
or not and it will generate the session id.
below is the code.....
PHP Code:
<?php 
session_start
();
mysql_connect("localhost","root","") or die("mysql_error()");
mysql_select_db("shopping") or die("mysql_error()");

if(!isset(
$_SESSION['username']))
{
 print 
"Your SessionID: ".time();
}
else
{
 print 
"Session does not exist";
}
?>
now i want that session id to be assigned to each user.
tell me how to do it....
can be explain me a bit more.
as far as i can understand, you want a unique id for every user in session whenever he logs in.

if i am right then you can follow these steps:
save the id with the username in it (will help you later) like Session id 100090009-1 where 1 is the user id.

Once the user logs in, the session id will be created and stored in session variable. try to add the variable inside an array something like $_SESSION['user']['id'] (just easy to manage things. If you want the whole user data stored in session you can have print_r $_SESSION['user'] and you will get all the stored data instead of tracking the code).

Let me know if this helped you or you still have doubts.
__________________
Regards
Amitav Roy
Web:
http://www.amitavroy.com/justread
http://www.pixelgroups.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning value to session object from repeater. aloktripathi.13 ASP.NET 2.0 Professional 1 November 16th, 2007 09:23 AM
Assigning Javascript variable to ASP session anaden Classic ASP Basics 2 September 18th, 2004 02:16 AM
Assigning Session Variables morpheus Classic ASP Basics 2 November 21st, 2003 01:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.