我正在为我的网站注册页面。当我尝试在Firefox中打开它时,它说:
Parse error: syntax error, unexpected 'login' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\register.php on line 30
我不明白这是什么意思
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
include("/session.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>Register | McWarfare</title>
<link rel="stylesheet" href="/style/style.css" type="text/css" media="screen" />
</head>
<body>
<div align="center" id="mainWrapper">
<?php include_once("template_header.php");?>
<div id="pageContent">
<table bgcolor="#bbbbbb" width="100%" border="0" cellspacing="0" cellpadding="10">
<td width="10%" valign="top" align="center">
<?php
if($session->logged_in){
echo "<h1>Registered</h1>";
echo "<p>We're sorry <b>$session->username</b>, but you're already registered. "
}
else if(isset($_SESSION['regsuccess'])){
if($_SESSION['regsuccess']){
echo "<p>Congratulations <b>".$_SESSION['reguname']."</b>, your account was successfully created! "
}
else{
echo "<h1>Registration Failed</h1>";
echo "<p>We're sorry <b>".$_SESSION['reguname']."</b>, "
.", but your request could not be completed.<br>Please try again at a later time.</p>";
}
unset($_SESSION['regsuccess']);
unset($_SESSION['reguname']);
}
else{
?>
<h1>Register</h1>
<?php
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<form action="process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr>
<td>
</td>
<td>
Username:
</td>
<td>
<input type="text" name="user" maxlength="16" value="<?php echo $form->value("user"); ?>">
</td>
<td>
<?php echo $form->error("user"); ?>
</td>
</tr>
<tr>
<td>
</td>
<td>
Password:
</td>
<td>
<input type="password" name="pass" maxlength="30" value="<?php echo $form->value("pass"); ?>">
</td>
<td>
<?php echo $form->error("pass"); ?>
</td>
</tr>
<tr>
<td>
</td>
<td>
Email:
</td>
<td>
<input type="text" name="email" maxlength="50" value="<?php echo $form->value("email"); ?>">
</td>
<td>
<?php echo $form->error("email"); ?>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="hidden" name="subjoin" value="1">
<input type="submit" value="Register!">
</td>
</tr>
<tr>
<td colspan="2" align="left">Back to <a href="/login">login</a> page.
</td>
</tr>
</table>
</form>
<?php
}
?>
</td>
</table>
</div>
<?php include_once("template_footer.php");?>
</div>
</body>
</html>
以下代码适用于@Phil请求的session.php。如果您需要任何其他文件,请询问。
<?php
include("/database.php");
include("/mailer.php");
include("/form.php");
class Session
{
var $username;
var $userid;
var $userlevel;
var $time;
var $logged_in;
var $userinfo = array();
var $url;
var $referrer;
function Session(){
$this->time = time();
$this->startSession();
}
function startSession(){
global $database;
session_start();
$this->logged_in = $this->checkLogin();
if(!$this->logged_in){
$this->username = $_SESSION['username'] = GUEST_NAME;
$this->userlevel = GUEST_LEVEL;
$database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
}
else{
$database->addActiveUser($this->username, $this->time);
}
$database->removeInactiveUsers();
$database->removeInactiveGuests();
if(isset($_SESSION['url'])){
$this->referrer = $_SESSION['url'];
}else{
$this->referrer = "/";
}
$this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
}
function checkLogin(){
global $database;
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
$this->username = $_SESSION['username'] = $_COOKIE['cookname'];
$this->userid = $_SESSION['userid'] = $_COOKIE['cookid'];
}
if(isset($_SESSION['username']) && isset($_SESSION['userid']) &&
$_SESSION['username'] != GUEST_NAME){
if($database->confirmUserID($_SESSION['username'], $_SESSION['userid']) != 0){
unset($_SESSION['username']);
unset($_SESSION['userid']);
return false;
}
$this->userinfo = $database->getUserInfo($_SESSION['username']);
$this->username = $this->userinfo['username'];
$this->userid = $this->userinfo['userid'];
$this->userlevel = $this->userinfo['userlevel'];
return true;
}
else{
return false;
}
}
function login($subuser, $subpass, $subremember){
global $database, $form;
$field = "user";
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, "* Username not entered");
}
else{
if(!preg_match("/^([0-9a-z])*$/i", $subuser)){
$form->setError($field, "* Username not alphanumeric");
}
}
$field = "pass";
if(!$subpass){
$form->setError($field, "* Password not entered");
}
if($form->num_errors > 0){
return false;
}
$subuser = stripslashes($subuser);
$result = $database->confirmUserPass($subuser, md5($subpass));
if($result == 1){
$field = "user";
$form->setError($field, "* Username not found");
}
else if($result == 2){
$field = "pass";
$form->setError($field, "* Invalid password");
}
if($form->num_errors > 0){
return false;
}
$this->userinfo = $database->getUserInfo($subuser);
$this->username = $_SESSION['username'] = $this->userinfo['username'];
$this->userid = $_SESSION['userid'] = $this->generateRandID();
$this->userlevel = $this->userinfo['userlevel'];
$database->updateUserField($this->username, "userid", $this->userid);
$database->addActiveUser($this->username, $this->time);
$database->removeActiveGuest($_SERVER['REMOTE_ADDR']);
if($subremember){
setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
setcookie("cookid", $this->userid, time()+COOKIE_EXPIRE, COOKIE_PATH);
}
return true;
}
function logout(){
global $database;
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
setcookie("cookname", "", time()-COOKIE_EXPIRE, COOKIE_PATH);
setcookie("cookid", "", time()-COOKIE_EXPIRE, COOKIE_PATH);
}
unset($_SESSION['username']);
unset($_SESSION['userid']);
$this->logged_in = false;
$database->removeActiveUser($this->username);
$database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
$this->username = GUEST_NAME;
$this->userlevel = GUEST_LEVEL;
}
function register($subuser, $subpass, $subemail){
global $database, $form, $mailer;
$field = "user";
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, "* Username not entered");
}
else{
$subuser = stripslashes($subuser);
if(strlen($subuser) < 5){
$form->setError($field, "* Username below 5 characters");
}
else if(strlen($subuser) > 30){
$form->setError($field, "* Username above 30 characters");
}
else if(!preg_match("/^([0-9a-z])+$/i", $subuser)){
$form->setError($field, "* Username not alphanumeric");
}
else if(strcasecmp($subuser, GUEST_NAME) == 0){
$form->setError($field, "* Username reserved word");
}
else if($database->usernameTaken($subuser)){
$form->setError($field, "* Username already in use");
}
else if($database->usernameBanned($subuser)){
$form->setError($field, "* Username banned");
}
}
$field = "pass";
if(!$subpass){
$form->setError($field, "* Password not entered");
}
else{
$subpass = stripslashes($subpass);
if(strlen($subpass) < 4){
$form->setError($field, "* Password too short");
}
else if(!preg_match("/^([0-9a-z])+$/i", ($subpass = trim($subpass)))){
$form->setError($field, "* Password not alphanumeric");
}
}
$field = "email";
if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, "* Email not entered");
}
else{
$regex = "/^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$/i";
if(!preg_match($regex,$subemail)){
$form->setError($field, "* Email invalid");
}
$subemail = stripslashes($subemail);
}
if($form->num_errors > 0){
return 1;
}
else{
if($database->addNewUser($subuser, md5($subpass), $subemail)){
if(EMAIL_WELCOME){
$mailer->sendWelcome($subuser,$subemail,$subpass);
}
return 0;
}else{
return 2;
}
}
}
function editAccount($subcurpass, $subnewpass, $subemail){
global $database, $form;
if($subnewpass){
$field = "curpass";
if(!$subcurpass){
$form->setError($field, "* Current Password not entered");
}
else{
$subcurpass = stripslashes($subcurpass);
if(strlen($subcurpass) < 4 ||
!preg_match("/^([0-9a-z])+$/i", ($subcurpass = trim($subcurpass)))){
$form->setError($field, "* Current Password incorrect");
}
if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){
$form->setError($field, "* Current Password incorrect");
}
}
$field = "newpass";
$subpass = stripslashes($subnewpass);
if(strlen($subnewpass) < 4){
$form->setError($field, "* New Password too short");
}
else if(!preg_match("/^([0-9a-z])+$/i", ($subnewpass = trim($subnewpass)))){
$form->setError($field, "* New Password not alphanumeric");
}
}
else if($subcurpass){
$field = "newpass";
$form->setError($field, "* New Password not entered");
}
$field = "email";
if($subemail && strlen($subemail = trim($subemail)) > 0){
$regex = "/^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$/i";
if(!preg_match($regex,$subemail)){
$form->setError($field, "* Email invalid");
}
$subemail = stripslashes($subemail);
}
if($form->num_errors > 0){
return false;
}
if($subcurpass && $subnewpass){
$database->updateUserField($this->username,"password",md5($subnewpass));
}
if($subemail){
$database->updateUserField($this->username,"email",$subemail);
}
return true;
}
function isAdmin(){
return ($this->userlevel == ADMIN_LEVEL ||
$this->username == ADMIN_NAME);
}
function generateRandID(){
return md5($this->generateRandStr(16));
}
function generateRandStr($length){
$randstr = "";
for($i=0; $i<$length; $i++){
$randnum = mt_rand(0,61);
if($randnum < 10){
$randstr .= chr($randnum+48);
}else if($randnum < 36){
$randstr .= chr($randnum+55);
}else{
$randstr .= chr($randnum+61);
}
}
return $randstr;
}
};
$session = new Session;
$form = new Form;
?>
答案 0 :(得分:3)
在这些行的末尾添加分号:
echo "<p>We're sorry <b>$session->username...
和
echo "<p>Congratulations <b>".$_SESSION...