php:从v7更改为v5时出现语法错误
我将我的php创建放到一个web托管服务上。他们支持php,但使用5,我在v7中编写了我的程序。我得到的唯一错误是语法错误:php:从v7更改为v5时出现语法错误,php,syntax-error,Php,Syntax Error,我将我的php创建放到一个web托管服务上。他们支持php,但使用5,我在v7中编写了我的程序。我得到的唯一错误是语法错误: Parse error: syntax error, unexpected '[' in /home/a9537925/public_html/V.4/www/login/index.php on line 46 错误发生在以下行: $token = create_token(login_info($email, $password)['user_id']); 该页面
Parse error: syntax error, unexpected '[' in /home/a9537925/public_html/V.4/www/login/index.php on line 46
错误发生在以下行:
$token = create_token(login_info($email, $password)['user_id']);
该页面的代码为:
<?php
require '../../request_manager.php';
if (isset($post['submit']))
{
$data_missing = array();
if (empty($post['password']))
{
$data_missing[] = 'Password';
}
else
{
$password = trim($post['password']);
}
if (empty($post['email']))
{
$data_missing[] = 'email';
}
else
{
$email = trim($post['email']);
}
if (empty($data_missing))
{
require '../../mysql.php';
require '../../login_manager.php';
$query = "SELECT * FROM login_info where primary_email = ?;";
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_bind_param($stmt, "s", $email);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$output = mysqli_fetch_assoc($result);
if ($extraOutput = mysqli_fetch_assoc($result))
{
echo "MySQL retrned extra values";
}
if (!mysqli_error($dbc) == "")
{
die("Error while qxecuting MySQL query");
}
if ($output == null)
{
die("The email or password was incorect");
}
if (verifyPassword($password, $output['password']))
{
$token = create_token(login_info($email, $password)['user_id']);
die('
<html>
<body>
<form action="../main/index.php" method="post">
<input type="hidden" name="token" value="' . $token . '">
<div id="manual" style="display: none;">
if your browser dose not suport automatic redirects, click <input type="submit" value="here">
</div>
</form>
<script type="text/javascript">document.forms[0].submit();</script>
<script>setTimeout(function() { document.getElementById("manual").style = "" }, 3000);</script>
</body>
</html>
');
}
else
{
echo "The email or password was incorect";
}
}
else
{
echo "The folowing data was not submited: ";
foreach ($data_missing as $missing)
{
echo $missing . " ";
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<br>
<a href="../signup">Sign Up</a>
<h3>Login</h3>
<form action="./" method="post">
<p>Email</p>
<input type="text" name="email" required>
<p>Password</p>
<input type="password" name="password" required>
<br><br>
<input type="submit" name="submit" value="Login">
</form>
</body>
</html>
可以找到站点的其余代码。您需要调用login\u info$email$password并分别分配给一个变量,然后从该新变量获取索引
这是因为我猜您的PHP版本实际上是5.3,它已经过时了,所以我建议更好的主机不支持函数数组解引用允许您访问函数调用的数组键的位,即在5.4.0中添加的[]你需要调用login\u info$email,$password并分别分配给一个变量,然后从该新变量获取索引。PHP 5.7从未有过-您的代码在许多级别上都失败了。另外,还有太多的未知数。@JonStirling你能把你的评论写进一个答案吗,还有为什么会有不同?