Skip to content

Instantly share code, notes, and snippets.

@indrakaw
Created April 28, 2017 09:49
Show Gist options
  • Save indrakaw/cbf31d45d0cf68173dc5a1223f6e7e6c to your computer and use it in GitHub Desktop.
Save indrakaw/cbf31d45d0cf68173dc5a1223f6e7e6c to your computer and use it in GitHub Desktop.
<h1>Put this file anywhere.</h1>
<pre>Print server Variable:
<?php print_r($_SERVER); ?></pre>
<pre>Print base dir of this file:
<?php
$protocol = 'http://';
$host = $_SERVER['HTTP_HOST'];
$file = $_SERVER['SCRIPT_NAME'];
// $baseDir = $protocol.$host.str_replace(basename($file), "", $file);
$baseDir = str_replace(basename($file), "", $file);
echo $baseDir;
// PS: It only work via webserver
?></pre>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment