This is almost same question as this
I need to get ABSOLUTE url to my script. For example, I have this structure
http://mydomain.com/downloads/games/freegame_222/ajax.php
My application root would be in freegame_222/
but, how can I "build" absolute, not relative path to ajax.php? Result will be
http://mydomain.com/downloads/games/freegame_222/ajax.php
or
/downloads/games/freegame_222/ajax.php
but not:
ajax.php
These examples will return after url("ajax.php");
is called
Is there a native function in PHP for it? If no, does anybody know about any custom one?
I want to call that page from another page, for example index.php
Similar to George Cummins' answer, simply do something like such:
$path = $_SERVER['SERVER_NAME'] . '/' . $_SERVER['REQUEST_URI'];
This should give you the complete path. Now if you want to get this from another page, what reason is there to have it generate the url dynamically? Why can't you just use the absolute path, or if anything, $_SERVER['SERVER_NAME']
+ rest of path so it works between domains/hosts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With