i 是在 php/ mysql 中是新来的, 抱歉如果我的问题很傻的话。 我正在尝试用 php 和 Mysql 建立一个注册/ login/ logout 系统。 我的技巧不好, 我不是一个程序员, 所以我试图更改我在网络上找到的脚本。 它包含文件, 索引. php, 激活 php. login. php, 登录. php, 注册. php 。
当我尝试给定的示例时,它效果很好, 但
< 加强> index.php: 加强 > 是一个非常简单的文件, 它有 html 格式, 询问未知用户是否想要登录或注册并同时启动会话
<强度> logout.php: 强度> 简单解密会话
<强>login.php: 强>
<?php session_start(); ?>
<html>
<body>
<?php
if(isset($_POST["user"])){
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die( Could not connect: . mysql_error());
}
mysql_select_db("myapp", $con);
$sql = "SELECT * FROM `users` WHERE `user` LIKE ". mysql_real_escape_string($_POST["user"])
." AND ".
"`pass` LIKE MD5( ". mysql_real_escape_string($_POST["pass"])
." ) AND ".
"`active` = DONE ";
$result = mysql_query($sql);
$found = 0;
while ($row = mysql_fetch_array($result)) {
if ($row[1]==$_POST["user"]) {
$found = 1;
}
}
if ($found) {
$_SESSION["USER"] = $_POST["user"];
?>Thank you for logging in<?
}
else {
?>User/Pass is wrong!<?
}
mysql_close($con);
}
else {
?>
Please log-in:<br/>
<form action="login.php" method="POST">
User: <input type="text" name="user"><br />
Pass: <input type="password" name="pass"><br />
<input type="submit" />
</form>
<?php
}
?>
<强度 > 登记员.php: 强度>
<?php session_start(); ?>
<html>
<body>
<?php
if(isset($_POST["user"])){
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die( Could not connect: . mysql_error());
}
mysql_select_db("myapp", $con);
$random = rand();
$sql = "INSERT INTO `myapp`.`users` (`id`, `user`, `pass`, `active`, `firstname`, `lastname`, `mail`) ".
" VALUES (NULL, ". mysql_real_escape_string($_POST["user"])
." , MD5( ".mysql_real_escape_string($_POST["pass"])
." ), ".mysql_real_escape_string($random)
." ), ".mysql_real_escape_string($_POST["firstname"])
." ), ".mysql_real_escape_string($_POST["lastname"])
." ) ".mysql_real_escape_string($_POST["mail"])
." );";
mysql_query($sql);
mysql_close($con);
$message = "Please put this url http://localhost/mypage/activate.php?active=" . $random . " in your browser to activate your account.";
@mail($_POST["mail"], Thank you for registering , $message);
?>Thank you <?php echo $_POST["user"]; ?> we send you a confirmation e-mail in <?php echo $_POST["mail"]; ?><?php
echo $message;
}
else {
?>
Please register:<br/>
<form action="register.php" method="POST">
User: <input type="text" name="user"><br />
Pass: <input type="password" name="pass"><br />
firstname:<input type="text" name="firstname"><br />
lastname:<input type="text" name="lastname"><br />
mail: <input type="text" name="mail"><br />
<input type="submit" />
</form>
<?php
}
?>
activate.php: 。 php:
<?php session_start(); ?>
<html>
<body>
<?php
if(isset($_GET["active"])){
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die( Could not connect: . mysql_error());
}
mysql_select_db("myapp", $con);
$sql = "SELECT * FROM `users` WHERE `active` LIKE ".
mysql_real_escape_string($_GET["active"])." ";
$result = mysql_query($sql);
$found = 0;
while ($row = mysql_fetch_array($result)) {
$found = 1;
}
if ($found) {
$sql = "UPDATE `users` SET `active` = DONE ";
$result = mysql_query($sql);
?>Thank you for activating<?
}
else {
?>Can t find user!<?
}
mysql_close($con);
}
else {
?>Invalid activation<?php
}
?>
</body>
</html>
任何帮助都会受到欢迎,