Using Hidden Controls to Check Whether a Page Has Been Seen Before


To check whether a page has been previously viewed, the example illustrated in the previous section can work, but it might not always give you correct results. For example, checking the data in a text field to see whether the user has seen the page already may work some of the time, but in some cases it may be a valid option to leave the text field blank.

To avoid using HTML controls that the user can work with to check whether that user has already seen the page, you can use hidden controls instead, which store hidden text in a page.

For example, you can modify the example, single.php, illustrated in the previous section, into single2.php, which looks and acts just the same as single.php, but uses a hidden control to determine whether the user has seen the page before. That means that you check the hidden control, which will be named already_shown, to see whether you should display the text field:

 <html>     <head>         <title>           Putting everything in a single page         </title>     </head>     <body>         <center>           <h1>Putting everything in a single page</h1>           <?             if(isset($_REQUEST["already_shown"])){           ?>           .           .           .           ?>         </center>     </body> </html>

If you’re supposed to show the text field, you can create and add the hidden control to the same form as the text field, placing the text data in the hidden control:

 <html>     <head>         <title>           Putting everything in a single page         </title>     </head>       <body>         <center>           <h1>Putting everything in a single page</h1>           <?             if(isset($_REQUEST["already_shown"])){           ?>             Your name is           <?             echo $_REQUEST["name"];             }             else {           ?>             <form method="post" action="single.php">                 Enter your name:                   <input name="name" type="text">                 <input name="already_shown" type="hidden"                   value="data">                 <br>                 <br>                 <input type="submit" value="Submit">             </form>           <?             }           ?>         </center>     </body> </html>

This page, single2.php, works just as single.php did, but it has the advantage that the control you use to check whether the user has seen the page before is under your control, not the user’s.



Ajax Bible
Ajax Bible
ISBN: 0470102632
EAN: 2147483647
Year: 2004
Pages: 169

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net