{"id":148,"date":"2011-12-24T15:12:08","date_gmt":"2011-12-24T15:12:08","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=148"},"modified":"2026-04-03T11:58:01","modified_gmt":"2026-04-03T10:58:01","slug":"getting-url-arguments","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/page-control\/getting-url-arguments","title":{"rendered":"Getting URL Arguments"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Get an argument<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">GET only using $_GET<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyArgument = $_GET&#91;'MyArgument'] ?? '';\n\n  $MyArgument = \"\";\n  if (isset($_GET&#91;'MyArgument']))\n    $MyArgument = $_GET&#91;'MyArgument'];\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">POST only using $POST<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyArgument = $_POST&#91;'MyArgument'] ?? '';\n\n  $MyArgument = \"\";\n  if (isset($_POST&#91;'MyArgument']))\n    $MyArgument = $_POST&#91;'MyArgument'];<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">GET or POST using $_REQUEST<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyArgument = \"\";\n  if (isset($_REQUEST&#91;'MyArgument']))\n    $MyArgument = $_REQUEST&#91;'MyArgument'];\n  if (isset($_POST&#91;'MyArgument']))\n    $MyArgument = $_POST&#91;'MyArgument'];<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Did GET or POST occur<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>if ($_SERVER&#91;\"REQUEST_METHOD\"] === \"POST\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Example GET URL<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;www.somedomain.com\/somedir\/somepage.php?name_a=value_a&amp;name_b=value_b&amp;name_c=value_c<\/code><\/pre>\n\n\n\n<p>Start with an &#8216;?&#8217;,&nbsp;then separate other values with an &#8216;&amp;&#8217; <\/p>\n\n\n\n<p>To read: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyArgument = \"\";\n  if (isset($_REQUEST&#91;'MyArgument']))\n    $MyArgument = $_REQUEST&#91;'MyArgument'];\n\n   if (!empty($_REQUEST&#91;'redirect_to']))    \/\/Note that a value of zero will cause empty() to be true!!!!!!!\n\n   if (isset($_REQUEST&#91;'source']))    \/\/A value of zero will still give isset() being true so this is often the better choice then empty() \n\n   echo $_REQUEST&#91;'name_a'] . \"&lt;br\/>\";\n   echo $_REQUEST&#91;'name_b'] . \"&lt;br\/>\";\n   echo $_REQUEST&#91;'name_c'] . \"&lt;br\/>\";\n\n   $name_a= $_REQUEST&#91;'name_a'];\n\n\n  if (isset($_REQUEST&#91;'submitted']) &amp;&amp; $_REQUEST&#91;'submitted'] == 'yes'))\n\n  if (isset($_REQUEST&#91;'image_upload_filename']))\n\n  if (isset($_REQUEST&#91;'image_upload_filename'])) &amp;&amp; $_REQUEST&#91;'image_upload_filename']  == 'abc')\n\n  $arg1 = 0;\n  if ($_REQUEST&#91;'arg1'])\t\t\/\/&lt;&lt;Remember this will be false if the value is 0!\n    $arg1 = (int)$_REQUEST&#91;'arg1'];<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Example For POST Parameters <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>   echo $_POST&#91;'name_a'] . \"&lt;br\/&gt;\";\n   echo $_POST&#91;'name_b'] . \"&lt;br\/&gt;\";\n   echo $_POST&#91;'name_c'] . \"&lt;br\/&gt;\";\n\n   $name_a= $_POST&#91;'name_a'];\n\n\n  if (isset($_POST&#91;'submitted']) &amp;&amp; $_POST&#91;'submitted'] == 'yes')\n\n  if(isset($_POST&#91;'image_upload_filename']))\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Sanitise Them!!! <\/h4>\n\n\n\n<p>htmlentities() converts things like &lt; &gt; \u201d \\ etc into HTML strings like &lt; so they become harmless. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     echo htmlentities($_REQUEST&#91;'name_a']) . \"&lt;br\/&gt;\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">POST OR GET <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  $group_id = mysql_real_escape_string($_GET&#91;'gid']);\n  if($group_id == \"\")\n    $group_id = mysql_real_escape_string($_POST&#91;'gid']);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Debug Show All Posted Values <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/----- DISPLAY ALL POSTED VALUES -----\necho\"&#91;POSTED VALUES START]&lt;br \/&gt;\";\nforeach($_POST as $posted_var =&gt; $posted_value)\n\techo $posted_var . ' : ' . $posted_value . \"&lt;br&gt;\";\necho\"&#91;POSTED VALUES END]&lt;br \/&gt;\";<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Is A Form Value Present <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\tif ($_POST&#91;'delete_user'])<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Getting Form Values <\/h4>\n\n\n\n<p>Each form item with a name will be posted. <\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Multiple Images As Submit Buttons <\/h5>\n\n\n\n<p>This example witth POST &#8216;delete_user&#8217; if the button is pressed but not if it isn&#8217;t <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;input type=\"image\" src=\"\/button_delete.png\" alt=\"Delete\" value=\"Delete\" name=\"delete_user\" onClick=\"return(window.confirm('&#91;var.confirm_popup_javascript]'))\" \/&gt;\n\n  \/\/This is the PHP test for was the button pressed\n  if ($_POST&#91;'delete_user_x'])<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Getting Arguments From A URL String <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>\t$url = \"http:\/\/www.mydomain.com\/watch?v=fdagikhfdaq&amp;res=45\";\n\tparse_str(parse_url( $url, PHP_URL_QUERY ), $array_of_vars);\n\techo $array_of_vars&#91;'v'];    \n  \/\/Outputs: fdagikhfdaq<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Storing A Value In A Page Using POST <\/h4>\n\n\n\n<p>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 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\t$_POST&#91;\"player_video_id\"] = $player_video_id;\n\t$video_index = (int)$_POST&#91;'player_video_id'];<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Get an argument GET only using $_GET POST only using $POST GET or POST using $_REQUEST Did GET or POST occur Example GET URL Start with an &#8216;?&#8217;,&nbsp;then separate other values with an &#8216;&amp;&#8217; To read: Example For POST Parameters Sanitise Them!!! htmlentities() converts things like &lt; &gt; \u201d \\ etc into HTML strings like [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,56],"tags":[],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-page-control","category-urls"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":37,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":5340,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/148\/revisions\/5340"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}