OhEmGee Posted February 18, 2007 Share Posted February 18, 2007 I'm an absolute newbie to php and was wondering if anyone could point me in the right direction, searching google/forums and everywhere else has been no help, I need to excute a peice of code on index.php only, how would I go about doing that..? Using a bit of common sense I'd guess that the code would need to check the current page, then something like an if statement so that if the filename is index.php, the code would work, but display something else if not. I hope that made sense! Link to comment https://forums.phpfreaks.com/topic/39028-code-that-checks-for-filename-of-current-page-no-idea-where-to-start/ Share on other sites More sharing options...
redarrow Posted February 18, 2007 Share Posted February 18, 2007 use $_GET['']; example <?php index.php?cmd=page if($_GET['cmd']=="page"){ //do some think }else { //do nothink } ?> Link to comment https://forums.phpfreaks.com/topic/39028-code-that-checks-for-filename-of-current-page-no-idea-where-to-start/#findComment-187926 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 That will not give the OP the name of the script that is being run. To get that you need to use the magic constant __FILE__. Ken Link to comment https://forums.phpfreaks.com/topic/39028-code-that-checks-for-filename-of-current-page-no-idea-where-to-start/#findComment-187930 Share on other sites More sharing options...
OhEmGee Posted February 18, 2007 Author Share Posted February 18, 2007 Sorry I'm not sure about that, how would I put that magic constant into the script..? Link to comment https://forums.phpfreaks.com/topic/39028-code-that-checks-for-filename-of-current-page-no-idea-where-to-start/#findComment-187944 Share on other sites More sharing options...
trq Posted February 18, 2007 Share Posted February 18, 2007 Did you read the link to the manual page provided? Link to comment https://forums.phpfreaks.com/topic/39028-code-that-checks-for-filename-of-current-page-no-idea-where-to-start/#findComment-187947 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 Did you look at the manual page I referenced in my answer? Put this in a test script to see what it produces: <?php echo "This script is running from file: " . __FILE__; ?> Ken Link to comment https://forums.phpfreaks.com/topic/39028-code-that-checks-for-filename-of-current-page-no-idea-where-to-start/#findComment-187949 Share on other sites More sharing options...
OhEmGee Posted February 18, 2007 Author Share Posted February 18, 2007 Well I read the manual but none of it helps with what I'm trying to do, I tried this but it obviously doesn't work, <?php $index = "absolute/path/to/my/index.php" if ( __FILE__ == $index ) { include("certain_file.php"); } ?> but I hope that makes it clearer for what I am trying to get. I'd like the code to check if the file is index.php and if so, then include the certain file. ??? ??? Sorry I am still learning Php, it's difficult reading that manual because it's like I've been thrown into the deep end, I don't yet know how it all works. Link to comment https://forums.phpfreaks.com/topic/39028-code-that-checks-for-filename-of-current-page-no-idea-where-to-start/#findComment-187978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.