Different Pages using PHP $_GET variable
No POST response yet
- <?php
- /**
- * Check to see if any Server POST request has been made
- */
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- echo '<div class="response"><p>You have entered your name <strong>' . $_POST['user_name'] . '</strong> via HTTP POST method</p></div>';
- }
- else {
- echo '<p>No POST response yet</p>';
- }
- ?>
Hi there, Welcome to our site.
Basic Source Codes
- /**
- * A function to stripslashes from string
- * To be used if magiccodegpc is turned on in the server
- */
- function stripslash_gpc( &$value ) {
- }
- /**
- * Check to see if magicgpc is on or not! If so then stripslase all the POST variable
- * First check if server request method is post
- * Then check if magic code gpc is turned on or not
- */
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- }
- <?php
- /**************************************************************
- * PHP Advance Technique to use POST and GET simultaneously
- * @author Swashata <swashata4u@gmail.com>
- * @license GPL2 You are free to do whatever you want
- */
- ?>
- <!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=utf-8" />
- <title>Demonstation: Using PHP GET and POST together to make Interactive Page</title>
- </head>
- <body>
- <p style="text-align: center;"><a href="?pmode=main">The Main Page</a> | <a href="?pmode=contact">Contact Page</a> | <a href="?pmode=register">Register Page</a></p>
- <?php
- /**
- * A function to stripslashes from string
- * To be used if magiccodegpc is turned on in the server
- */
- function stripslash_gpc( &$value ) {
- }
- /**
- * Check to see if magicgpc is on or not! If so then stripslase all the POST variable
- * First check if server request method is post
- * Then check if magic code gpc is turned on or not
- */
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- }
- /** Define and check the pmode from the GET URL variable */
- $pmode = $_GET['pmode'];
- if( !$pmode )
- $pmode = 'main';
- /** Now actually make the page using the pmode */
- switch( $pmode ) {
- default :
- case 'main' :
- /**
- * Check to see if any Server POST request has been made
- */
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- echo '<div class="response"><p>You have entered your name <strong>' . $_POST['user_name'] . '</strong> via HTTP POST method</p></div>';
- }
- else {
- echo '<p>No POST response yet</p>';
- }
- ?>
- <p>Hi there, Welcome to our site.</p>
- <fieldset>
- <legend>Enter your Name</legend>
- <form action="?pmode=main" method="post">
- <p>
- <label for="user_name">What is your name? » </label>
- <input type="text" name="user_name" id="user_name" value="Name please" />
- </p>
- <p>
- <input type="submit" value="Submit" />
- </p>
- </form>
- </fieldset>
- <?php
- break;
- case 'contact' :
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- ?>
- <div class="response">
- <p>Hi <a href="mailto:<?php echo $_POST['user_email_post']; ?>"><?php echo $_POST['user_name_post']; ?></a>. We have received your email.</p>
- <p>Your Email message was:</p>
- <blockquote>
- <p><strong><?php echo $_POST['user_subj_post']; ?></strong></p>
- <p><?php echo $_POST['user_text_post']; ?></p>
- </blockquote>
- </div>
- <?php
- }
- ?>
- <p>Feel Free to drop in</p>
- <fieldset>
- <legend>Contact Us</legend>
- <form action="?pmode=contact" method="post">
- <p>
- <label for="user_name_post">Your Name: »</label>
- <input type="text" name="user_name_post" id="user_name_post" value="Enter name" />
- </p>
- <p>
- <label for="user_email_post">Your Email: »</label>
- <input type="text" name="user_email_post" id="user_email_post" value="yourname@company.com" />
- </p>
- <p>
- <label for="user_subj_post">Subject: »</label>
- <input type="text" name="user_subj_post" id="user_subj_post" value="Enter Subject" />
- </p>
- <p>
- <label for="user_text_post">Message? »</label>
- <textarea name="user_text_post" id="user_text_post"></textarea>
- </p>
- <p>
- <input type="submit" value="Send" />
- </p>
- </form>
- </fieldset>
- <?php
- break;
- case 'register' :
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- ?>
- <div class="response">
- <p>Thanks for registration. Following credentials have been stored in our database.</p>
- <p>Name: <?php echo $_POST['user_name_post']; ?></p>
- <p>Age: <?php echo $_POST['user_age_post']; ?> years</p>
- <p>Sex: <?php echo $_POST['user_sex_post']; ?></p>
- <p>Email: <?php echo $_POST['user_email_post']; ?></p>
- <p>Company: <?php echo $_POST['user_company_post']; ?></p>
- <p>Message:</p>
- <blockquote>
- <p><?php echo $_POST['user_text_post']; ?></p>
- </blockquote>
- </div>
- <?php
- }
- ?>
- <p>Register to take full advantage</p>
- <fieldset>
- <legend>Register Now</legend>
- <form action="?pmode=register" method="post">
- <p>
- <label for="user_name_post">Your Name: »</label>
- <input type="text" name="user_name_post" id="user_name_post" value="Enter name" />
- </p>
- <p>
- <label for="user_age_post">Your Age: »</label>
- <input type="text" name="user_age_post" id="user_age_post" value="Age in Years" />
- </p>
- <p>
- <label for="user_sex_post">Your Sex: »</label>
- <select name="user_sex_post" id="user_sex_post">
- <option value="Male">Male</option>
- <option value="Female">Female</option>
- </select>
- </p>
- <p>
- <label for="user_email_post">Your Email: »</label>
- <input type="text" name="user_email_post" id="user_email_post" value="yourname@company.com" />
- </p>
- <p>
- <label for="user_company_post">Company: »</label>
- <input type="text" name="user_company_post" id="user_company_post" value="Company name" />
- </p>
- <p>
- <label for="user_text_post">Any Message? »</label>
- <textarea name="user_text_post" id="user_text_post"></textarea>
- </p>
- <p>
- <input type="submit" value="Register" />
- </p>
- </form>
- </fieldset>
- <?php
- }
- ?>
- </body>
- </html>
