Relative and/or Absolute path in PHP

Asked

Viewed 37 times

0

I’ve done a few searches on Stackoverflow about Absolute path and relative path, but none of the solutions worked for what I need. I need the $host (example below) point to where my index.php dynamically, that is, if you change the hosting do not need to change the address manually. Any suggestions?

$host."index.php?id=2&url=".$link."&title=".$noticia."&s=1&logo=".$foto;

$host = "http://exemplo.com.br/teste/"
  • $host = ("http://".$_SERVER['HTTP_HOST']); this will return h ttp://example.com.br

  • In HTML, when to put a slash / the front of the file, you will be indicating that the path is relative to the root directory of the server. When doing /index.php, that will always point to the index.php from the root of the application, regardless of which domain it is. Would that solve your problem? Which to your second question, I will remove it for making the question too broad, but if you need it you can open a new question on the subject. I already advance and research on the native class DOMDocument that will probably be useful to you.

  • I had already tried these two alternatives, but with me it didn’t work.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.