Jump to content

HTTP ROOT


mme

Recommended Posts

If you want it to read "/var/www/vhosts/mysite.com", use:

$pos = strpos($myvar, 'httpdocs');

$newenv = substr($myvar, 0, $pos-1);

echo $newenv;

 

If you want it to read "/var/www/vhosts/mysite.com/", use:

$pos = strpos($myvar, 'httpdocs');

$newenv = substr($myvar, 0, $pos);

echo $newenv;

Link to comment
https://forums.phpfreaks.com/topic/102239-http-root/#findComment-523463
Share on other sites

Thanks

 

But what if I wanted to use this on another server that doesnt use httpdocs? without manual changes for each different server?

 

You'd need to code a function that analyzed the string and got the position of the last slash and removed it that way.  I could code one I guess, if you really need it.  Do you? :o

Link to comment
https://forums.phpfreaks.com/topic/102239-http-root/#findComment-523473
Share on other sites

function get_new_root() {
  $oldenv = get_env("DOCUMENT_ROOT");
  $slashpos = strrpos($oldenv, "/");
  if ($slashpos === false) {
    return false;
  }
  $newenv = substr($oldenv, 0, $slashpos);
  return $newenv;
}

 

Removes everything after the final slash. =)  Should work on any server.

Usage:

  $doc_root = get_new_root();

 

Returns FALSE if it can't find slashes.

Link to comment
https://forums.phpfreaks.com/topic/102239-http-root/#findComment-523478
Share on other sites

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.