Jul 24, 2008

Php Sessions - Multiple users using the same login

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Php Sessions - Multiple users using the same login

fsoftball
Hi,

I'm realtively new to PHP and I'm considering creating some login functionality. However I want a group of users to use the same loginname and password. They will be loggin infrom different machines. The users will know they are sharing the account.

Can anyone give me an idea of what kind of effect this might have on my sessions? Will it create any odd hiccups or other strange things?

Reply

nipun
Session allows you to preserve data across page requests (going from one page to another on a website) by saving the data to variables that you register as being part of a session. Sessions are tracked through
cookies or through the URL. I prefer to track sessions through the URL because cookies may not be enabled on the client computer.

If PHP is compiled with --enable-trans-sid then URLs will contain the session id automatically via the constant PHPSESSID.

Function session_start(void):
Looks for an existing session and if one does not exist, it creates a session. If a session already exists it resumes the current one [sets the session variables for the page] based on the session id being passed via a GET variable [the URL] or a cookie). This function always returns TRUE.

Function session_id([string id]):
Get and and returns the session id for the current session. If a session id is specified, it will replace the current session id with the specified id. If you assign a session id on your own you should call the session_id() function before starting a session. Your custom session id cannot have whitespaces, underscores(_) or periods (.).

PHP Code
$id = 445785931;
session_id($id);
session_start();

Function session_register(mixed name [, mixed ...]):
Registers one or more variables with the current session, either a string holding the name of a variable or an array consisting of variable names or other arrays. For each name, session_register() registers a global variable with that name in the current session. This function returns TRUE when all of the variables are successfully registered with the session.

Function session_is_registered(string name):
Determines if a variable is registered in a session. This function returns TRUE if there is a variable with the name registered in the current session.

Function session_unregister(string name):
Unregisters a specific variable from the current session. The variable will no longer be saved as part of the session. This function returns TRUE when the variable is successfully unregistered from the session.

Function session_unset(void):
Free all session variables that are registered for the current session. The variables can be re-registered by calling session_register().

Function session_destroy(void):
Destroys all data registered to a session. This function returns TRUE on success and FALSE on failure to destroy the session data.

Further reading PHP: Manual: Session handling functions

The following example demonstrates how to create a session variable on one page, then redirect the user to another page and passing the session id variable thru a querystring to the next page. Then the next
page will do a detection to see if the value of the SessionID Querystring is the same as the actual session_id().

PHP Code
<?
// start session
session_start();

if(!session_is_registered("favcolour")) {

// assign a value to the favorite colour variable
$favcolour = "purple";

// register the favorite colour variable as a session variable
session_register('favcolour');

// assign the sessionID to a variable
//$seshID = session_id();
?>
<A HREF="<? echo "$PHP_SELF?=SID"; ?>">click here</A>
<?
} else {
// print the value of the favorite colour session variable
print "<p>Session Variable (favcolour) was successfully registered: ". $HTTP_SESSION_VARS['favcolour'];

// print the value of the SessionID Querystring Variable (represents the sessionID
print "<p>Session ID (session_ID()): ". session_id();
print "<p>Session ID (SID): ". $SID;


if ($SID != session_id()) {
print "<p>SID is NOT equal to session_id()";
} else {
print "<p>SID is equal to session_id()";
}

session_unregister('favcolour');
if(!session_is_registered("favcolour")) {
print "<p>Session Variable (favcolour) was successfully unregistered!</p>";
} else {
print "<p>Session Variable (favcolour) was NOT successfully unregistered!</p>";
}

//unset all session variables
session_unset();

//destroy session
session_destroy();
}
?>



The output results should look something like so:

Session Variable (favcolour) was successfully registered: purple

SID (session_ID()): c95a9b59ad06409627bbfd92aea7aa92

SID ($SessionID): c95a9b59ad06409627bbfd92aea7aa92

SID is equal to session_id()

Session Variable (favcolour) was successfully unregistered!

 

 

 


