[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Can someone help me understand this syntax


Just a quick one, can anyone help me understand these few lines..

if ((!isset($_GET["cPath"]) or $_GET["cPath"]=="") && (!isset($_GET["keywords"])))
header("Location: home page ");

(I've put in home page)


  • 2
1 Solution
Pratima PharandeCommented:
if ((!isset($_GET["cPath"]) or $_GET["cPath"]=="") && (!isset($_GET["keywords"])))

isset($_GET["cPath"])   == whethere the Field present in Get method

then OR means

$_GET["cPath"]==""   if present then is it null ?

If both are True the

AND  that is &&
isset($_GET["keywords"]) whethere the Field present in Get method

Logically it means:

If the variable cPath is empty and the variable keywords is also empty then redirect the user to the home page
Here is a lesson:

1.  An exclamation point ! means NOT.
2. $_GET is a method used by a form.  The alternative is $_POST.  These are used in a form such as <form name="form1" action="" method="get">
3. == means equals.
4. double quotes "" means empty string
5. && means AND
6. isset means is set as in ... the variable keywords is set to monkey blood

So, if you place an exclamation point in front of isset then !isset would mean: not set or also known as an empty string.  The first part of your code means the same thing which is not necessary to have both:  

((!isset($_GET["cPath"]) means the same things as
 $_GET["cPath"]=="") because !isset (variable not set) means the same thing as "" (variable equals and empty string)

chriscounter07Author Commented:
and a fine lesson that is.  Extremely helpful.


Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now