我在php中寻找html的用法,我看到了一个方法,我们可以像这样使用它:echo '<a href="url">text</a>'
我做的是:
$redirect = 'Redirecting to login page in 5 seconds. If it does not work, <a href="localhost:51631/login.aspx">click here</a> to do it manually.';
echo 'Account could not be verified. ' . $redirect;
当我从localhost打开文件时,输出如下所示:
到目前为止,我已经尝试了很多东西,包括分离php标签,将DOCTYPE html放在文件的顶部,打印功能等等。但无论如何,输出看起来像这样。有什么建议?这是我的php文件的完整代码。
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
$token = $_GET["key"];
$redirect = 'Redirecting to login page in 5 seconds. If it does not work, <a href="localhost:51631/login.aspx">click here</a> to do it manually.';
if(isset($_GET["key"]) && $token !== "")
{
$unique_id = $db->getUniqueIdFromToken($token);
if(is_null($unique_id))
echo 'Key not found.' . $redirect;
else
{
$verify = $db->verifyAccount($unique_id);
if($verify)
echo 'Account is successfully verified. ' . $redirect;
else
echo 'Account could not be verified. ' . $redirect;
}
}
else
echo 'Key is missing.' . $redirect;
?>
解决方案编辑:Progman建议检查标题,所以我应用了他的建议并且出来了:
array (size=2)
0 => string 'X-Powered-By: PHP/5.5.12' (length=24)
1 => string 'Content-type:application/json;charset=utf-8' (length=43)
string 'BREAK' (length=5)
array (size=1)
'X-Powered-By' => string 'PHP/5.5.12' (length=10)
在我看到json标头之后,我将其命名为JSONHeader并从原始.php文件中删除了标头,因为标头也自动包含在“require_once”注释中,文件是破坏html输出的。谢谢@Progman向我展示错误。
答案 0 :(得分:0)
尝试这样做,<a href = "login.aspx">
而不是在anchor标记中传递localhost,并将login.aspx文件放在此PHP代码文件所在的同一目录中。祝你好运!
答案 1 :(得分:0)
您正在发送JSON内容类型标头,解决方案只是将内容类型标头设置为text / html。
这是一个修复:
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
$token = $_GET["key"];
header('Content-Type: text/html; charset=utf-8');
$redirect = 'Redirecting to login page in 5 seconds. If it does not work, <a href="localhost:51631/login.aspx">click here</a> to do it manually.';
if(isset($_GET["key"]) && $token !== "")
{
$unique_id = $db->getUniqueIdFromToken($token);
if(is_null($unique_id))
echo 'Key not found.' . $redirect;
else
{
$verify = $db->verifyAccount($unique_id);
if($verify)
echo 'Account is successfully verified. ' . $redirect;
else
echo 'Account could not be verified. ' . $redirect;
}
}
else
echo 'Key is missing.' . $redirect;
?>