1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Load another page on refresh

Discussion in 'HTML & JavaScript' started by jericko, Nov 25, 2008.

  1. jericko

    jericko Newbie

    Joined:
    Nov 15, 2008
    Messages:
    6
    Likes Received:
    0
    I saw on a site a while ago, their index page first shows their registration form, but if you refresh that page, the index appears instead.

    How is it possible to do that?
     
  2. drdankmendez

    drdankmendez Junior Member

    Joined:
    May 30, 2008
    Messages:
    194
    Likes Received:
    316
    Location:
    In front of my computer
    This can be done with PHP and sessions. Pretty much what the example below shows is when the page is loaded php initializes a session, then checks to see if the "second_view" session variable has been set to "yes". If it has been set then it will show the code for the index page. If the "second_view" variable is not set then it sets the "second_view" variable to "yes" and displays the registration form.

    Create index.php and insert the following code:

    Code:
    <?php
    session_start();
    
    if (isset($_SESSION['second_view']) && $_SESSION['second_view'] == 'yes'){
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Index Page</title>
    </head>
    <body>
    	<div>Your index page would go here</div>
    </body>
    </html>
    <?php
    } else {
    	$_SESSION['second_view'] = 'yes';
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Registration Form</title>
    </head>
    <body>
    	<form action="formpost.php" method="post" enctype="multipart/form-data" >
    		<input type="text" name="input1" />
    		<br />
    		<input type="text" name="input1" />
    		<input type="submit" />
    	</form>		
    </body>
    </html>
    <?php
    }
    ?>