Reply

mobious
it's really not a problem if you are not going to keep track of their ip adresses.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. php session files are read to find out which other users are online/offline - 1.86 hr back. (1)
  2. multiple php sessions - 2.49 hr back. (1)
  3. php login script no multiple logins - 3.63 hr back. (1)
  4. easyphp session_id(); not found - 4.47 hr back. (1)
  5. using session with multiple users and web pages with php - 5.05 hr back. (1)
  6. php code with sessions for login system - 10.42 hr back. (2)
  7. session multiples en php - 15.65 hr back. (1)
  8. creating logins using sessions in php - 15.78 hr back. (1)
  9. "php form""login""sessions" - 30.71 hr back. (1)
  10. php multiple session login check - 41.55 hr back. (1)
  11. php login multiple users - 43.16 hr back. (1)
  12. php multiple users - 43.22 hr back. (1)
  13. php cookie for multiple user in same machine - 55.25 hr back. (1)
  14. creating multiple sessions php - 66.23 hr back. (1)
Similar Topics

Keywords : php, sessions, multiple, users, login

  1. How To Print In Php
    How to print to the users printer using PHP (9)
  2. One Login Account At One Time
    (3)
    When we login, we got a session. But at the same time when we still login, another one could login
    at our account. So, can we restrict only one user could login at one account? So if another wants
    to log into the same account, he must wait until the one logs out. Thanks in advance.....
  3. Something I Discovered With Sessions [php]
    (4)
    Hello All, I've been doing a lot of PHP programming since I last posted here. I've run
    across two security related things with sessions that you may or may not know about. The first one
    pertains to the session id, or the id that PHP assigns each computer when a session is created.
    This id is either stored in a cookie (search for PHPSESSID) or through the URL as GET data.
    Remember that all session data is stored server side; this ID is the only thing that PHP will use to
    differentiate your computer from someone else's. While I was programming for Plug ....
  4. Php Sessions And Post Variables Issues
    My script dosent seem to work as intended (1)
    You can test it out for yourself at http://sonesay.trap17.com/application.php I've been
    working on this page locally and it seems to be working fine but when I upload it to my trap17
    account the post variables dont get saved properly. Fill in some fields and submit it, the form
    will come up as a empty field yet when you resubmit it without any modifications and the data you
    entered in orginally will now magically appear, resubmit it again and it will be gone. This is
    really annoying as I have no clue why it would be doing this when it seems to work fine locally.....
  5. Html Site With Login
    Is it possible? (2)
    Hello. I´m building my own site and I need some help... Is it possible to use a login sistem in php
    and mysql database in a html site? ....
  6. Login System
    (6)
    i am designing a site for my alliance for the game Dark Throne. and i want some content to be
    availabe to members of the alliance only, and other content to be available to people with a certain
    rank within the alliance. i know this should be somewhat simple, but i am not that sure how to do
    it. my idea for the website is just have basic info about the alliance available to everyone, then
    news about the alliance and member lists and other things like that available to every alliance
    member, then things such as the strike team, diplomat team, and special areas like that,....
  7. Php Login Script
    (1)
    I'm looking for a good php login script. I would like one where it pops up. like http-auth. but
    with out the data base. I would also like for it to have a log out fuction.....
  8. Creating A Login Box That Links To My Phpbb Forum
    Have my phpBB Forum Intergrated with my Website (4)
    Can someone please give me a code that I can use to put a login box on my website, that will login a
    user into my phpBB Forum? Sort of like Having my phpBB Forum Intergrated with my Website? Thank you
    so much if you can! /angel.gif" style="vertical-align:middle" emoid=":angel:" border="0"
    alt="angel.gif" /> Ex. ....
  9. Multiple Drop Down Lists ?
    Multiple drop down lists to take user to new page (4)
    Hi everyone I was wondering if anyone could help. I want to create a page with multiple drop down
    lists and depending what the user selects decides the page they will be taken to. Sorry i havent
    explained this too well. Here is an example of what i want (link below) the user is also emailed a
    copy http://www.dermalogica.com/SpeedMappingOnl...US®ion=B I have searched the web and come
    close but nothing does it right I would be extremely greatful if anyone could help! Thanks ....
  10. Windows Login Credentials
    (0)
    On an intranet I'm running php. apache and mysql. We use Windows logins. I have a form that
    users can submit. This will require a login. I would prefer to use the windows login and passwords.
    can I link to the windows authentication? The issue I see is when a user changes the password. My
    link would need to update the password....
  11. Using Multiple Selection Array In Table To Order Data
    Using multiple selection array in table to order data (1)
    have a form that has a multiple select choice, like this: CODE <form method="post"
    action="display.php" <select multiple name="selectsort[]">
    <option value="code">Code</option> <option
    value="amount">Amount</option> <option value="dateammended">Date
    Ammended</option> <option value="expreviewdate">Expiration/Review
    Date</option> <option value="effectivedate">Effective Date</option>
    <option value="e....
  12. Is This A Good Script?
    A login script (9)
    Okay, I am trying to password one page of my website. I need confirmation if this is a safe code or
    not. The whole code is on the page I'm protecting. CODE <?php
    include('header.php') ?> <?php // Define your username and password
    $username = "THE_USERNAME"; $password = "THE_PASSWORD"; if
    ($_POST['txtUsername'] != $username ||
    $_POST['txtPassword'] != $password) { ?>
    <h1>Login</h1> <form name="form" method=&....
  13. <?php ?> Unique Visitors Script
    Flat file unique visitors script (no sessions) (2)
    This is really simple script. Well at least this part is, but it could be extendable. Only problem
    is that it's not really for massive websites with hundread of visitors a day, but rather for
    small ones. But it is a good script to figure out how to make a visitor counter script. Anyway
    here's the snippet. CODE <?php function getVisits($variable) {
        $visits = array();     if ($handle =
    opendir('stats/')) {     while (false !== ($file =
    readdir($handle))) {  ....
  14. Phpmyadmin Login Problem!
    (1)
    I have easyphp. But i can not log when i go to phpmyadmin. I directly enter the page. But i think i
    should normally have to log in before enter that page. What should i do to configure the access to
    phpmyadmin? Thank for help....
  15. Login System Help...
    (3)
    I know, nol tried to use this script.. and erm.. i think failed.. but i installed it all good, works
    fine, UNTILL........ i tried to add a new option to the registration. Thhis is the url to the
    site.. where the dl is.. http://evolt.org/PHP-Login-System-with-Adm...nts_per_page=50 I would
    really appreciate it if somebody could add, in all the php files properly a new registration thing,
    called "name" where they write their name in so i know it for future reference. if somebody could
    get that to me i would really appreciate it. ALSO... if you can't do that, or jus....
  16. <?php ?> Sloppy Login Script
    Sloppy login script, couse i used @ on one string (12)
    Here's a sloppy 3 files login script. First file is Login file that looks like this login.php
    CODE <form action="check.php" method="post"> Username: <input
    type="text" name="username1"><br /> Password: <input
    type="password" name="password1"><br /> <input type="submit"
    value="Login"> </form> Basicly that is HTML form that's used for input
    Second part of the script is the check.php that we call from our login.php form QUOTE ....
  17. New Arisen Site Problem
    Nettek Login Trouble (2)
    Okay, so I installed Nettek and got everything set up. But every time I try and login, it says
    it's incorrect. I've gone into the Database and gotten the password and since it was
    simple, put them in and had tried but with no success. I tried changing the password but I still
    couldn't get in. I tried adding another login and it still didn't work. I have no idea
    what's wrong and I need some help.....
  18. What Does This Do?
    $ban = ($data->login) ? $lban : $iban; (4)
    I'm correcting a 'few' php-files for a friend, but I got this line of code: CODE
    $ban = ($data->login) ? $lban : $iban; and I don't know
    what it does xD Could someone please explain me what this line does? Thanks....
  19. Help Improving My Login Script Code
    The code works okay...just not the authorization part (4)
    I have developed a piece of code /smile.gif" style="vertical-align:middle" emoid=":)" border="0"
    alt="smile.gif" /> that is going to work as my login script for my website. I need some help making
    improvements and creating additional features. Here is my code: CODE <?php
    session_start(); $name = $_POST['username']; $password =
    $_POST['password']; $con =
    mysql_connect("localhost","myDbUser","myDbPassword");
        if(!$con)         {         die(&#....
  20. Add Users On Email Program With Php?
    (1)
    First of all Marry Christmas, Well so i am in some kind of a problem, i can't find out how to
    add users to my mail service, i have no idea what SMTP/IMAP program the server runs, neither does
    the system administrator. But it should be kinda the same thing for all of them if i am not wrong,
    Anyways i have full access to server so i can do whatever i want to do, i have SSH access too (Root
    access /rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0"
    alt="rolleyes.gif" /> )....
  21. .htaccess-style Login System And Php
    (13)
    I am trying to make a login system that looks and works like .htaccess using sessions, with a PHP
    script that detects the username used. Let's say I log on with the username "Amezis" and
    correct password. Then I want a PHP (or any other kind of script) to create a cookie or session
    which stores the user name, so it could be possible to store it in a variable as long as the user is
    logged in, and so it can be printed when needed. Basically, this is what I want the script to do:
    CODE /* This file can only be executed after logging in with the htaccess-style login....
  22. Using Sessions Instead Of Cookies, Help Please
    (1)
    This is a simple code to register and login.. this uses cookies.. i want to use sessions instead..
    can someone tell how i can do it ? config.php CODE <?    ob_start(); // allows you
    to use cookies    $conn =
    mysql_connect("localhost","USER","PASSWORD");   
    mysql_select_db(DATEBASE) or die(mysql_error());    //fill in the above
    lines where there are capital letters.    $logged = MYSQL_QUERY("SELECT * from users
    WHERE id='$_COOKIE[id]' AND password = '$....
  23. Login Script
    (11)
    I am using the following code as a login page. I try to start by checking if a session already
    exists so that people don't have to login each time. The problem is that it is just being
    ignored. How do I check if a session is already set? CODE if
    (isset($_SESSION['loginname'])) { print('you were
    already logged in'); } else { if (submit) {
      list($users,$passwords,$accounttypes)=GetCurrentUsers($user,$
    password,$accounttype);   $nologin=1;   for (&....
  24. Evilboard (forum Software) - Multiple Categorys - Don't Work :(
    I am creating a forum and i can't fix more then 1 category. (6)
    I am at the moment trying to program my own forum, but i need more then a single category, here is
    my source: CODE function cat () { include("functions/functions.php");
    echo '<table width="100%"  border="0" cellspacing="0">
    <tr> <td class="eb_top" colspan="3" style="border-bottom-width:
    0; height: 30px; font-size: 12px;"> <b>Forum</b></td>
    </tr>';      global $catid;   $db = new db;   $db->connec....
  25. Sessions And Login
    Without Cookies (5)
    Hi, I have a login script i made using PHP sessions and MySQL. It works fine but there is a
    problem. As you know Sessions are stored in Cookies by PHP. So if someone has switched Cookies off
    then no sessions will work. How to solve this problem ? Please help me. Thanks and have a good
    day. ....
  26. Automatic Login Using Curl
    (1)
    If you'are lazy people like me. This script may help u. This script is to automated our login to
    some site. You must have cURL installed to use this script. CODE <?php // INIT CURL
    $ch = curl_init(); // SET URL FOR THE POST FORM LOGIN curl_setopt($ch,
    CURLOPT_URL, 'http://www.external-site.com/Members/Login.php'); // ENABLE HTTP POST
    curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH
    FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'fieldname1=fieldvalue1&fieldna....
  27. Script That Tracks The User Status
    how can I track on or offline users? (4)
    long explaination: hey, I'm building a user profile site right now. And, I kinda know how to
    make a online/offline detector, but not totally sure. I know I can make a mysql database to track
    them, but how does it entrer the information? I could easily put in a field where when they login it
    sets them to online, but if they don't sign out, and just exit the browser, how can I tell.
    short: I want someone to tell me how to make a online/offline status detector, like they have here
    on trap17. I'd be thrilled if you can post to this, thanks, arcticsnpr....
  28. Session Variables
    Sessions in PHP behaving strangely (4)
    Hi. I am part of a development team working in PHP and MySQL. The site is using SSL, and users
    have to log to use the site. When users log in, their important details are retrieved from the
    database and stored in session variables (functionality in the site is permissions specific).
    Lately, sessions are "disappearing" for no apparent reason. Users will log in, and at some point
    (the length of time will vary unpredicatably) the sessions will lose their value (the variables are
    empty) and this causes the site to evict the user. This is very frustrating for the user b....
  29. Multiple Options?
    (3)
    Okay so what Im trying to figure out is how I would go about giving the people to uh, well for
    examplkes sake it would be like "how many cats do you have" then theyd fill in a number, submit and
    the next page would print out boxes for as many cats they have that will be too fill in a color of
    the cat, so basically something like that, where it will only give them so many fields based on how
    many they said they have, and then their final "reciept" will only print out stuff for as many as
    they filled itn ....
  30. Login / Authetication System Using Database
    adding information (4)
    Is there any way to make such database where I can write like name and passwords.. Then make an
    login box, and when somebody trys to acces the login he needs to write the name and password.. Then
    it is verifyed if is there such name and password and if it is then acces the page.. I think there
    is posible something like that with MySQL (db).. but can anybody say me a script or way to make
    something like that? Alredy thanks......

    1. Looking for php, sessions, multiple, users, login

Searching Video's for php, sessions, multiple, users, login
Similar
How To Print
In Php - How
to print to
the users
printer
using PHP
One Login
Account At
One Time
Something I
Discovered
With
Sessions
[php]
Php Sessions
And Post
Variables
Issues - My
script
dosent seem
to work as
intended
Html Site
With Login -
Is it
possible?
Login System
Php Login
Script
Creating A
Login Box
That Links
To My Phpbb
Forum - Have
my phpBB
Forum
Intergrated
with my
Website
Multiple
Drop Down
Lists ? -
Multiple
drop down
lists to
take user to
new page
Windows
Login
Credentials
Using
Multiple
Selection
Array In
Table To
Order Data -
Using
multiple
selection
array in
table to
order data
Is This A
Good Script?
- A login
script
<?php
?> Unique
Visitors
Script -
Flat file
unique
visitors
script (no
sessions)
Phpmyadmin
Login
Problem!
Login System
Help...
<?php
?> Sloppy
Login Script
- Sloppy
login
script,
couse i used
@ on one
string
New Arisen
Site Problem
- Nettek
Login
Trouble
What Does
This Do? -
$ban =
($data-
>login) ?
$lban :
$iban;
Help
Improving My
Login Script
Code - The
code works
okay...just
not the
authorizatio
n part
Add Users On
Email
Program With
Php?
.htaccess-st
yle Login
System And
Php
Using
Sessions
Instead Of
Cookies,
Help Please
Login Script
Evilboard
(forum
Software) -
Multiple
Categorys -
Don't
Work :( - I
am creating
a forum and
i can't
fix more
then 1
category.
Sessions And
Login -
Without
Cookies
Automatic
Login Using
Curl
Script That
Tracks The
User Status
- how can I
track on or
offline
users?
Session
Variables -
Sessions in
PHP behaving
strangely
Multiple
Options?
Login /
Autheticatio
n System
Using
Database -
adding
information
advertisement



Php Sessions - Multiple users using the same login



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE