"Beauford.2005" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Yes, I'm still screwing around with this stupid redirection thing, and
> either I'm just a total idiot or there are some serious problems with
> PHP. I have now tried to do it another way and - yes - you guessed it.
> It does not work.
>
> I mean really, it can not be this hard to redirect a user to another
> page. If it is, then I must look into using something else as I just
> can't be wasting days and days on one minor detail that should take 30
> seconds to complete.
>
> If anyone has some concrete suggestion on how to get this to work It
> would be greatly appreciated. In the mean time I have given up on it as
> I am just totally pissed off at it.
>
> TIA

Beauford, here's a login routine that I wrote using Sessions and Header
redirects.  It is my interpretation of what you are trying to do.  I'm not
saying this is the only way to do it but it works well for me.  Compare it
to what you're doing to see if you're doing anything wrong.

page-whatever.php
<? // <-- line 1
session_start();
$thispage = "http://www.yourdomain.com".$_SERVER['REQUEST_URI'];
$_SESSION['return-to'] = $thispage;
if($_SESSION['valid_user'] !== true)
{
    // Access Denied!  Redirect to the login screen.
    header("Location: http://www.yourdomain.com/login.php";);
    exit;
}

// Access Granted!  Display secure content.
?>

Hello World!<br>
<a  href="login.php?logout=true">Click here to logout</a>
-----------------------------------------------------------------

login.php
<? // <-- line 1
session_start();

// Honor logout request and destroy the session..
if(isset($_GET['logout']))
{
    foreach($_SESSION as $key => $val)
    {
        $_SESSION[$key] = '';
    }

    echo "You have logged out succesfully.";
    // Continue to the login form..
}

// Validate form input if submitted..
if(isset($_POST['submit']))
{
    if(valid_user($_POST['username'], $_POST['password']))
    {
        // Access Granted!  Redirect to the page that brought us here.
        $_SESSION['valid_user'] = true;
        header("Location: ". $_SESSION['return-to']);
        exit;
    }
    else
    {
        echo "Invalid Username/Password.";
    }
}

// Function to validate username/password..
function valid_user($un, $pw)
{
    // Open database/userfile.
    // Check submited input against content
    // Return true or false based on result.
}

// Display the login form.
?>
<form method="post" action="<?= $_SERVER['PHP_SELF']?>">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit" value="Login">
</form>
----------------------------------------------------------------------

Good luck,
Kevin



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to