嘿,伙计们,我正在创建一个带有登录和注册的网站,并且默认情况下会在用户在表单中注册然后登录后创建一个个人资料页面帽子这些信息将显示为个人资料页面中的个人资料信息,每个人都是唯一的用户。用户名将指定每个用户及其个人资料页面。这些是一些 php 文件,任何人都知道如何仅显示属于指定用户的信息,而不是所有用户的所有信息。
注册表格.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration Page</title>
<link href="style/stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<?php require_once('header.php'); ?>
<body>
<h2 class="RegisterTitleForm">Registration Form</h2>
<h3 class="requiredField">* Requierd Field!!</h3>
<table width="280" border="0" align="center">
<form action="registerProcess.php" method="post" id="registerForm">
<tr>
<input type="hidden" name="uid" id="uid" />
<td style="text-align: right"><label for="firstname"><span class="Fields">First Name</span> <span class="requiredField">*</span></label></td>
<td><input type="text" name="firstname" id="firstname" /></td>
</tr>
<tr>
<td style="text-align: right"><label for="lasttname" class="Fields">Last Name</label></td>
<td><input type="text" name="lastname" id="lastname" /></td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="birthdate">Birth Date</label></td>
<td><input type="date" name="birthdate" value= "YYYY_MM_DD" onfocus="if (this.value == 'YYYY_MM_DD') {this.value = '';}" onblur="if (this.value == '') {this.value = 'YYYY_MM_DD';}" type="text" id="birthdate" /></td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="phonenumber">Phone Number</label></td>
<td><input type="tel" name="phonenumber" value="000-0-000 000" onfocus="if (this.value == '000-0-000 000') {this.value = '';}" onblur="if (this.value == '') {this.value = '000-0-000 000';}" type="text" id="phonenumber" /></td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="gender">Gender <span class="requiredField">*</span></label></td>
<td><p>
<label class="Fields">
<input type="radio" name="genderGroup" value="Male" id="genderGroup_male" />
Male</label>
<br />
<label class="Fields">
<input type="radio" name="genderGroup" value="Female" id="genderGroup_female" />
Female</label>
<br />
</p></td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="country">Country</label></td>
<td><select name="country" id="country"><option selected=>please choose coutry<option>lebanon<option>Us<option>europe
</select></td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="adress">Local Adress <span class="requiredField">*</span></label></td>
<td><input type="text" name="adress" id="adress" /></td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="specialisation">Specialisation <span class="requiredField">*</span></label></td>
<td><select name="specialisation" id="specialisation">
</select></td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="email">Email Adress<span class="requiredField">*</span></label></td>
<td><input type="email" name="email" id="email" /></td>
</td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="username">User Name<span class="requiredField">*</span></label></td>
<td><input type="text" name="username" id="username" /></td>
</td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="password">Password<span class="requiredField">*</span></label></td>
<td><input type="password" name="password" id="password" /></td>
</td>
</tr>
<tr>
<td class="Fields" style="text-align: right"><label for="password2">Re_Password<span class="requiredField">*</span></label></td>
<td><input type="password" name="password2" id="password2" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="register" id="register" value="Register" /></td>
</tr>
</form>
</table>
</body>
</html>
注册进程.php
<?php
require_once('config.php');
if(isset($_POST['register']))
{
if(! get_magic_quotes_gpc() )
{
$firstname = addslashes ($_POST['firstname']);
$lastname = addslashes ($_POST['lastname']);
$birthdate = addslashes ($_POST['birthdate']);
$phonenumber = addslashes ($_POST['phonenumber']);
$genderGroup = addslashes ($_POST['genderGroup']);
$country = addslashes ($_POST['country']);
$adress = addslashes ($_POST['adress']);
$specialisation = addslashes ($_POST['specialisation']);
$email = addslashes ($_POST['email']);
$password2 = addslashes ($_POST['password2']);
$username = addslashes ($_POST['username']);
$password = addslashes ($_POST['password']);
$password2 = addslashes ($_POST['password2']);
}
else
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$birthdate = $_POST['birthdate'];
$phonenumber = $_POST['phonenumber'];
$genderGroup = $_POST['genderGroup'];
$country = $_POST['country'];
$adress = $_POST['adress'];
$specialisation = $_POST['specialisation'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
}
$sql = "INSERT INTO users ".
"(firstname,lastname, birthdate, phonenumber, gender, country, localadress, specialisation, email, username, password, password2, joindate) ". "VALUES('$firstname','$lastname','$birthdate','$phonenumber','$genderGroup','$country','$adress','$specialisation','$email','$username','$password','$password2', NOW())";
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not enter data: ' . mysql_error());
}
echo "Entered data successfully\n";
}
mysql_close($conn);
?>
登录表单.php
<?php require_once('Connections/conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['username'])) {
$loginUsername=$_POST['username'];
$password=$_POST['password'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "profileForm.php";
$MM_redirectLoginFailed = "registerForm.php";
$MM_redirecttoReferrer = false;
mysql_select_db($database_conn, $conn);
$LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $conn) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && false) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<!--link CSS-->
<link href="style/stylesheet.css" rel="stylesheet" type="text/css" />
<body>
<!--<?php require_once('header.php'); ?>-->
<div id="loginForm"><table width="250" border="0" align="right">
<form id="loginForm" name="loginForm" method="POST" action="<?php echo
$loginFormAction; ?>">
<tr>
<td><label for="username">User Name</label></td>
<td><input type="text" name="username" id="username" /></td>
</tr>
<tr>
<td><label for="password">Password</label></td>
<td><input type="text" name="password" id="password" /></td>
</tr>
<tr>
<td> </td>
<td bgcolor="#FFFFFF"><input type="submit" name="login" id="login" value="Log In" />
<a href="registerForm.php"><strong> Register</strong></a></td>
</tr>
</form>
</table>
</div>
<?php require_once('footer.php'); ?>
</body>
</html>
profileForm.php
个人资料页
<body>
<?php require_once('header.php'); ?>
<?php
$con = mysql_connect("localhost","root","root");
if(!$con)
{
die('Could not connect: '.mysql_error());
}
mysql_select_db("testregister",$con);
$username =(isset($_POST['username']));
$result =mysql_query("Select * from users");
while ($row=mysql_fetch_array($result))
{
echo "<table border='0'>
<tr>
<td> First Name: </td>
<td>" .$row['firstname'] ." </td>
</tr>
<tr>
<td> Last Name: </td>
<td>" .$row['lastname'] ." </td>
</tr>
<tr>
<td> Birth Date: </td>
<td>".$row['birthdate'] ." </td>
</tr>
<tr>
<td> Phone Number: </td>
<td> ".$row['phonenumber'] ." </td>
</tr>
<tr>
<td> Gender: </td>
<td> ".$row['gender'] ." </td>
</tr>
<tr>
<td> Country: </td>
<td>".$row['country'] ."</td>
</tr>
<tr>
<td> Specialization: </td>
<td>".$row['specialisation'] ."</td>
</tr>
<tr>
<td> Email: </td>
<td>".$row['email'] ."</td>
</tr>
<tr>
<td> User Name: </td>
<td>".$row['username'] ."</td>
</tr>
<tr>
<td> Join Date: </td>
<td>".$row['joindate'] ."</td>
</tr>";
}
echo "</table>";
mysql_close ($con);
?>
<html>
<body>
Login Successful
<p><a href="logout.php\">Click here to logout!</a></p>
</body>
</html>
</body>
</html>