Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/14691-fetching-a-website/
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.
Link to comment
https://forums.phpfreaks.com/topic/14691-fetching-a-website/#findComment-58597
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.