Helping ordinary people create extraordinary websites!
$1 CPM Advertising For A Limited Time Only
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Using Sessions to Make a PHP Login Script

By Darren W. Hedlund
2005-06-20


Using Sessions to Make a Login Script

To begin this tutorial in PHP sessions, you must first make sure that your web server (ie. apache) has the options to allow session with the configuration.  Note: people using apache and php under a win32 enviorment must manually configure this option.

To start, this tutorial, you should have some basic knowledge of php coding.  Refer to Hotscripts for some basic and more advanced php coding tricks.

To begin, create a test folder called session.  With that you will created the two files below in that folder.

With that in mind let us begin.  First, create a text file called config.php and add in the following code into that textpage.

config.php

<?
# Admin Panel User Name
$uname = "admin";
# Admin Panel Password
$pword = "test";
?>


Save that file as config.php Next, create another test file as index.php and copy the following text into that file.

index.php

<?
require ("config.php");
session_start();
if ((!$username) || (!$password)) {
echo '<form name=login method=post action="">
user:<input type=text name=username><br>
pass:<input type=text name=password><br>
<input type=submit value=go>
</form>';
}
else {
if ($username=="$uname")  {
session_register("username");
session_register("password");
echo "user is $uname, and password is $pword
<br> <a href=\"?m=1\" >unreg</a>";
}
else echo "nope";
}
if ($m==1) {
session_unregister("username");
session_unregister("password");
}
?>

Now open that session folder and you should see the code in action!!



Tutorial Pages:
» Using Sessions to Make a Login Script


 | Bookmark
Related Tutorials:
» Zend Framework Tutorial
» Port Scanning and Service Status Checking in PHP
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1

Ask A Question
characters left.