::Another Basic Code::
Started by
toyolygbaik
, Mar 30 2005 05:02 AM
9 replies to this topic
#1
Posted 30 March 2005 - 05:02 AM
You can try this code... just copy and save with the nam ehas been given below...
<html>
<head>
<title>Enter Username and Password</title>
</head>
<body>
<form method="get" action="login.php">
Enter your username and password:<br>
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password">
<br>
<input type="submit" name="submit" value="Submit">
</form>
<br>
<a href="registration_form.html">REGISTER</a>
</body>
</html>
home.php
<?PHP
session_start();
if (!(session_is_registered("username")))
{
session_unset();
session_destroy;
$url = "Location: warning.html";
header($url);
}
?>
<html>
<head>
<title>Private Page</title>
</head>
<body>
<h1>Welcome to the private area</h1>
<?
echo "<h2>Hi $username</h2>";
echo "<h2>This is page 1</h2>";
echo "<a href=\"home2.php\">Page 2</a> || ";
echo "<a href=\"update.php\">Update Profile</a> || ";
echo "<a href=\"logout.php\">Logout</a>";
?>
</body>
</html>
home1.php
<?PHP
session_start();
if (!(session_is_registered("username")))
{
session_unset();
session_destroy;
$url = "Location: warning.html";
header($url);
}
?>
<html>
<head>
<title>Private Page 2</title>
</head>
<body>
<h1>Welcome to the private area 2</h1>
<?
echo "<h2>$username</h2>";
echo "<h2>This is page 2</h2>";
echo "<a href=\"home1.php\">Page 1</a> || ";
echo "<a href=\"logout.php\">Logout</a>";
?>
</body>
</html>
home2.php
<?PHP
if ((empty($username))||(empty($password)))
{
die ("Please fill in username and password");
}
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "SELECT * FROM user WHERE userName = '$username'";
$result = mysql_query($SQLcommand, $connect);
while($row = mysql_fetch_array($result))
{
$tmpUserName = $row["userName"];
$tmpPassword = $row["passWord"];
$tmpName = $row["fullName"];
}
if (!(($username==$tmpUserName)&&($password==$tmpPassword)))
{
echo "<h1>Wrong username and password!</h1>";
}
else
{
session_start();
session_register("username");
session_encode();
$url = "Location: home1.php?PHPSESSID=".$PHPSESSID;
header($url);
}
?>
login.php
<?PHP
session_start();
if (session_is_registered("username"))
{
session_unset();
session_destroy();
$url = "Location: home.php";
header($url);
}
else
{
die ("Only logged user can logout!");
}
?>
logout.php
<html>
<head>
<title>Registration Saved</title>
</head>
<body>
<p>
<?php
// Insert data to database
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "INSERT INTO `user` (`userID`, `userName`, `passWord`, `fullName`, `eMail`, `homepage`) VALUES ('', '$username2', '$password2', '$fname2', '$email2', '$homepage2') ";
$result = mysql_query($SQLcommand, $connect);
?>
Hi <span style = "color: blue"><strong>
<?php print( "$fname2" ); ?>.</strong></span>
Thank you for the registration.<br>
Please login using your username and password <br>
<table border = "0" cellpadding = "0" cellspacing = "10">
<tr><td bgcolor = "#ffffaa">Username </td>
<td bgcolor = "#ffffbb">Password</td>
</tr>
<tr><td bgcolor = "#ffffaa"><?php print( "$username2" ); ?> </td>
<td bgcolor = "#ffffbb"><?php print( "$password2" ); ?></td>
</tr>
</table>
<br>
<a href="home.php">Login NOW>></a>
</body>
</html>
register_process.php
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h1>Registration Form.</h1>
<p>Please fill in all fields and click Register.</p>
<form method = "post" action = "register_process.php">
<br>
<span style = "color: blue">
Please fill out the fields below.<br>
</span> <br>
Username:
<input type = "text" name = "username2" size="20"><br>
Password:
<input type = "text" name = "password2" size="20"><p><br>
Full Name:
<input type = "text" name = "fname2" size="20"><br>
Email:
<input type = "text" name = "email2" size="20"><br>
Homepage:
<input type = "text" name = "homepage2" size="20"><br>
<br>
<input type = "submit" value = "Register">
<input type = "reset" value = "Reset"> </p>
</form>
</body>
</html>
registration_form.html
<?php
session_start();
if (!(session_is_registered("username")))
{
session_unset();
session_destroy;
$url = "Location: warning.html";
header($url);
}
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "SELECT * FROM user WHERE userName = '$username'";
$result = mysql_query($SQLcommand, $connect);
while($row = mysql_fetch_array($result))
{
$tmpUserName = $row["userName"];
$tmpPassword = $row["passWord"];
$tmpEmail = $row["eMail"];
$tmpPassword = $row["passWord"];
$tmpUserID = $row["userID"];
$tmpName = $row["fullName"];
$tmpHomepage = $row["homepage"];
}
?>
<html> <head> <title>Update for Registration Form</title> </head>
<body>
<h1>Update for Registration Form.</h1>
<p>Please fill in all fields and click Register.</p>
<form method = "post" action = "update_process.php"><br>
<span style = "color: blue">
Please fill out the fields below.<br> </span> <br>
Username:
<input type = "text" name = "username2" size="20" value="<? print $tmpUserName; ?>"><br>
Password:
<input type = "text" name = "password2" size="20" value="<? print $tmpPassword; ?>"><p><br>
Full Name:
<input type = "text" name = "fname2" size="20" value="<? print $tmpName; ?>"><br>
Email:
<input type = "text" name = "email2" size="20" value="<? print $tmpEmail; ?>"><br>
Homepage:
<input type = "text" name = "homepage2" size="20" value="<? print $tmpHomepage; ?>"><br>
<br>
<input type = "hidden" name="userID2" value = "<? print $tmpUserID; ?>">
<input type = "submit" value = "Update">
<input type = "reset" value = "Reset"> </p>
</form>
</body>
</html>
update.php
<html>
<head>
<title>Updated</title>
</head>
<body>
<p>
<?php
// Insert data to database
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "UPDATE `user` SET `userName` = '$username2', `passWord` = '$password2', `fullName` = '$fname2', `eMail` = '$email2', `homepage` = '$homepage2' WHERE `userID` = '$userID2'";
$result = mysql_query($SQLcommand, $connect);
?>
Hi <span style = "color: blue"><strong>
<?php print( "$fname2" ); ?>.</strong></span>
You have successfully updated your profile.<br>
<br>
<br>
<a href="home1.php">BACK>></a>
</body>
</html>
update_process.php
<html>
<head>
<title>Unauthorized Access</title>
</head>
<body>
<h1>Unauthorized Access</h1>
<a href="home.php">Back to Login Page</a>
</body>
</html>
warning.html
Database dump file....
# phpMyAdmin MySQL-Dump
# version 2.2.3
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Generation Time: Feb 08, 2005 at 08:45 AM
# Server version: 3.23.47
# PHP Version: 4.1.1
# Database : `system`
# --------------------------------------------------------
#
# Table structure for table `user`
#
CREATE TABLE user (
userID tinyint(4) NOT NULL auto_increment,
userName varchar(8) NOT NULL default '',
passWord varchar(8) default NULL,
fullName text,
eMail text,
homepage tinytext,
KEY userID (userID)
) TYPE=MyISAM;
Good luck....
<html>
<head>
<title>Enter Username and Password</title>
</head>
<body>
<form method="get" action="login.php">
Enter your username and password:<br>
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password">
<br>
<input type="submit" name="submit" value="Submit">
</form>
<br>
<a href="registration_form.html">REGISTER</a>
</body>
</html>
home.php
<?PHP
session_start();
if (!(session_is_registered("username")))
{
session_unset();
session_destroy;
$url = "Location: warning.html";
header($url);
}
?>
<html>
<head>
<title>Private Page</title>
</head>
<body>
<h1>Welcome to the private area</h1>
<?
echo "<h2>Hi $username</h2>";
echo "<h2>This is page 1</h2>";
echo "<a href=\"home2.php\">Page 2</a> || ";
echo "<a href=\"update.php\">Update Profile</a> || ";
echo "<a href=\"logout.php\">Logout</a>";
?>
</body>
</html>
home1.php
<?PHP
session_start();
if (!(session_is_registered("username")))
{
session_unset();
session_destroy;
$url = "Location: warning.html";
header($url);
}
?>
<html>
<head>
<title>Private Page 2</title>
</head>
<body>
<h1>Welcome to the private area 2</h1>
<?
echo "<h2>$username</h2>";
echo "<h2>This is page 2</h2>";
echo "<a href=\"home1.php\">Page 1</a> || ";
echo "<a href=\"logout.php\">Logout</a>";
?>
</body>
</html>
home2.php
<?PHP
if ((empty($username))||(empty($password)))
{
die ("Please fill in username and password");
}
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "SELECT * FROM user WHERE userName = '$username'";
$result = mysql_query($SQLcommand, $connect);
while($row = mysql_fetch_array($result))
{
$tmpUserName = $row["userName"];
$tmpPassword = $row["passWord"];
$tmpName = $row["fullName"];
}
if (!(($username==$tmpUserName)&&($password==$tmpPassword)))
{
echo "<h1>Wrong username and password!</h1>";
}
else
{
session_start();
session_register("username");
session_encode();
$url = "Location: home1.php?PHPSESSID=".$PHPSESSID;
header($url);
}
?>
login.php
<?PHP
session_start();
if (session_is_registered("username"))
{
session_unset();
session_destroy();
$url = "Location: home.php";
header($url);
}
else
{
die ("Only logged user can logout!");
}
?>
logout.php
<html>
<head>
<title>Registration Saved</title>
</head>
<body>
<p>
<?php
// Insert data to database
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "INSERT INTO `user` (`userID`, `userName`, `passWord`, `fullName`, `eMail`, `homepage`) VALUES ('', '$username2', '$password2', '$fname2', '$email2', '$homepage2') ";
$result = mysql_query($SQLcommand, $connect);
?>
Hi <span style = "color: blue"><strong>
<?php print( "$fname2" ); ?>.</strong></span>
Thank you for the registration.<br>
Please login using your username and password <br>
<table border = "0" cellpadding = "0" cellspacing = "10">
<tr><td bgcolor = "#ffffaa">Username </td>
<td bgcolor = "#ffffbb">Password</td>
</tr>
<tr><td bgcolor = "#ffffaa"><?php print( "$username2" ); ?> </td>
<td bgcolor = "#ffffbb"><?php print( "$password2" ); ?></td>
</tr>
</table>
<br>
<a href="home.php">Login NOW>></a>
</body>
</html>
register_process.php
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h1>Registration Form.</h1>
<p>Please fill in all fields and click Register.</p>
<form method = "post" action = "register_process.php">
<br>
<span style = "color: blue">
Please fill out the fields below.<br>
</span> <br>
Username:
<input type = "text" name = "username2" size="20"><br>
Password:
<input type = "text" name = "password2" size="20"><p><br>
Full Name:
<input type = "text" name = "fname2" size="20"><br>
Email:
<input type = "text" name = "email2" size="20"><br>
Homepage:
<input type = "text" name = "homepage2" size="20"><br>
<br>
<input type = "submit" value = "Register">
<input type = "reset" value = "Reset"> </p>
</form>
</body>
</html>
registration_form.html
<?php
session_start();
if (!(session_is_registered("username")))
{
session_unset();
session_destroy;
$url = "Location: warning.html";
header($url);
}
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "SELECT * FROM user WHERE userName = '$username'";
$result = mysql_query($SQLcommand, $connect);
while($row = mysql_fetch_array($result))
{
$tmpUserName = $row["userName"];
$tmpPassword = $row["passWord"];
$tmpEmail = $row["eMail"];
$tmpPassword = $row["passWord"];
$tmpUserID = $row["userID"];
$tmpName = $row["fullName"];
$tmpHomepage = $row["homepage"];
}
?>
<html> <head> <title>Update for Registration Form</title> </head>
<body>
<h1>Update for Registration Form.</h1>
<p>Please fill in all fields and click Register.</p>
<form method = "post" action = "update_process.php"><br>
<span style = "color: blue">
Please fill out the fields below.<br> </span> <br>
Username:
<input type = "text" name = "username2" size="20" value="<? print $tmpUserName; ?>"><br>
Password:
<input type = "text" name = "password2" size="20" value="<? print $tmpPassword; ?>"><p><br>
Full Name:
<input type = "text" name = "fname2" size="20" value="<? print $tmpName; ?>"><br>
Email:
<input type = "text" name = "email2" size="20" value="<? print $tmpEmail; ?>"><br>
Homepage:
<input type = "text" name = "homepage2" size="20" value="<? print $tmpHomepage; ?>"><br>
<br>
<input type = "hidden" name="userID2" value = "<? print $tmpUserID; ?>">
<input type = "submit" value = "Update">
<input type = "reset" value = "Reset"> </p>
</form>
</body>
</html>
update.php
<html>
<head>
<title>Updated</title>
</head>
<body>
<p>
<?php
// Insert data to database
$connect=mysql_connect('localhost');
mysql_select_db('system');
$SQLcommand = "UPDATE `user` SET `userName` = '$username2', `passWord` = '$password2', `fullName` = '$fname2', `eMail` = '$email2', `homepage` = '$homepage2' WHERE `userID` = '$userID2'";
$result = mysql_query($SQLcommand, $connect);
?>
Hi <span style = "color: blue"><strong>
<?php print( "$fname2" ); ?>.</strong></span>
You have successfully updated your profile.<br>
<br>
<br>
<a href="home1.php">BACK>></a>
</body>
</html>
update_process.php
<html>
<head>
<title>Unauthorized Access</title>
</head>
<body>
<h1>Unauthorized Access</h1>
<a href="home.php">Back to Login Page</a>
</body>
</html>
warning.html
Database dump file....
# phpMyAdmin MySQL-Dump
# version 2.2.3
# http://phpwizard.net/phpMyAdmin/
# http://phpmyadmin.sourceforge.net/ (download page)
#
# Host: localhost
# Generation Time: Feb 08, 2005 at 08:45 AM
# Server version: 3.23.47
# PHP Version: 4.1.1
# Database : `system`
# --------------------------------------------------------
#
# Table structure for table `user`
#
CREATE TABLE user (
userID tinyint(4) NOT NULL auto_increment,
userName varchar(8) NOT NULL default '',
passWord varchar(8) default NULL,
fullName text,
eMail text,
homepage tinytext,
KEY userID (userID)
) TYPE=MyISAM;
Good luck....
#2
Posted 30 March 2005 - 09:11 AM
purely cause i can't be arsed to read it, whats it for, and do you care to explain the code a little for users starting to learn php?
#3
Posted 30 March 2005 - 12:43 PM
Exactly what i was thinking, this isn't really a tutorial as such, it's just a script.purely cause i can't be arsed to read it, whats it for, and do you care to explain the code a little for users starting to learn php?
#4
Posted 01 April 2005 - 03:04 AM
can we know about it's about???
#5
Posted 03 April 2005 - 10:03 AM
Lol that is a HUGE post lol. Its hard to understand if you dont know what its about, apart from the fact its way to long to keep anybodies attention
#6
Posted 03 April 2005 - 04:00 PM
**thinks**
Signup and login site
Signup and login site
#7
Posted 11 April 2005 - 07:58 PM
where do we use all this stuff in?(what area of Admin CP)
And whats it for and what will it do?
And whats it for and what will it do?
#8
Posted 12 April 2005 - 06:13 AM
its supposed to be a login/page protect script, but is there something wrong with it that u want us to check or what? are u just showin it off?
#9
Posted 16 May 2005 - 09:56 AM
I got a feeling thats just been copyed out of a script on hotscripts.com or maybe a tutorial which has been posted on P2L
#10
Posted 18 May 2005 - 05:55 AM
too long didn't read. not explained. this is not a tutorial.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users