-1

我对这些表格有疑问

注意:未定义的索引:第 2 行 C:\xampp\htdocs\putline\test1\index.php 中的 form_name

注意:未定义的索引:第 68 行 C:\xampp\htdocs\putline\test1\index.php 中的 form_name

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'loginform')
{
   $success_page = '';
   $error_page = basename(__FILE__);
   $mysql_server = 'localhost';
   $mysql_username = 'root';
   $mysql_password = '';
   $mysql_database = 'putline';
   $mysql_table = 'user';
   $crypt_pass = md5($_POST['password']);
   $found = false;
   $fullname = '';
   $session_timeout = 600;
   $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
   if (!$db)
   {
      die('Failed to connect to database server!<br>'.mysql_error());
   }
   mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());
   $sql = "SELECT password, fullname, active FROM ".$mysql_table." WHERE username = '".mysql_real_escape_string($_POST['username'])."'";
   $result = mysql_query($sql, $db);
   if ($data = mysql_fetch_array($result))
   {
      if ($crypt_pass == $data['password'] && $data['active'] != 0)
      {
         $found = true;
         $fullname = $data['fullname'];
      }
   }
   mysql_close($db);
   if($found == false)
   {
      header('Location: '.$error_page);
      exit;
   }
   else
   {
      if (session_id() == "")
      {
         session_start();
      }
      $_SESSION['username'] = $_POST['username'];
      $_SESSION['fullname'] = $fullname;
      $_SESSION['expires_by'] = time() + $session_timeout;
      $_SESSION['expires_timeout'] = $session_timeout;
      $rememberme = isset($_POST['rememberme']) ? true : false;
      if ($rememberme)
      {
         setcookie('username', $_POST['username'], time() + 3600*24*30);
         setcookie('password', $_POST['password'], time() + 3600*24*30);
      }
      header('Location: '.$success_page);
      exit;
   }
}
$username = isset($_COOKIE['username']) ? $_COOKIE['username'] : '';
$password = isset($_COOKIE['password']) ? $_COOKIE['password'] : '';
?>
<?php
$mysql_server = 'localhost';
$mysql_username = 'root';
$mysql_password = '';
$mysql_database = 'putline';
$mysql_table = 'users';
$success_page = '';
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['form_name'] == 'signupform')
{
   $newusername = $_POST['username'];
   $newemail = $_POST['email'];
   $newpassword = $_POST['password'];
   $confirmpassword = $_POST['confirmpassword'];
   $newfullname = $_POST['fullname'];
   $website = $_SERVER['HTTP_HOST'];
   $script = $_SERVER['SCRIPT_NAME'];
   $timestamp = time();
   $code = md5($website.$timestamp.rand(100000, 999999));
   if ($newpassword != $confirmpassword)
   {
      $error_message = 'Password and Confirm Password are not the same!';
   }
   else
   if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newusername))
   {
      $error_message = 'Username is not valid, please check and try again!';
   }
   else
   if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newpassword))
   {
      $error_message = 'Password is not valid, please check and try again!';
   }
   else
   if (!preg_match("/^[A-Za-z0-9_!@$.' &]{1,50}$/", $newfullname))
   {
      $error_message = 'Fullname is not valid, please check and try again!';
   }
   else
   if (!preg_match("/^.+@.+\..+$/", $newemail))
   {
      $error_message = 'Email is not a valid email address. Please check and try again.';
   }
   if (empty($error_message))
   {
      $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
      if (!$db)
      {
         die('Failed to connect to database server!<br>'.mysql_error());
      }
      mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());
      $sql = "SELECT username FROM ".$mysql_table." WHERE username = '".$newusername."'";
      $result = mysql_query($sql, $db);
      if ($data = mysql_fetch_array($result))
      {
         $error_message = 'Username already used. Please select another username.';
      }
   }
   if (empty($error_message))
   {
      $crypt_pass = md5($newpassword);
      $newusername = mysql_real_escape_string($newusername);
      $newemail = mysql_real_escape_string($newemail);
      $newfullname = mysql_real_escape_string($newfullname);
      $sql = "INSERT `".$mysql_table."` (`username`, `password`, `fullname`, `email`, `active`, `code`) VALUES ('$newusername', '$crypt_pass', '$newfullname', '$newemail', 0, '$code')";
      $result = mysql_query($sql, $db);
      mysql_close($db);
      $subject = 'Your new account';
      $message = 'A new account has been setup.';
      $message .= "\r\nUsername: ";
      $message .= $newusername;
      $message .= "\r\nPassword: ";
      $message .= $newpassword;
      $message .= "\r\n";
      $message .= "\r\nhttp://".$website.$script."?user=".$newusername."&code=$code";
      $header  = "From: no-reply@putline.com"."\r\n";
      $header .= "Reply-To: no-reply@putline.com"."\r\n";
      $header .= "MIME-Version: 1.0"."\r\n";
      $header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
      $header .= "Content-Transfer-Encoding: 8bit"."\r\n";
      $header .= "X-Mailer: PHP v".phpversion();
      mail($newemail, $subject, $message, $header);
      header('Location: '.$success_page);
      exit;
   }
}
else
if (isset($_GET['code']) && isset($_GET['user']))
{
   $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
   if (!$db)
   {
      die('Failed to connect to database server!<br>'.mysql_error());
   }
   mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());
   $sql = "SELECT * FROM ".$mysql_table." WHERE username = '".$_GET['user']."' AND code = '".$_GET['code']."'";
   $result = mysql_query($sql, $db);
   if ($data = mysql_fetch_array($result))
   {
      $sql = "UPDATE `".$mysql_table."` SET `active` = 1 WHERE `username` = '".$_GET['user']."'";
      mysql_query($sql, $db);
   }
   else
   {
      die ('User not found!');
   }
   mysql_close($db);
   header("refresh:5;url=".basename(__FILE__));
   echo 'Your user account was succesfully activated. You\'ll be redirected in about 5 secs. If not, click <a href="'.basename(__FILE__).'">here</a>.';
   exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Untitled Page</title>
