...

View Full Version : Which is the Right way



ajloun
02-23-2010, 05:37 AM
Hello

which is the Right way of the two Codes.


if (HtmlSpecialchars($_GET['op']) == "news"){

or


if(isset($_GET['op']) == 'news' ? htmlspecialchars($_GET['op']) == 'news' : (isset($_GET['op']) == 'news' ? htmlspecialchars($_GET['op']) == 'news' : '')){

MattF
02-23-2010, 06:03 AM
if (isset($_GET['op']) && trim($_GET['op']) == 'news')
{
[code here]
}

bidipetson
02-23-2010, 06:03 AM
I think that first one is the right code,you can use it and show result.

Advanced Acai (http://www.articlesbase.com/health-articles/advanced-acai-review-does-advanced-acai-really-work-1778693.html)

Len Whistler
02-23-2010, 06:18 AM
I'm going to take an educated guess and say your 2nd example is the correct way, because it looks like you have a default value for $_GET['op'] in case it's not set.

If a variable has no value you get those undefined errors with PHP 5.3 I think. I'm not 100% sure on this though.


-----------------

MattF
02-23-2010, 06:26 AM
It depends what he's doing with the GET var. If that if clause is the only place it's used, there's no need to set a default value. If he's using its value in code later on, then checking and setting is required.

ajloun
02-23-2010, 06:31 AM
The Get is to load a Post Form . I belive my way right but if we Need More Security i think the right way is MATTF way.


if (isset($_GET['op']) && trim($_GET['op']) == 'news')
{
[code here]
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum