Redirection Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Topspin

    Redirection Problem

    I'm running PHP on Windows, but that's just the local test... in production
    it will be on Apache.

    I am not using PHP as a CGI. I want to perform redirection of the user's
    browser if the user isn't a valid user. I don't want to use the refresh
    meta tag or javascript to do this. I want to do this with some sort of
    server command.

    Does anyone know how to make this work? Here's my code...
    <?php
    session_start() ;
    $goal = "";
    if (array_key_exis ts('goal', $_GET)) { $goal = $_GET['goal']; }

    if (isset($HTTP_PO ST_VARS['userid']) && isset($HTTP_POS T_VARS['password']))
    {
    $userid = $HTTP_POST_VARS['userid'];
    $password = $HTTP_POST_VARS['password'];
    $db_conn = mysql_connect(' localhost', 'webauth', 'webauth');
    mysql_select_db ('auth', $db_conn);
    $query = "select * from auth where name='$userid' and
    pass=password(' $password')";
    $result = mysql_query($qu ery, $db_conn);
    if (mysql_num_rows ($result) > 0) {
    $HTTP_SESSION_V ARS['valid_user'] = $userid;
    }
    }
    ?>
    <?
    if (isset($HTTP_SE SSION_VARS['valid_user'])) {
    // redirection code goes here. Re-direct to value current to the value of
    $goal which is a html file in the current directory http directory

    } else {
    if (isset($userid) ) {
    echo 'Could not log you in';
    } else {
    echo 'You are not logged in <br/>';
    }

    echo '<html><body><f orm method="post" action="authmai n.php">';
    echo '<table>';
    echo '<tr><td>Userid :</td><td><input type="text" name="userid"></td></tr>';
    echo '<tr><td>Passwo rd:</td><td><input type="password"
    name="password" ></td></tr>';
    echo '<tr><td colspan="2" align="center"> <input type="submit" value="Log
    In"></td></tr>';
    echo '</table></form></body></html>';
    }
    ?>



  • Frank

    #2
    Re: Redirection Problem

    Topspin wrote:
    [color=blue]
    > I'm running PHP on Windows, but that's just the local test... in
    > production it will be on Apache.
    >
    > I am not using PHP as a CGI. I want to perform redirection of the user's
    > browser if the user isn't a valid user. I don't want to use the refresh
    > meta tag or javascript to do this. I want to do this with some sort of
    > server command.
    >
    > Does anyone know how to make this work? Here's my code...[/color]
    Hi Topspin,

    just set the http-location-header like so:

    header("locatio n: $newurl");

    The users browser should then load this new URL.
    Make sure -as usual with the call to header- that your script
    did not write anything out prior to the function call.
    A simple blank somewhere in an included file is sufficient to let your
    call fail.

    Cheers
    Frank


    Comment

    • Shawn Wilson

      #3
      Re: Redirection Problem

      Topspin wrote:
      [color=blue]
      > I am not using PHP as a CGI. I want to perform redirection of the user's
      > browser if the user isn't a valid user. I don't want to use the refresh
      > meta tag or javascript to do this. I want to do this with some sort of
      > server command.[/color]

      Upon finding out that they're not valid:

      header("Locatio n: http://www.getouttaher e.com");

      Make sure you write this BEFORE your script produces any output. Even a single
      space will cause you grief. Also, be sure to use an absolute URL. Relative
      URLs will work in some newer browsers, but cause trouble in others.

      Shawn
      --
      Shawn Wilson
      shawn@glassgian t.com



      Comment

      Working...