php - How would I use the header command in the Cloud 9 IDE to redirect someone after their forms are validated? -
i using cloud 9 ide , had created registration page redirect user once submit registration credentials. trying using header method in php. however, don't know if can use or have work around due url provide website. example, url be, "https://example-user.c9users.io/register.php" , header trying use is:
header("location:https://vomica-porixify.c9users.io/home.php");
the main problem won't work , can't figure out why. don't know if due links given or if registration page broken.
here register.php
<?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' ?>
and here redirect.php
<?php $pagetitle = "redirected"; ?> <?php include 'inc/header.php' ?> <?php if(isset($_get['submit'])) { // fetches variables form $username = $_get['inputuser']; $email = $_get['inputemail']; $password = $_get['inputpassword']; if(inputuser !='' && inputemail !='' && inputpassword !='') { // redirects page header("location:https://vomica-porixify.c9users.io/home.php"); } else { ?> <div class="alert alert-danger" role="alert"> <?php echo 'please fill out fields!'; ?> </div> <?php } } ?> <?php include 'inc/footer.php' ?>
when use header() should remember that:
header() must called before actual output sent, either normal html tags, blank lines in file, or php. common error read code include, or require, functions, or file access function, , have spaces or empty lines output before header() called. same problem exists when using single php/html file.
in code, when submit form, there post request call process.php file, can write register code here , user header() redirect:
//process.php // register code ... // redirect header("location: http://www.example.com/home"); // make sure code below not executed when redirect. exit;
Comments
Post a Comment