473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

re-setting session variables in PHP

I'm using the following code for a login page in PHP. Everything
works OK until someone else logs in from the same browser. As best I
can tell $mail, $password, and $user_id are not getting updated in the
session.

I tried doing

session_start();
session_destroy();

$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;

which seems to prevent email, password, and user_id from being set.

I'm using 4.1.2, no changes to php.ini (register_globals = On)

Any suggestions, help, or comments greatly appriciated.

Thanks!

Thomas
================================================== ========

<?php

$email = addslashes($_POST['f-email']);
$password = addslashes($_POST['f-password']);

// connect to database

# query the database here - if $password and $mail match,
# return $user_id

if (!$user_id) {

// login failure

header('Location: login_error.php');

} else {

// login is good. start a session for this user

session_start();

$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;

// and send them on their way

header('Location: home.php');

}

?>

Jul 17 '05 #1
2 1837
su*********@hotmail.com wrote:
I'm using the following code for a login page in PHP. Everything
works OK until someone else logs in from the same browser. As best I
can tell $mail, $password, and $user_id are not getting updated in the
session.

I tried doing

session_start();
session_destroy();

$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;

which seems to prevent email, password, and user_id from being set.

I'm using 4.1.2, no changes to php.ini (register_globals = On)

Any suggestions, help, or comments greatly appriciated.

Thanks!

Thomas
================================================== ========

<?php

$email = addslashes($_POST['f-email']);
$password = addslashes($_POST['f-password']);

// connect to database

# query the database here - if $password and $mail match,
# return $user_id

if (!$user_id) {

// login failure

header('Location: login_error.php');

} else {

// login is good. start a session for this user

session_start();

$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;

// and send them on their way

header('Location: home.php');

}

?>


Thomas,

It seems to me like you are hitting the same bug I encountered a while
back on PHP 4.1.2. This is a documented bug and I would advise you to
upgrade your PHP4 version to the latest one. Here is a link to the bug
report:

http://bugs.php.net/bug.php?id=16102

Amir.

--
Rules are written for those who lack the ability to truly reason, But for
those who can, the rules become nothing more than guidelines, And live
their lives governed not by rules but by reason.
- James McGuigan
Jul 17 '05 #2

<su*********@hotmail.com> escreveu na mensagem
news:40**************@news.sonic.net...
I'm using the following code for a login page in PHP. Everything
works OK until someone else logs in from the same browser. As best I
can tell $mail, $password, and $user_id are not getting updated in the
session.

I tried doing

session_start();
session_destroy();
But you didnt do the two of them together right? You should *only* do the
"session_destroy();" when you want the user to log out and not before trying
to change "$_SESSION" fields.

$_SESSION['email'] = $email;
$_SESSION['password'] = $password;
$_SESSION['user_id'] = $user_id;


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
8
by: Lothar Scholz | last post by:
Because PHP5 does not include the mysql extension any more is there a chance that we will see more Providers offering webspace with Firebird or Postgres Databases ? What is your opinion ? I must...
1
by: joost | last post by:
Hello, I'm kind of new to mySQL but more used to Sybase/PHP What is illegal about this query or can i not use combined query's in mySQL? DELETE FROM manufacturers WHERE manufacturers_id ...
3
by: presspley | last post by:
I have bought the book on advanced dreamweaver and PHP recently. I have installed MySQL and PHP server but am getting an error on the $GET statement show below. It says there is a problem with...
2
by: sky2070 | last post by:
i have two file with jobapp.html calling jobapp_action.php <HTML> <!-- jobapp.html --> <BODY> <H1>Phop's Bicycles Job Application</H1> <P>Are you looking for an exciting career in the world of...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.