我从PHP的书籍中学到了一些点点滴滴的注册脚本。不可思议的是,在本地主机上测试时(在提交测试注册页面之后),它会在浏览器中显示PHP脚本的来源。有什么我做错了吗?有没有人知道任何开源注册脚本?
由于
<?php
$submitted = $_POST["submitted"];
if ($submitted == 'yes') {
$firstName = mysql_real_escape_string($_POST["firstName"]);
$lastName = mysql_real_escape_string($_POST["lastName"]);
$eMail = mysql_real_escape_string($_POST["eMail"]);
$password = mysql_real_escape_string($_POST["password"]);
$confirmPassword = mysql_real_escape_string($_POST["confirmPassword"]);
// Kill script if input fields are blank
if ($firstName == '' or $lastName == '' or $eMail == '' or $password == '' or $confirmPassword == '') {
die();
}
// Check if passwords match
if ($password != $confirmPassword) {
die();
}
// Check if password is appropriat length
$passwordLength = strlen($password);
if ($passwordLength < 6 or $passwordLength > 30) {
die();
}
//////////////////////////
// Insert into database //
//////////////////////////
// Signup time in Unix Epoch
$time = time();
// Human readable date
$date = date("F jS, Y g:i:s A");
$sql = "INSERT into userInfo (firstName, lastName, password, eMail, time, date) VALUES ('$firstName', '$lastName', '$password', '$eMail', '$time', '$date')";
$sqlserver = "localhost";
$sqluser = "xxxxxx";
$sqlpassword = "xxxxxx";
mysql_connect($sqlserver, $sqluser, $sqlpassword) or die(mysql_error());
mysql_select_db("store");
// Check database if username already exists
$newEmail = $eMail;
$checkUsername = mysql_query("SELECT eMail FROM userinfo WHERE eMail = '$newEmail'");
$numRows = mysql_num_rows($checkUsername);
if ($numRows > 0) {
die();
}
mysql_query($sql) or die(mysql_error());
mysql_close();
header("Location: http://store.viddir.com/login/");
exit;
} else {
die();
}
?>
答案 0 :(得分:1)
您必须不执行php文件扩展名。这就是它返回PHP源代码的原因。
答案 1 :(得分:1)
您的PHP代码未被解释。原因可能是:
.php
扩展名命名您的文件。file://
而不是http://
)。
确保您的网址看起来像http://localhost/folder/stuff.php
,如果您正在使用MAMP,WAMP或XAMP,请检查您的活动端口是否有apache,并将其附加到您的网址,例如:localhost:8080
(默认如果我记得很清楚MAMP的端口。)
提醒:PHP是服务器端客户端,需要服务器来解释它(与HTML不同)。