Hi,
I am trying to creat a very simple session between 3 php pages as:index.php ,validate.php and target.php
index.php
<?php
session_start();
$_SESSION['uid'] = 'test';
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Start A Session</title>
</head>
<body>
<h1>Welcome to Heaven</h1>
<form method="POST" action="validate.php">
Your Name: <input type="text" name="name" value="" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
and validate.php as:
<?php
session_start();
$err="Not Allowed";
if(($_POST['name']) == $_SESSION['uid']){
header ("Location: heaven.php");}
else
{echo $err; }
?>
and finally target.php as
<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Start Email with PHP</title>
</head>
<body>
<h1>Welcome to Targer <?php echo $_SESSION['uid'] ?></h1>
<img src="session.jpg">
</body>
</html>
Now my questions are:
1- How come user still can get access to target page while I have already set a seetion between pages(according to my understanding of sessions the target page must NOT be accessible unless the correct seesion value has beeb submitted)
2- I tried to validate the $_SESSSION value by using the isset() but it did'nt go through! can you please let me know how I can modify the validate.php using the isset() instead of if(($_POST['name']) == $_SESSION['uid']) comarison?
3- Can you please let me know how I can merge two (idex.php and validate.php) in one page? I mean how I can validate the session inside the index.php and reduce the files two index and target? In this case I need to handle the wronge logins inside the index page.
and finally,can you please let me know how I can assign the value to $_SESSION from user input? I mean instesd of having a hard coded part like $_SESSION['uid'] = 'test'; let the session value start with user input!.I know this looks meaningless here but I would like to get idae on creating captcha in same index page
Thanks for your time in advance