Jump to content

How to rewrite this ( if and if )


manalnor

Recommended Posts

hello friends,

 

that would help me alot , if i've 2 code all are of if and else

 

code 1

 

 

$r = $_SERVER['HTTP_REFERER'];if (stripos($r, $refere) !== false) {echo "good";}else{echo "bad";}

 

 

code 2

 

 

if($line[hits] >= $limited){echo "bad";}else{echo "good";}

 

 

both are 2 codes where the user should pass before it show good

 

how then it be 1 code not 2 ( if x  if y else y2 else x2 )

it like double sandwich

Link to comment
Share on other sites

 

if (stripos($r, $refere) !== false) {

 

 

Careful with the use of !== this can produce unexpected results... It's a lot easier to use != unless your certain that the evaluated items are of the same type (int, char, string, object)

 

Other than that, not sure what your trying to achieve.

 

From abracadaver's suggestion:-

 

if ((stripos($r, $refere) === false) || ($line['hits'] >= $limited)) {

 

 

Just parenthesize the evaluated parts of either side of the conditional || just because it's easier to read..

 

Rw

Link to comment
Share on other sites

 

if (stripos($r, $refere) !== false) {

 

 

Careful with the use of !== this can produce unexpected results... It's a lot easier to use != unless your certain that the evaluated items are of the same type (int, char, string, object)

 

Other than that, not sure what your trying to achieve.

 

Rw

 

 

The intent is to see if a string is found in another string by returning the position of the match or false if no match.  If the string is found in the other string at position 0 then using 0 != false will evaluate to false, whereas 0 !== false evaluates to true.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.