So, I've found a way to get the current directory using dirname(__FILE__)
and getting the domain with $_SERVER['HTTP_HOST']
. While both of these are well and good, they aren't quite what I need them to be.
For instance, if I have a script on http://mydomain.com/scripts/myscript.php
, I'd like to get http://mydomain.com/scripts/
. I feel like there should be an easy way to do this and that I've somehow overlooked something.
As an aside, I am currently using the script in a cloud shared hosting environment, so the directory structure is somewhat odd.
Try:
<?php
echo $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
The only problem with that is that dirname returns the parent directory, so if you access http://domain.com/scripts/ directly you'll just get http://domain.com/ withouth the scripts. http://domain.com/scripts/script.php resolves correctly to http://domain.com/scripts/ though.
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