php - Redirect not working with header("Location: -


i've searched can't seem figure 1 out. have config.php searches active session , if found passes user through, if not fowards login.php page. config.php grabs orginal url , posts login.php can redirect them page going originally.

from there should pretty simple, authenticate , use redirect variable forward browser original page. it's not working that. forwards me login.php , says "object moved". redirects if put header("location: /index.php"); not if use variable in login.php below.

any appreciated!

php (config.php):

<?php session_start(); // put somewhere in config file define('session_expire',3600); // in seconds  // check passage of time, force log-out session expire time if(isset($_session['last_activity']) && (time() - strtotime($_session['last_activity']) >     session_expire)) { // destroy session session_unset(); session_destroy(); }  // if user logged in , unexpired, update activity if(isset($_session['user'])) { // user logged in $_session['last_activity'] = date('y-m-d h:i:s'); }  // if user doesn't have session forward them login page , post requested url if (!(isset($_session['user']) && $_session['user'] != '')) { header ("location: ../login.php?location=" . urlencode($_server['request_uri'])); } ?> 

php (login.php):

<?php include("authenticate.php");  // check see if user logging out if(isset($_get['out'])) { // destroy session session_unset(); $_session = array(); unset($_session['user'],$_session['access']); session_destroy(); } // orginal url config.php $url = $_get['location'];  // check see if login form has been submitted if(isset($_post['userlogin'])){ // run information through authenticator if(authenticate($_post['userlogin'],$_post['userpassword'])) {     // authentication passed     header("location:".$url);     die(); } else {     // authentication failed     $error = 1; } }   // output logout success if (isset($_get['out'])) echo "logout successful"; ?> 

html:

<div class="panel-body">     <form action="login.php" method="post">          <fieldset>              <div class="form-group">                 <input class="form-control" placeholder="username" name="userlogin" type="username" autofocus>              </div>              <div class="form-group">                 <input class="form-control" placeholder="password" name="userpassword" type="password" value="">              </div>       <!-- change button or input when using form -->                 <input class="btn btn-lg btn-success btn-block" type="submit" name="submit" value="login" />        </fieldset>     </form>  </div> 

you need remove login.php here: action="login.php" you're losing $url variable because it's not being included in after page posts itself.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -