i have a login page which checks the user login...this works by fetching the data from the database and it is working....
but when i type the url of the second page it is getting displayed....i want all the user to enter through the first page...please tell me how to achieve tat

when the user logs in, put his username to the session. Eg.
//After logging in, add his name to the session. $_SESSION['user']=$username; Then in each page, check if $_SESSION is not null. If its null, then use header function to redirect the user back to the first page. If its not null, then continue with normal operations.

hi
i tried someething like this but it is not working is my code in the third is correct...
error:login is not working in this case....
1st page

<body>
<form method="post" action="start1.php">
Username<input name="myusername" type="text" id="myusername">
Password<input name="mypassword" type="password" id="mypassword">
<input type="submit" name="Submit" value="Login">
</form>

2nd page

<?php
session_start();
?>
<?php

$myusername=$_POST['myusername'];
$_session['name']=$myusername;
$mypassword=$_POST['mypassword'];

if ($myusername=="hi" && $mypassword=="xxxx")
{
print "<script language=\"JavaScript\">";
print "window.location = 'http://www.careerglitters.com/aletheia/viewuser.php'";
print "</script>";
}
else
{
print "<script language=\"JavaScript\">";
print "window.location = 'http://www.careerglitters.com/aletheia/start.php'";
print "</script>";
}
?>

3rd page

<?php
   session_start();
  ?>

<?php
$_session['name']=$myusername;
if($_session['name']==0)
{
print "<script language=\"JavaScript\">";
print "window.location = 'http://www.careerglitters.com/aletheia/start.php'";
print "</script>";
  }
else
{
$result=mysql_query("SELECT id,name,email FROM member");
......
for ($i = 0; $i < mysql_num_rows($result); ++$i)
{

$line = mysql_fetch_row($result);
print "<tr><td><a href='welcome.php?id=".$line[0]."'>".$line[1]."</td><td>".$line[2]."</td></tr>";
print "<tr><td bgcolor='#008080'></td><td bgcolor='#008080'></td></tr>";
}
}
mysql_close($link);
?>

This wouldn't work since you are adding $_SESSION=$myusername; even without checking if hes a valid user. Secondly, $_SESSION will be null and not 0.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.