| | |
Help login issue
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hi php gurus. newbie here needs help.
I m having a problem with my login script. Basically it works 95% of the time, but once and a while it doesn't. The session variable doesn't get set, or remembered, and the next referred page fails on the isset check. I tried a number of things, Please any suggestions would be great. My code is pretty messy...at the moment... but I've been going nuts with this. I recently added the session_regenerate_id and the session_write function to no avail.
snipplet from login.php.
Next Page. Client.php
I use this check to confirm the session is there.
I m having a problem with my login script. Basically it works 95% of the time, but once and a while it doesn't. The session variable doesn't get set, or remembered, and the next referred page fails on the isset check. I tried a number of things, Please any suggestions would be great. My code is pretty messy...at the moment... but I've been going nuts with this. I recently added the session_regenerate_id and the session_write function to no avail.
snipplet from login.php.
PHP Syntax (Toggle Plain Text)
//Start session session_start(); sql="SELECT login,id FROM tblDealer WHERE login='".$email."' and password='".$password."'"; $r = mysql_query($sql); $row=mysql_fetch_array($r); if($r) { if(mysql_num_rows($r)>0) { //Login Successful session_regenerate_id(); //$member=mysql_fetch_assoc($r); //$_SESSION['dealer_id']=$member['id']; $_SESSION['dealer_id']=$row["id"]; session_write_close(); //header("location: client.php"); $dealer_id = $row["id"]; print 'success,client.php,dealer='.$dealer_id; // maybe add it to the url ? just for now. exit(); }else { //Login failed //header("location: login-failed.php"); print "no such login in the system. please try again."; exit(); } }else { die("Query failed"); }
I use this check to confirm the session is there.
PHP Syntax (Toggle Plain Text)
session_start(); if(!isset($_SESSION['dealer_id'])) { echo '<p>Security Violation '; exit(); }
Last edited by Tekmaven; Jul 19th, 2008 at 2:36 pm. Reason: Code tags
•
•
Join Date: Jul 2008
Posts: 89
Reputation:
Solved Threads: 10
Hi,
I am as newbie to PHP as you but in this line you missed teh '$' symbol.
in front of the sql variable
$sql
Although you can go to this link
http://us2.php.net/manual/en/function.mysql-query.php
Hope this help,
Camilo
I am as newbie to PHP as you but in this line you missed teh '$' symbol.
PHP Syntax (Toggle Plain Text)
sql="SELECT login,id FROM tblDealer WHERE login='".$email."' and password='".$password."'";
in front of the sql variable
$sql
Although you can go to this link
http://us2.php.net/manual/en/function.mysql-query.php
Hope this help,
Camilo
Last edited by camilojvarona; Jul 19th, 2008 at 12:58 pm.
Try eliminating one problem at a time. create a page with just this code in it and refresh it several times, if it resets to zero then you have a problem, if not, I'm pretty sure that it is not a problem with the session.
php Syntax (Toggle Plain Text)
<? session_start(); if(!isset($_SESSION['sesstest']) || !is_numeric($_SESSION['sesstest'])) { $_SESSION['sesstest'] = 0; } else { $_SESSION['sesstest']++; } echo $_SESSION['sesstest']; ?>
Last edited by R0bb0b; Jul 20th, 2008 at 3:30 am.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Jul 2008
Posts: 2
Reputation:
Solved Threads: 0
PHP Syntax (Toggle Plain Text)
//Start session session_start(); $sql="SELECT login,id FROM tblDealer WHERE login='".$email."' and password='".$password."'"; if($result = mysql_query($sql)) { if(mysql_num_rows($result)>0) { list($login,$id) = mysql_fetch_array($result); $_SESSION['dealer_id']= $id; print 'success,client.php,dealer='.$id; // maybe add it to the url ? just for now. exit(); }else { print "no such login in the system. please try again."; exit(); }//else } else{ die("Query failed"); }
actually, I really don't see much difference, but it looks much cleaner.
Last edited by R0bb0b; Jul 20th, 2008 at 5:25 am.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
![]() |
Similar Threads
- Login-Logoff Loop (Windows NT / 2000 / XP)
- network login problem (Windows NT / 2000 / XP)
- Network Login Issue (Please Help!) (Windows NT / 2000 / XP)
- PHPbb - Login Issue (PHP)
- Strange blank WinXP Login error message ... (Windows NT / 2000 / XP)
- Windows Wont Load Past Login (Windows NT / 2000 / XP)
- login screen config (Window and Desktop Managers)
- redhat 8.0 firewall issue (*nix Software)
Other Threads in the PHP Forum
- Previous Thread: help with Checkbox value in mysql
- Next Thread: Help Anybody?
| Thread Tools | Search this Thread |
apache api array basic beginner binary body broken cache cakephp class cms code computing confirm cron curl customizableitems database date date/time delete display dynamic email error file filter folder form forms forum function functions gc_maxlifetime google header headmethod howtowriteathesis href htaccess html iframe image include ip javascript joomla limit link list login malfunction memmory memory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation neutrality oop parameter parsing paypal pdf php phpmysql query question random recourse regex script search select seo server sessions snippet source space sql static system table thesishelp trouble tutorial update upload url variable video web webdesign xml youtube





