我正在尝试为我正在处理的网站创建登录页面,我可以访问该服务器。
我可以加载一些100%工作的页面,但是当我向网站添加成员时,它会给我一条错误消息:
错误500
sharedweb.unisite.ac.uk页面无效。 sharedweb.unisite.ac.uk目前无法处理此请求。
我不知道为什么。导致此错误的脚本是:
<?php
// include function files for this application
require_once('bookmark_fns.php');
//create short variable names
$email=$_POST['email'];
$username=$_POST['username'];
$passwd=$_POST['passwd'];
$passwd2=$_POST['passwd2'];
// start session which may be needed later
// start it now because it must go before headers
session_start();
try {
// check forms filled in
if (!filled_out($_POST)) {
throw new Exception('You have not filled the form out correctly. Please go back and try again.');
}
// email address not valid
if (!valid_email($email)) {
throw new Exception('That is not a valid email address. Please go back and try again.');
}
// passwords not the same
if ($passwd != $passwd2) {
throw new Exception('The passwords you entered do not match. Please go back and try again.');
}
// check password length is ok
// ok if username truncates, but passwords will get
// munged if they are too long.
if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z]{6,12}$/)', $passwd)) {
throw new Exception('Your password must be between 6 and 12 characters inclusive. Please go back and try again.');
}
// attempt to register
// this function can also throw an exception
register($username, $email, $passwd);
// register session variable
$_SESSION['valid_user'] = $username;
// provide link to members page
do_html_header('Registration successful');
echo "Welcome " $_POST["username"];
echo 'Your registration was successful. Go to the members page to start setting up your bookmarks!';
do_html_url('member.php', 'Go to members page');
// end page
do_html_footer();
}
catch (Exception $e) {
do_html_header('Warning:');
echo $e->getMessage();
do_html_footer();
exit;
}
?>
我该如何解决这个问题?
答案 0 :(得分:1)
您的代码中存在2个语法错误:
首先,您需要使用.
:
echo "Welcome " . $_POST["username"];
其次,这里有一个额外的结束括号:
if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z]{6,12}$/)', $passwd)) {
throw new Exception('Your password must be between 6 and 12 characters inclusive. Please go back and try again.');
}
删除额外的括号:
if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z]{8,12}$/', $passwd)) {
throw new Exception('Your password must be between 6 and 12 characters inclusive. Please go back and try again.');
}
至于这个错误:
不推荐使用:不推荐使用函数ereg()
PHP手册:
ereg()
在PHP 5.3.0中已弃用,并在PHP 7.0.0中被删除。
查看此帖子:Deprecated: Function ereg() is deprecated
提示:您应该通过将此代码添加到PHP文件的顶部来启用Error Reporting,这将有助于您查找错误。
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);