Very simple but daunting PHP problem I can't figure out

Discussion in 'PHP' started by Grimmfang, Apr 17, 2012.

  1. #1
    This line of code is enabling a feature on my site which is good for the most part. What I need to do is display this string on index.php and news.php BUT not on url extensions of news.php like news.php?xxx ( Sorry I don't know the correct name so I will call them url extensions... )

    Could anyone please tell me how to make this line strictly only serve news.php and not news.php?xxx

    $CUSTOMPAGES['feature'] = " index.php news.php "
    PHP:
     
    Grimmfang, Apr 17, 2012 IP
  2. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #2
    you can use $_SERVER['SCRIPT_NAME'] but it adds the slash before.

    so it would be /news.php
     
    Lee Stevens, Apr 17, 2012 IP
  3. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #3
    So $CUSTOMPAGES['feature'] = " index.php /news.php " ?

    Edit - Just tried it, didn't work could you clarify?
     
    Grimmfang, Apr 17, 2012 IP
  4. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #4
    What is $CUSTOMPAGES['feature'] for?

    Use:
    
    <?php
    if ($_SERVER['SCRIPT_NAME']  == "/news.php")
    {
        //do stuff
    } else
    {
        //other stuff.
    }
    ?>
    
    PHP:
    or

    
    <?php
    if (in_array(array("/index.php", "/news.php"), $_SERVER['SCRIPT_NAME']))
    {
    	//do stuff
    } else
    {
    	// do other stuff
    }
    ?>
    
    PHP:
     
    Lee Stevens, Apr 17, 2012 IP
  5. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #5
    It activates the featurebox on those pages. Is there anyway to do this in that single line of code?
     
    Grimmfang, Apr 17, 2012 IP
  6. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #6
    What should be the value of $CUSTOMPAGES['feature']?

    You mean like this:
    
    $CUSTOMPAGES['feature'] = (in_array(array("/index.php", "/news.php"), $_SERVER['SCRIPT_NAME'])) ? true : false;
    
    PHP:
     
    Lee Stevens, Apr 17, 2012 IP
  7. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #7
    $CUSTOMPAGES['feature'] = " index.php news.php " .$tp->toFORM( $pref['bn_layout1']). "";

    This is the full line.
     
    Grimmfang, Apr 17, 2012 IP
  8. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #8
    Try this:
    
    $CUSTOMPAGES['feature'] = (in_array(array("/index.php", "/news.php"), $_SERVER['SCRIPT_NAME'])) ? $tp->toFORM( $pref['bn_layout1']) : '';
    
    PHP:
    I'm still not sure really what your trying to do.....
     
    Lee Stevens, Apr 17, 2012 IP
  9. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #9
    After applying your code it didn't work at all on news.php :\

    All I want to do is have the featurebox play on news.php but not on pages like news.php?1
     
    Grimmfang, Apr 17, 2012 IP
  10. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #10
    Just do this then:
    
    echo (in_array(array("/index.php", "/news.php"), $_SERVER['SCRIPT_NAME'])) ? $CUSTOMPAGES['feature'] .  $tp->toFORM( $pref['bn_layout1']) : '';
    
    PHP:
     
    Lee Stevens, Apr 17, 2012 IP
  11. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #11
    That didn't work the featurebox didn't play on any pages.
     
    Grimmfang, Apr 17, 2012 IP
  12. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #12
    Sorry my bad, just tested.
    
    echo (in_array(basename($_SERVER['SCRIPT_NAME']), array("index.php", "news.php"))) ? $CUSTOMPAGES['feature'] . $tp->toFORM( $pref['bn_layout1']) : '';
    
    PHP:
     
    Lee Stevens, Apr 17, 2012 IP
  13. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #13
    Still didn't work, however it glitched my layout and wrote index.php in the top corner.
     
    Grimmfang, Apr 17, 2012 IP
  14. Lee Stevens

    Lee Stevens Active Member

    Messages:
    148
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    68
    #14
    Well considering i don't no what $CUSTOMPAGES['feature'] is for nor $tp->toFORM( $pref['bn_layout1']) this is getting really hard to help you and it's 3:35 am in the UK, so i'm going hopefully someone else will sort it out for you...
     
    Lee Stevens, Apr 17, 2012 IP
  15. Grimmfang

    Grimmfang Member

    Messages:
    191
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #15
    I didn't think it would be this difficult to just disable this for all pages except news.php >.>
     
    Grimmfang, Apr 17, 2012 IP