Php 我如何在Cloud9IDE中使用header命令在表单验证后重定向某人?
我正在使用Cloud 9 IDE,我已经创建了注册页面,希望在用户提交注册凭据后重定向用户。我正试图通过使用PHP中的header方法来实现这一点。但是,我不知道我是否可以使用它,或者我是否需要解决它,因为他们为您的网站提供了URL。例如,URL应该是“”,我尝试使用的标题是: 标题(“位置:”) 主要问题是它不起作用,我不知道为什么。我不知道这是因为你的链接,还是我的注册页面被破坏了 这里是register.phpPhp 我如何在Cloud9IDE中使用header命令在表单验证后重定向某人?,php,forms,redirect,cloud9-ide,Php,Forms,Redirect,Cloud9 Ide,我正在使用Cloud 9 IDE,我已经创建了注册页面,希望在用户提交注册凭据后重定向用户。我正试图通过使用PHP中的header方法来实现这一点。但是,我不知道我是否可以使用它,或者我是否需要解决它,因为他们为您的网站提供了URL。例如,URL应该是“”,我尝试使用的标题是: 标题(“位置:”) 主要问题是它不起作用,我不知道为什么。我不知道这是因为你的链接,还是我的注册页面被破坏了 这里是register.php <?php $pageTitle = "Sign Up";
<?php
$pageTitle = "Sign Up";
$section = "signing";
?>
<?php include 'INC/header.php'; ?>
<div class="row">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-body">
<div class="page-header">
<h3 class="text-center"> Register </h3>
</div>
<form class="form-horizontal" role="form" acion="process.php" method="post">
<div class="form-group">
<label for="inputUser" class="col-sm-2 control-label"> Username </label>
<div class="col-sm-10">
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-user"> </span>
</span>
<input type="text" class="form-control" id="inputUser" placeholder="Username">
</div>
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-sm-2 control-label"> E-Mail </label>
<div class="col-sm-10">
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-envelope"> </span>
</span>
<input type="email" class="form-control" id="inputEmail" placeholder="E-Mail">
</div>
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label"> Password </label>
<div class="col-sm-10">
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-star"> </span>
</span>
<input type="password" class="form-control" id="inputPassword" placeholder="Password">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary"> Register </button>
<button type="button" class="btn btn-info"> User Login </button>
</div>
</div>
<?php include 'INC/redirect.php' ?>
</form>
</div>
</div>
</div>
<div class="col-md-2"></div>
</div>
<?php include 'INC/footer.php' ?>
登记
用户名
电子邮件
密码
登记
用户登录
这是我的redirect.php
<?php $pageTitle = "Redirected"; ?>
<?php include 'INC/header.php' ?>
<?php
if(isset($_GET['submit'])) {
// Fetches variables from the form
$username = $_GET['inputUser'];
$email = $_GET['inputEmail'];
$password = $_GET['inputPassword'];
if(inputUser !='' && inputEmail !='' && inputPassword !='')
{
// Redirects to the page
header("Location:https://vomica-porixify.c9users.io/home.php");
} else {
?> <div class="alert alert-danger" role="alert"> <?php echo 'Please fill out all the fields!'; ?> </div> <?php
}
}
?>
<?php include 'INC/footer.php' ?>
使用header()时,应记住:
在发送任何实际输出之前,必须调用header(),可以通过普通HTML标记、文件中的空行,也可以通过PHP。使用include或require函数或其他文件访问函数读取代码,并在调用header()之前输出空格或空行,这是非常常见的错误。使用单个PHP/HTML文件时也存在同样的问题
在您的代码中,当您提交表单时,会有一个post请求来调用您的process.php文件,您可以在此处编写一些注册代码,并使用user header()重定向:
//process.php
// Register code
...
// Redirect
header("Location: http://www.example.com/home");
// Make sure that code below does not get executed when we redirect.
exit;
很抱歉,我无意中包含了两次相同的文件,让我尽快修复!