Topic: Help with php_sessions login system, please? (Read 572 times)
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« on: Feb 18, 2007, 08:36:24 PM »
Hi guys, I know you guys have been a little bit upset about my questions here before posted, because they may look as rookie questions, but I never said I was a pro and I'm stucked once again. So, if anyone could help I'd be very grateful. My question is kind of simple (probably) for you guys, I'm validating a user through PHP+MySQL, and, if the username and password match, the script is supossed to begin a PHP Session to register the session so the user can go around the php files without having to retype anything. But it's not initializing the session, before it seem to work but I changed the code a bit to try to fix it and now it doesn't even work. Anyway, when it seemed to work whenever I moved on to any other page it stopped validating, the session was not working. Also, the session is not being register because I get this message when I try to login:
« Last Edit: Feb 18, 2007, 09:31:41 PM by eliezer »
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8104
41581 credits Members referred : 3
« Reply #1 on: Feb 18, 2007, 09:49:00 PM »
From a first look it seems that your script is really unsecure. You must addslashes() whatever you put in the queries as the way it is now anyone can login or truncate your database.
Maybe you should use Olaf's access user class for this thing.
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #2 on: Feb 18, 2007, 10:41:32 PM »
Darn. I'll go read some logins tutorials. I mean, Olafs class is great but I'd like to get this done by myself so I can learn some. Thanks for the reply anyway Nikolas. (:
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 8104
41581 credits Members referred : 3
« Reply #3 on: Feb 18, 2007, 10:50:01 PM »
In your script you are not setting $_SESSION['dominio'] and $_SESSION['contrasena']
I guess this is a part of the problem
Also instead of
session_register('misesion');
You can use :
$_SESSION['misesion'] = true;
BTW we always love to help people who want to learn, so don't hesitate to ask whatever you want But do not use this snippet in a production server as it can cause security issues.
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #4 on: Feb 18, 2007, 11:18:03 PM »
Nikolas! Thanks a lot for the advice man. My bad, I posted a (once again) slightly modified code, the SESSION values I had on the query, were $_POST values instead. At least I'm not that slow hehehe.
Anyway sir, I tryied also with...
Code:
session_register($contrasena);
where $contrasena was a $_POST value and it didn't work either. And I tryied to call it later on like this:
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
my day will come..
« Reply #7 on: Feb 19, 2007, 12:36:03 AM »
After googling for WAMP+"PHP SESSIONS" I came up with this post:
Quote
If you use the latest version of WAMP or PHP, you are using PHP 5. This means that register_globals is disabled by default. Therefore you should use the superglobal $_SESSION, instead of session_is_registered and session_register. Quoting the manual-page of session_register at php.net ( http://nl3.php.net/manual/en/functi...on-register.php) "If you want your script to work regardless of register_globals, you need to instead use the $_SESSION array as $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where the PHP directive register_globals is disabled."
So, now it seems I managed to get the sessions working. But I'm not sure yet since I have to fix some stuff into the script. I'll let you know how did this end. (:
OMG!I am geek
Gender:
Posts: 55
366 credits Members referred : 0
if there is a session, session_id() will return the session id, otherwise it will return an empty string.
Hey Nikolas, I finally got it working man. I think it was wrong mostly because the register_globals were Off at PHP.INI. Reason is off it's because it says it is better to do not use register_globals. Anyway, register_globals will do the work. About the stripslashes, I just have to use them like:
PS.. By the way, now I got it all setup but when I click on a button it destroys my session and I don't want it like that. http://189.153.96.165/laguna/index.php?login=si Link here, username: eliezer.com, password: elie1983. The results are displayed in a basic sheet and in the left side you will see a button, this is the code: