my session starts is not working.

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 1859 Views - Last Post: 04 June 2009 - 12:57 AM Rate Topic: -----

#16 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: my session starts is not working.

Posted 03 June 2009 - 11:58 PM

check your database table fields.
Was This Post Helpful? 0
  • +
  • -

#17 kunkka  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 15-May 09

Re: my session starts is not working.

Posted 04 June 2009 - 12:00 AM

page will go to home page even without the username check

i have Login table

which has Username and Password

it has

test as the username and Password 123
Was This Post Helpful? 0
  • +
  • -

#18 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: my session starts is not working.

Posted 04 June 2009 - 12:22 AM

ok here is a sample code
pages
index.php
home.php

here is the table to create
CREATE TABLE `login`.`users` (
`ID` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`Username` VARCHAR( 50 ) NOT NULL ,
`Password` VARCHAR( 50 ) NOT NULL
) ENGINE = MYISAM ;

index.php
<?php
if(!isset($_SESSION))
{
session_start();
}
$con =  mysql_connect('localhost','root','');
$db = mysql_select_db('login',$con);
if(isset($_POST['Username']) && isset($_POST['Password']))
{
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$strQuery = mysql_query("SELECT * FROM users WHERE Username='$Username' AND Password='$Password'") or die(mysql_error());
if(mysql_num_rows($strQuery)>0)
{
$_SESSION['Username']=$Username;
header("Location: home.php");
}
else
{
echo "Invalid Username or Password";
}
}
?>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
	<tr>
	  <td width="140"> </td>
	  <td width="360"> </td>
	</tr>
	<tr>
	  <td>Username</td>
	  <td><label>
		<input type="text" name="Username" id="Username">
	  </label></td>
	</tr>
	<tr>
	  <td>Password</td>
	  <td><label>
		<input type="text" name="Password" id="Password">
	  </label></td>
	</tr>
	<tr>
	  <td> </td>
	  <td><label>
		<input type="submit" name="button" id="button" value="Login">
	  </label></td>
	</tr>
  </table>
</form>



home.php
<?php
if(!isset($_SESSION))
{
session_start();
}
if(!isset($_SESSION['Username']) || isset($_SESSION['Username'])==NULL)
{
header("Location: index.php");
die();
}
?>
<h1>Welcome To My Site <?php echo $_SESSION['Username']?></h1>


This post has been edited by noorahmad: 04 June 2009 - 12:24 AM

Was This Post Helpful? 1

#19 kunkka  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 15-May 09

Re: my session starts is not working.

Posted 04 June 2009 - 12:42 AM

thanks a lot. ... appreciate it a lot..

i did it finally .. thanks for the amazing support guys.. now i can proceed to the next page :D
Was This Post Helpful? 0
  • +
  • -

#20 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: my session starts is not working.

Posted 04 June 2009 - 12:57 AM

you welcome?
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2