<style type="text/css">
body
{
   margin: 0;
   padding: 0;
   background-color: #FFFFFF;
   color: #000000;
}
</style>
<style type="text/css">
a
{
   color: #0000FF;
   text-decoration: underline;
}
a:visited
{
   color: #800080;
}
a:active
{
   color: #FF0000;
}
a:hover
{
   color: #0000FF;
   text-decoration: underline;
}
</style>
<style type="text/css">
#loginform
{
   background-color: #522D2B;
   border: 1px #878787 solid;
}
#Text1 
{
   background-color: #6C3C39;
   border: 0px #000000 solid;
   padding: 0;
   text-align: center;
}
#Text1 div
{
   text-align: center;
}
#Text2 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: right;
}
#Text2 div
{
   text-align: right;
}
#username
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color :#A9A9A9;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#Text3 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: right;
}
#Text3 div
{
   text-align: right;
}
#password
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color :#A9A9A9;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#Text4 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: left;
}
#Text4 div
{
   text-align: left;
}
#login
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color: #000000;
   font-family: Arial;
   font-size: 13px;
}
#signupform
{
   background-color: #255853;
   border: 1px #878787 solid;
}
#Text5 
{
   background-color: #347C75;
   border: 0px #000000 solid;
   padding: 0;
   text-align: center;
}
#Text5 div
{
   text-align: center;
}
#Text6 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: right;
}
#Text6 div
{
   text-align: right;
}
#fullname
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color :#A9A9A9;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#Text7 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: right;
}
#Text7 div
{
   text-align: right;
}
#username
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color :#A9A9A9;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#Text8 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: right;
}
#Text8 div
{
   text-align: right;
}
#password
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color :#A9A9A9;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#Text9 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: right;
}
#Text9 div
{
   text-align: right;
}
#confirmpassword
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color :#A9A9A9;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#Text10 
{
   background-color: transparent;
   border: 0px #000000 solid;
   padding: 0;
   text-align: right;
}
#wb_Text10 div
{
   text-align: right;
}
#email
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color :#A9A9A9;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#error
{
   border: 0px #EEEEEE solid;
   background-color: #255853;
   color :#FF8C00;
   font-family: Arial;
   font-size: 13px;
   text-align: left;
   vertical-align: middle;
}
#signup
{
   border: 1px #878787 solid;
   background-color: #FFFFFF;
   color: #000000;
   font-family: Arial;
   font-size: 13px;
}
</style>
</head>
<body>
<div id="loginform" style="position:absolute;left:57px;top:97px;width:300px;height:175px;z-index:22;">
<form name="loginform" method="post" action="" enctype="text/plain" id="loginform">
<input type="hidden" name="form_name" value="loginform">
<div id="Text1" style="position:absolute;left:4px;top:4px;width:292px;height:16px;text-align:center;z-index:0;">
<span style="color:#FFFFFF;font-family:Arial;font-size:13px;">Log In</span></div>
<div id="Text2" style="position:absolute;left:4px;top:32px;width:94px;height:16px;text-align:right;z-index:1;">
&nbsp;</div>
<div id="Text3" style="position:absolute;left:4px;top:58px;width:94px;height:16px;text-align:right;z-index:2;">
&nbsp;</div>
<div id="Text4" style="position:absolute;left:31px;top:113px;width:179px;height:16px;z-index:3;text-align:left;">
<span style="color:#FFFFFF;font-family:Arial;font-size:13px;">Remember me</span></div>
<input type="checkbox" id="rememberme" name="rememberme" value="on" style="position:absolute;left:12px;top:112px;z-index:4;">
<input type="submit" id="login" name="login" value="Log In" style="position:absolute;left:221px;top:143px;width:76px;height:29px;z-index:5;">
<input type="text" id="username" style="position:absolute;left:7px;top:35px;width:279px;height:24px;line-height:24px;z-index:6;" name="username" value="<?php echo $username; ?>" placeholder="username">
<input type="password" id="password" style="position:absolute;left:7px;top:77px;width:279px;height:24px;line-height:24px;z-index:7;" name="password" value="<?php echo $password; ?>" placeholder="password">
</form>
</div>

