Jump to content

Newbie question involving include()


Little Yoshi

Recommended Posts

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

Do not use the full URL to include local files.

In file1.php
[code]<?php
include('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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.