Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts

    Which is the Right way

    Hello

    which is the Right way of the two Codes.

    PHP Code:
    if (HtmlSpecialchars($_GET['op']) == "news"){ 
    or

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

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    if (isset($_GET['op']) && trim($_GET['op']) == 'news')
    {
        [code here]
    }

  • #3
    Banned
    Join Date
    Feb 2010
    Location
    New York
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    First one is right..........

    I think that first one is the right code,you can use it and show result.

    Advanced Acai

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    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.


    -----------------
    Leonard Whistler

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    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.

  • #6
    Regular Coder
    Join Date
    Aug 2009
    Posts
    215
    Thanks
    74
    Thanked 0 Times in 0 Posts
    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.

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



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •