[英]PHP Login form doesn't redirect to another page
validation process works well but it won't redirect to the new "profile.php " page. 验证过程运行良好,但不会重定向到新的“ profile.php”页面。 Pls let me know where I am going wrong.
请让我知道我要去哪里了。
Here is the html form. 这是html表单。
<form name = "fomu_kuingia" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method = "POST">
<br><br> Barua pepe: <input type="text" name="baruapepe" />
<span class = "error" style = "color: #DC143C;"> <?php echo $tatizo; ?></span>
<br><br> Neno la siri: <input type="password" name="nenosiri" />
<span class = "error" style = "color: #DC143C;"> <?php echo $tatizo1; ?></span>
<br><br><input type="button" value="Nimesahau" name="nimesahau" /><input type="submit" value="Ingia " name="ingia " />
<span class = "error" style = "color: #DC143C;"> <?php //echo $jinaErr; ?></span>
</form>
here is the php function to take data (email/ passed) 这是获取数据的php函数(电子邮件/已通过)
<?php
//$pepe = " ";
// $siri = " ";
function take_data()
{ $pepe = "";
$siri = "";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
if (empty ($_POST["baruapepe"])||empty ($_POST["nenosiri"]))
{ echo "<font color = '#DC143C' > TATIZO: Tafadhali ingiza barua pepe au neno siri </font>" ; }
else { $pepe = verify($_POST["baruapepe"]);
$siri = verify($_POST["nenosiri"]);
kuingia ($pepe, $siri); }
}
}
?>
here if the function to verify data ;php function; 这里是否有验证数据的功能; php功能;
<?php
//$pepe = " ";
// $siri = " ";
function verify ($data)
{
$data = trim ($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
and fınally ıs the functıon to check logın (email,paswd) detaıls and redırect to new page . 最后,该功能将检查日志(电子邮件,密码)详细信息并重新定向到新页面。
<?php
//$pepe = " ";
// $siri = " ";
function kuingia ($pp, $sr)
{
$con = mysql_connect('localhost', 'root', 'root');
if (!$con)
{ echo "Connection was not possible ";}
else
{
mysql_select_db('DalaliOnline', mysql_connect('localhost', 'root', 'root'));
$result = mysql_query("select jina1, jina2 from watumiaji where barua_pepe = '$pp' and neno_siri = '$sr' ");
if (!$result)
{ echo "Tatizo la mysql"; }
else if (mysql_num_rows($result)== 0)
{ echo "<font color = '#DC143C' > TATIZO: Barua pepe au neno siri vimekosewa </font>" ; }
else
{ header ("Location:profile.php");
echo "umefanikiwa kuingia"; }
}
}
?>
Your header()
call is sending a relative path for the Location
header. 您的
header()
调用正在发送Location
标头的相对路径。
According to the PHP documentation for header()
, the HTTP/1.1 spec requires an absolute URL: 根据PHP文档
header()
,HTTP / 1.1规范需要一个绝对URL:
HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs.
HTTP / 1.1需要绝对URI作为»位置的参数:包括方案,主机名和绝对路径,但是某些客户端接受相对URI。 You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself
通常,您可以使用$ _SERVER ['HTTP_HOST'],$ _ SERVER ['PHP_SELF']和dirname()从您自己的亲戚那里创建绝对URI
It looks like you are also missing a space between the colon ( :
) and the content of the header. 它看起来像你还缺少冒号之间的空间(
:
)和头的内容。
Another common gotcha (although I'm not seeing it in your code above) is that you can't call header()
if you've already sent any output to the browser. 另一个常见的陷阱(尽管我在上面的代码中没有看到它)是,如果您已经将任何输出发送到浏览器,则无法调用
header()
。
The header location should be an absolute url, and there should be a space between Location:
and the url, ie; 标头位置应该是绝对网址,并且
Location:
和网址之间应该有一个空格 ,即;
header ("Location: http://yoursite.com/profile.php");
Also make sure there is nothing outputted to the browser before that header is sent. 另外,在发送该标头之前,请确保没有任何内容输出到浏览器。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.