Jump to content

Archived

This topic is now archived and is closed to further replies.

daughn888

fetching a website

Recommended Posts

I need to know a command that will display one of my site's web pages if a certain form value equals a certain value.

For instance, in a form validating program/quiz I am writing, I have the a "wrong answer" prompt displayed on screen if the user gets the wrong answer...

-----------------------------------------
$question1 = $_POST['q1'];

if ($question1 != "results") {
echo "sorry, wrong answer. Please hit your browser's back button and try again. ";
}

------------------------------------------
but if the user types in the correct answer, I would like the php script to automatically display in the same window another of my html pages.  What command would I use to automatically pull up another html page?

Any help would be appreciated.

Thanks

Share this post


Link to post
Share on other sites
Couldn't you just use include("page.php"); or redirect them to page.php with header("location: page.php"); (but remember rules for sending headers so you don't get errors).

Or, use this function for redirecting:
<?php
DEFINE("X_REDIRECT_HEADER", 1);
DEFINE("X_REDIRECT_JS", 2);
function redirect($path, $timeout=2, $type=X_REDIRECT_HEADER) {

    // split session attack code fix
    if (strpos(urldecode($path), "\n") !== false || strpos(urldecode($path), "\r") !== false)
    {
        error('Tried to redirect to potentially insecure url.');
    }

    // force session to be written before redirecting
    session_write_close();

    $type = (headers_sent() || $type == X_REDIRECT_JS ) ? X_REDIRECT_JS : X_REDIRECT_HEADER;
    if ($type == X_REDIRECT_JS) {
        ?>
        <script language="javascript" type="text/javascript">
        function redirect() {
            window.location.replace("<?php echo $path?>");
        }

        setTimeout("redirect();", <?php echo ($timeout*1000)?>);
        </script>

        <?php
    } else {
        if ( $timeout == 0) {
            header("Location: $path");
        } else {
            header("Refresh: $timeout; URL=./$path");
        }
    }
    return true;
}
?>

And then, when you want to redirect do something like:
redirect("page.php", 0);
0 is the time, so adjust it higher if you want it to linger one the results page before redirecting.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.