Little Yoshi Posted December 2, 2006 Share Posted December 2, 2006 Hi everyone, I'm relatively new to php and have a question.Is there a way for a file that is included by include() to get the url (not including the domain name) of the file that is including it? Like domain.com/file1.php includes domain.com/file2.php. Is there a way for file2.php to get the string "/file1.php"? $_SERVER['PHP_SELF'] would have /file2.php and not /file1.php so I don't know what to do. Link to comment https://forums.phpfreaks.com/topic/29186-newbie-question-involving-include/ Share on other sites More sharing options...
jsladek Posted December 2, 2006 Share Posted December 2, 2006 You sure about that? I'm pretty sure $_SERVER['PHP_SELF'] (contained in file2.php) will have file1.php not file2.php-John Link to comment https://forums.phpfreaks.com/topic/29186-newbie-question-involving-include/#findComment-133811 Share on other sites More sharing options...
Little Yoshi Posted December 3, 2006 Author Share Posted December 3, 2006 Yeah, I just tried it so I'm sure. Link to comment https://forums.phpfreaks.com/topic/29186-newbie-question-involving-include/#findComment-134160 Share on other sites More sharing options...
kenrbnsn Posted December 3, 2006 Share Posted December 3, 2006 How are you including file2.php?Please show us your script.Ken Link to comment https://forums.phpfreaks.com/topic/29186-newbie-question-involving-include/#findComment-134184 Share on other sites More sharing options...
Little Yoshi Posted December 3, 2006 Author Share Posted December 3, 2006 Here's how I'm doing it:file1.php:[code]<?php include("http://www.mydomainname.com/file2.php");?>[/code]file2.php:[code]<?php print $_SERVER['PHP_SELF'];?>[/code]file1.php displays "/file2.php" Link to comment https://forums.phpfreaks.com/topic/29186-newbie-question-involving-include/#findComment-134219 Share on other sites More sharing options...
kenrbnsn Posted December 3, 2006 Share Posted December 3, 2006 Do not use the full URL to include local files.In file1.php[code]<?phpinclude('file2.php');?>[/code]When you use the full URL, you're invoking another instance of the PHP processor that is separate from the original script, so $PHP_SELF is the included file.Ken Link to comment https://forums.phpfreaks.com/topic/29186-newbie-question-involving-include/#findComment-134231 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.