Trying to get information about the current directly you are in via PHP can be a bit confusing with all the various PHP functions related to listing information about the current directory.
For the code examples below, we will pretend we are running the php from a url on our website https://www.vb6code.com/phpcode/examples/code-php-current-directory-file-functions.php
getcwd()
OR dirname(__FILE__)
.
/elmo/walweb04/walweb04ac/d793/moo.isspybubbleascamcom/vb6code.com/phpcode/examples/
. Note that the last listed item listed to the right is the current folder.
basename(dirname(__FILE__))
OR basename(__DIR__)
.
examples
.
dirname($_SERVER[PHP_SELF])
.
/phpcode/examples
.
http://
or https://
:
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"
.
$protocol
now contains either http://
or https://
.
$_SERVER['HTTP_HOST']
.
vb6code.com
.
$_SERVER['REQUEST_URI']
.
/phpcode/examples/code-php-current-directory-file-functions.php
.
$protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
.
https://www.vb6code.com/phpcode/examples/code-php-current-directory-file-functions.php
.
You can test these file/folder functions on your web server by copying and pasting the code below into a text file and saving as .php.
If you have a url and you want to parse the url into its different parts you can use the PHP parse_url
function.
We will use the example url https://www.vb6code.com/phpcode/examples/code-php-current-directory-file-functions.php?r=affiliate
First you call the parse_url
function, passing the url you want to parse.
$arrparts['scheme']
.
https://
.
$arrparts['host']
.
vb6code.com
.
$arrparts['path']
.
/phpcode/examples/code-php-current-directory-file-functions.php
.
$arrparts['query']
.
r=affiliate
.