Someone test my session page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Someone test my session page?

Post by nigma »

Hey I am having trouble with sessions (as expressed in previous posts) but I thought maybe it would be easier for someone to help me if I showed them what happens.

Anyone willing to help please go here:
http://www.mc0.cjb.net/login.html

I created a test accnt. User: test
Pass: test

Here is code for the validation page that is called when you hit the submit button:

validate.php

Code: Select all

<?php

	session_start();
	$db_user = 'dbuser';
	$db_pass = 'dbpass';
	$user_id = $_POST&#1111;'user_id'];
	$password = $_POST&#1111;'password'];


	$connection = mysql_connect('localhost', $db_user, $db_pass) or die(mysql_error());
	mysql_select_db('mc0', $connection) or die(mysql_error());

	$query = "select * from vUsers
				where user_id='$user_id' AND password='$password'";

	$result = mysql_query($query, $connection) or die('error making query');
	$affected_rows = mysql_num_rows($result);

	if ($affected_rows == 1) &#123;
	 	print '<html><head><meta http-equiv="refresh" content="1;url=test.php"><title>VALIDATED</title></head><body bgcolor="black" text="999999"><center>Succesfully Logged In</center></body></html>';
		session_register('username');
		$_SESSION&#1111;'username'] = $user_id;
	&#125;
	else
	&#123;
		print '<html><head><meta http-equiv="refresh" content="2;url=login.html"><title>NOT VALIDATED</title></head><body bgcolor="black" text="999999"><center>Failed To Log In</center></body></html>';
	&#125;
?>
When you enter it correctly it says you validated yourself?

but the problem I think occurs when you try to go to a page that has code in it that checks to see if you are validated. When you correctly login with the username test, and pass test, you go to test.php where this file is included to check to see if user is validated:
<?php require_once("check_user.php");?>

Code for check_user.php:

Code: Select all

session_start();
	if(empty($_SESSION&#1111;'username']))
	&#123;
		die('<html><body bgcolor="black" text="999999"><div align="center">It appears that
		you have not logged in. Please do so by going to the <a href="login.html">Login Page</a>.<br>
		If you feel that you have recieved this message by error please email me at<br>
		f0cc@charter.net .</div></body></html>');
	&#125;
?>
Any suggestions?
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post by Coco »

taken from the php site:
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister().
here

dont know if thats going to be any help....
Post Reply