Hi,
A little tutorial example perhaps?
<?php
// home.php
session_start();
$user='Guest';
if(isset($_SESSION['name']) && !empty($_SESSION['name'])){
$user=$_SESSION['name'];
echo "Welcome home <b>$user</b>";
}
else
echo "Welcome <b>$user</b>";
if($user=='Guest')
echo "<br><br><a href='page1.php'>Join this website</a>";
else
echo "<br><br><a href='page1.php'>Change my profile</a>";
?>
<!-- //////////////////////////////-->
<?php
// page1.php
// session hasto be started when store or read
session_start();
if ( !isset($_SESSION['name']) || $_POST['reset'] ) $_SESSION['name'] = '';
if ( !isset($_SESSION['pass']) || $_POST['reset'] ) $_SESSION['pass'] = '';
if ($_POST['submit']) {
$usern = trim($_POST['username']);
$passw = trim($_POST['password']);
if ($usern=='?') $usern='';
if ($passw=='?') $passw='';
if(!empty($usern)) $_SESSION['name'] = $usern;
if(!empty($passw)) $_SESSION['pass'] = $passw;
}
$usern = '?';
$passw = '?';
if(!empty($_SESSION['name'])) $usern = $_SESSION['name'];
if(!empty($_SESSION['pass'])) $passw = $_SESSION['pass'];
?>
<!-- when action empty, goes back this page again -->
<form action='' method='post'>
<input type='text' name='username' value='<?php echo $usern ?>'> Username
<br>
<input type='text' name='password' value='<?php echo $passw ?>'> Password
<br>
<input type='submit' name='submit' value='SUBMIT'>
<input type='submit' name='reset' value='RESET'>
<br><br>
<a href='home.php'>Cancel</a>
<br>
<a href='page2.php'>Continue</a>
<!-- //////////////////////////////-->
<?php
// page2.php
// hasto start SESSION
session_start();
$uname = $_SESSION['name'];
$upass = $_SESSION['pass'];
echo "User Name: $uname";
echo '<br>';
echo "Pass Word: $upass";
?>
<br><br>
<a href='page1.php'>Back</a>
<br>
<a href='home.php'>Cancel</a>
<br>
<a href='page3.php'>Continue</a>
<!-- //////////////////////////////-->
<?php
// page3.php
echo "This is";
echo '<br>';
echo "The End";
?>
<br><br>
<a href='home.php'>Home</a>
Instuction:
The above PHP Script by me, halojoy, is a set of 4 php pages.
You can see I have put in the name of each page:
- home.php (startpage)
- page1.php ( the STEP 1, form input page )
- page2.php ( can be made into STEP 2, form page )
- page3.php ( the end page - like in a good movie! )
What seems like a very simple set of 4 small pages,
is really a sophisticated little piece of php code.
These 4 pages can easily be modified into
a nice looking and good working SESSION handling application.
And I do not lie to you ........ this time 😃
/halojoy
🙂