johnwinch42 Posted February 3, 2014 Share Posted February 3, 2014 (edited) Hello, I would like to know how to proceed to only have specific links to show on a specific page (index.php for example) The links would be in my footer and would only show up on my homepage. How can I do that? Thanks for your answers, Best regards, Edited February 3, 2014 by johnwinch42 Quote Link to comment Share on other sites More sharing options...
adam_bray Posted February 3, 2014 Share Posted February 3, 2014 You want to use an IF statement with $_SERVER['php_self'] Quote Link to comment Share on other sites More sharing options...
johnwinch42 Posted February 3, 2014 Author Share Posted February 3, 2014 You want to use an IF statement with $_SERVER['php_self'] I'm kind of new to all of this, how can I implement this variable in my code? Quote Link to comment Share on other sites More sharing options...
adam_bray Posted February 3, 2014 Share Posted February 3, 2014 Like this - <?php if( $_SERVER['PHP_SELF'] == '/index.php' ) { print '<a href="page2.php">Go to page 2</a>'; } elseif( $_SERVER['PHP_SELF'] == '/page2.php' ) { print '<a href="index.php">Go Home</a>'; } ?> Quote Link to comment Share on other sites More sharing options...
johnwinch42 Posted February 3, 2014 Author Share Posted February 3, 2014 Thanks you very much! For the else I don't want to show anything on the other pages, would it be something like this? <?php if( $_SERVER['PHP_SELF'] == '/index.php' ) { print '<a href="page2.php">Go to page 2</a>'; } else { print ' '; }?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 3, 2014 Share Posted February 3, 2014 For the else I don't want to show anything on the other pages, would it be something like this? If you don't want anything to show up, you don't need the else. The links will only show up when the if conditions are met. Also note that you could use a switch for multiple pages: <?php switch($_SERVER['PHP_SELF']) { case '/index.php': print '<a href="page2.php">Go to page 2</a>'; break; case '/page2.php': print '<a href="index.php">Go Home</a>'; break; } ?> Quote Link to comment Share on other sites More sharing options...
johnwinch42 Posted February 4, 2014 Author Share Posted February 4, 2014 (edited) Great it's working thanks you But is there a way to put the full url instead of the path in if( $_SERVER['PHP_SELF'] == '/index.php' ) ? Edited February 4, 2014 by johnwinch42 Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 4, 2014 Share Posted February 4, 2014 You could try using $_ENV['SCRIPT_URI'] Quote Link to comment Share on other sites More sharing options...
johnwinch42 Posted February 4, 2014 Author Share Posted February 4, 2014 Like this? <?php if( $_ENV['SCRIPT_URI'] == 'http://www.test.com' ) { print '<a href="page2.php">Go to page 2</a>'; } else { print ' '; } ?> Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted February 4, 2014 Share Posted February 4, 2014 You'll need to use the full URL. <?php if($_ENV['SCRIPT_URI'] == 'http://www.test.com/index.php' ) { print '<a href="page2.php">Go to page 2</a>'; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.