Professional Web Applications Themes

Redirection Problem - PHP Programming

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_exists('goal', $_GET)) { $goal = $_GET['goal']; } if (isset($HTTP_POST_VARS['userid']) && isset($HTTP_POST_VARS['password'])) { $userid = $HTTP_POST_VARS['userid']; $password ...

  1. #1

    Default 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_exists('goal', $_GET)) { $goal = $_GET['goal']; }

    if (isset($HTTP_POST_VARS['userid']) && isset($HTTP_POST_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($query, $db_conn);
    if (mysql_num_rows($result) > 0) {
    $HTTP_SESSION_VARS['valid_user'] = $userid;
    }
    }
    ?>
    <?
    if (isset($HTTP_SESSION_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><form method="post" action="authmain.php">';
    echo '<table>';
    echo '<tr><td>Userid:</td><td><input type="text" name="userid"></td></tr>';
    echo '<tr><td>Password:</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>';
    }
    ?>



    Topspin Guest

  2. #2

    Default Re: Redirection Problem

    Topspin wrote:
    > 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...
    Hi Topspin,

    just set the http-location-header like so:

    header("location: $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


    Frank Guest

  3. #3

    Default Re: Redirection Problem

    Topspin wrote:
    > 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.
    Upon finding out that they're not valid:

    header("Location: http://www.getouttahere.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
    [email]shawnglassgiant.com[/email]
    [url]http://www.glassgiant.com[/url]


    Shawn Wilson Guest

  4. #4

    Default Redirection problem

    Hi there, I am new to contribute. I have set up a new index page for my website
    however it is still redirecting to an old page that was filling a gap while the
    new page was being built. Unfortunately the page it redircts to was not made by
    us and is under a domain owned by someone else. What setting do I need to
    change in order to stop the automatic redirection?
    Cheers.

    kirsto Guest

  5. #5

    Default Re: Redirection problem

    Hello everyone....

    I am new to here. I think this is right place for learning about the PHP. Thanks
    sharonbaker is offline Junior Member
    Join Date
    Feb 2011
    Posts
    1

Similar Threads

  1. ASP redirection
    By Ianmundy in forum Dreamweaver AppDev
    Replies: 2
    Last Post: February 20th, 03:28 AM
  2. Passport Redirection Problem.
    By Munna in forum ASP.NET Security
    Replies: 2
    Last Post: July 14th, 10:06 AM
  3. Redirection Help Please
    By RX in forum PHP Development
    Replies: 3
    Last Post: February 22nd, 09:46 AM
  4. header() redirection/session variable problem
    By Nick Whitelegg in forum PHP Development
    Replies: 1
    Last Post: September 17th, 07:39 PM
  5. Problem with redirection in a Form...
    By Calvin in forum ASP
    Replies: 2
    Last Post: July 15th, 01:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139