<div id="signupform" style="position:absolute;left:534px;top:92px;width:313px;height:320px;z-index:24;">
<form name="signupform" method="post" action="<?php echo basename(__FILE__); ?>" id="signupform">
<input type="hidden" name="form_name" value="signupform">
<div id="Text5" style="position:absolute;left:4px;top:4px;width:305px;height:16px;text-align:center;z-index:8;">
<span style="color:#FFFFFF;font-family:Arial;font-size:13px;">Sign up for a new account</span></div>
<div id="Text6" style="position:absolute;left:4px;top:32px;width:75px;height:16px;text-align:right;z-index:9;">
&nbsp;</div>
<div id="Text7" style="position:absolute;left:4px;top:58px;width:75px;height:16px;text-align:right;z-index:10;">
&nbsp;</div>
<div id="Text8" style="position:absolute;left:4px;top:84px;width:75px;height:16px;text-align:right;z-index:11;">
&nbsp;</div>
<div id="Text9" style="position:absolute;left:4px;top:110px;width:75px;height:16px;text-align:right;z-index:12;">
&nbsp;</div>
<div id="Text10" style="position:absolute;left:4px;top:136px;width:75px;height:16px;text-align:right;z-index:13;">
&nbsp;</div>
<input type="text" id="error" style="position:absolute;left:14px;top:234px;width:150px;height:20px;line-height:20px;z-index:14;" name="error" value="<?php echo $error_message; ?>">
<input type="text" id="fullname" style="position:absolute;left:14px;top:27px;width:279px;height:24px;line-height:24px;z-index:15;" name="fullname" value="">
<input type="text" id="username" style="position:absolute;left:14px;top:66px;width:279px;height:24px;line-height:24px;z-index:16;" name="username1" value="">
<input type="password" id="password" style="position:absolute;left:14px;top:105px;width:279px;height:24px;line-height:24px;z-index:17;" name="password1" value="">
<input type="password" id="confirmpassword" style="position:absolute;left:14px;top:148px;width:279px;height:24px;line-height:24px;z-index:18;" name="confirmpassword" value="">
<input type="text" id="email" style="position:absolute;left:14px;top:192px;width:279px;height:24px;line-height:24px;z-index:19;" name="email" value="">
<input type="submit" id="signup" name="signup" value="Sgin Up" style="position:absolute;left:235px;top:289px;width:76px;height:29px;z-index:20;">
</form>
</div>

</body>
</html>
4

1 回答 1

1

您可以添加检查关联数组索引form_name是否存在/字段是否已发送,例如

if (($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST['form_name']) && ($_POST['form_name'] == 'loginform')) 

这避免了通知消息。 http://us.php.net/isset

此外,在生产应用程序中,您应该关闭可见的 PHP 错误消息。只需让 php 将它们记录到文件中。但是在开发系统中,这样的消息当然是有帮助的。

于 2013-10-19T13:55:37.757 回答