Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, I would like to address the original question. As there are already answers for the obvious <code>isset()</code> .. I would like to point out that 1) You don't need to check for the existence of <code>$_GET</code> prior, it's just wasted code. So the examples such as:</p> <pre><code>if(isset($_GET['errormsg']) { echo $_GET['errormsg']; } </code></pre> <p>are indeed correct usage. I would like to also point out you will get PHP Notices &amp; Warnings <strong>anytime</strong> you use <code>$_GET['foo']</code> without it being initialized first. So for example, this <strong>will</strong> produce a notice: (Note: In the below examples I changed "errormssg" to "errormsg", note the removal of the double "s")</p> <pre><code>$errormsg = stripslashes(str_replace("'","",$_GET['errormsg'])); if(isset($errormsg)) { echo $errmsg; } </code></pre> <p>In fact, that code is very redundant, since unless the code changes, <code>$errmsg</code> will always be set. To use this properly, you would want to say something like:</p> <pre><code>if(isset($_GET['errormsg'])) { $errormsg = stripslashes(str_replace("'","",$_GET['errormsg'])); echo $errormsg; } </code></pre> <p>I would also like to point out the usage of <code>!empty()</code> as well. <code>!empty()</code> is different than <code>isset()</code> that can be demonstrated with the following example:</p> <pre><code>$x = ''; if(isset($x)) { echo 'This will fire, since $x *is* set, just empty'; } if(!empty($x)) { echo 'This will not fire, even though $x is set, it is empty'; } </code></pre> <p>Although for your example, it will only make unnoticeable differences more than likely.</p> <p>Secondly, although not related directly to the original question, I would like to point out your use of <code>header()</code> and URLs is highly incorrect:</p> <pre><code>header("Location:contact.php?errormssg='You seem to have forgotten one of the fields'"); </code></pre> <p>This is all wrong. You <strong>should</strong> instead use something like this:</p> <p>header("Location: contact.php?errormsg=" . urlencode("You seem to have forgotten one of the fields"));</p> <p>Note the space between Location: and the URL. Technically, this is <strong>still</strong> incorrect but will work. The 100% proper way to do it (according to the RFC) would be to include the <strong>full</strong> URL in the header, such as:</p> <pre><code>header("Location: http://www.yoursite.com/contact.php?errormsg=" . urlencode("You seem to have forgotten one of the fields")); </code></pre> <p>You will not need your <code>stripslashes()</code> if you URL escape/encode your data properly.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload