2013-04-30 95 views
0

我看着通过stackoverflow,但我只能找到SQL的东西。如何设置通用密码和用户名持有者,以便在php中检查它,然后重定向到另一个页面?例如,如果帖子包含用户名部分的“用户名”和密码部分的“密码”,则当点击提交按钮时,它将重定向到标题中的页面。重定向与简单的PHP和后

<form action="" method="post"> 
    Username:<input type="text" name="username" placeholder="Username" maxlength = "15"/> 
    Password: <input type="password" name="password" placeholder="Password" maxlength = "15"/> 
    <input type='image' alt='Submit' src='button.jpg' width='15%'/> 
</form>` 

if ($_POST["username"] == "Username" && $_POST['password']=="Password") 
{ 
header("thesite"); 
} 
+0

...'header('Location:some/page.php')'? – Ryan 2013-04-30 23:50:50

回答

0

你的代码看起来不错。它只是缺少在头

<?php 

if($_POST['username'] == 'Username' && $_POST['password'] == 'Password') 
    header('Location: thesite.url'); 

?> 
+0

谢谢,在阅读标题时我没有看到“位置:”。 – 2013-05-01 00:04:33

0

重定向的Location:在HTTP存在Location头。您错过了输入标题Location:的名称。将该行更改为:

header("Location: http://thesite.com/..."); 
+1

谢谢修复它。我不知道位置标记,现在我看到它在php.net上。 – 2013-05-01 00:03:54