Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path where user extracted php files to

Tags:

php

If a user extracted the files of my php application to example http://example.com/test/webapp/, the absolute links in my application won't work anymore.

How can I get the path /test/webapp/ to add it to my absolute links?

like image 546
Zulakis Avatar asked Sep 14 '26 23:09

Zulakis


1 Answers

You can with:

dirname( $_SERVER["SCRIPT_NAME"] );

make sure your links are always relative in your pages, so when you move your site to another domain they still work.

Check out all other $_SERVER variables by executing phpinfo() .

for redirecting, you can use:

header('Location: https://' . $_SERVER['SERVER_NAME'] . dirname($_SERVER['SCRIPT_NAME']) . '/some_page.php');
like image 135
Nelson Avatar answered Sep 17 '26 21:09

Nelson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!