Get an argument

  $MyVariable = "";
  if (isset($_REQUEST['MyVariable']))
    $MyVariable = $_REQUEST['MyVariable'];
  $MyVariable = "";
  if (isset($_POST['MyVariable']))
    $MyVariable = $_POST['MyVariable'];
  $MyVariable = "";
  if (isset($_REQUEST['MyVariable']))
    $MyVariable = $_REQUEST['MyVariable'];
  if (isset($_POST['MyVariable']))
    $MyVariable = $_POST['MyVariable'];

Example GET URL

Start with an ‘?’, then separate other values with an ‘&’

To read:

  $MyVariable = "";
  if (isset($_REQUEST['my_variable']))
    $MyVariable = $_REQUEST['my_variable'];

   if (!empty($_REQUEST['redirect_to']))    //Note that a value of zero will cause empty() to be true!!!!!!!

   if (isset($_REQUEST['source']))    //A value of zero will still give isset() being true so this is often the better choice then empty() 

   echo $_REQUEST['name_a'] . "<br/>";
   echo $_REQUEST['name_b'] . "<br/>";
   echo $_REQUEST['name_c'] . "<br/>";

   $name_a= $_REQUEST['name_a'];

  if (isset($_REQUEST['submitted']) && $_REQUEST['submitted'] == 'yes'))

  if (isset($_REQUEST['image_upload_filename']))

  if (isset($_REQUEST['image_upload_filename'])) && $_REQUEST['image_upload_filename']  == 'abc')

  $arg1 = 0;
  if ($_REQUEST['arg1'])		//<<Remember this will be false if the value is 0!
    $arg1 = (int)$_REQUEST['arg1'];

Example For POST Parameters

   echo $_POST['name_a'] . "<br/>";
   echo $_POST['name_b'] . "<br/>";
   echo $_POST['name_c'] . "<br/>";

   $name_a= $_POST['name_a'];

  if (isset($_POST['submitted']) && $_POST['submitted'] == 'yes')


Sanitise Them!!!

htmlentities() converts things like < > ” \ etc into HTML strings like < so they become harmless.

     echo htmlentities($_REQUEST['name_a']) . "<br/>";


  $group_id = mysql_real_escape_string($_GET['gid']);
  if($group_id == "")
    $group_id = mysql_real_escape_string($_POST['gid']);

Debug Show All Posted Values

echo"[POSTED VALUES START]<br />";
foreach($_POST as $posted_var => $posted_value)
	echo $posted_var . ' : ' . $posted_value . "<br>";
echo"[POSTED VALUES END]<br />";

Is A Form Value Present

	if ($_POST['delete_user'])

Getting Form Values

Each form item with a name will be posted.

Multiple Images As Submit Buttons

This example witth POST ‘delete_user’ if the button is pressed but not if it isn’t

  <input type="image" src="/button_delete.png" alt="Delete" value="Delete" name="delete_user" onClick="return(window.confirm('[var.confirm_popup_javascript]'))" />

  //This is the PHP test for was the button pressed
  if ($_POST['delete_user_x'])

Getting Arguments From A URL String

	$url = "";
	parse_str(parse_url( $url, PHP_URL_QUERY ), $array_of_vars);
	echo $array_of_vars['v'];    
  //Outputs: fdagikhfdaq

Storing A Value In A Page Using POST

This can be a way of overwriting an existing POST value or passing a value to another php file which will get used as a script include later for an example

	$_POST["player_video_id"] = $player_video_id;
	$video_index = (int)$_POST['player_video_id'];
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.