what is the difference ($_SERVER)
Moderator: General Moderators
what is the difference ($_SERVER)
I'm a little confused with this uses of this variables:
'PHP_SELF'
'DOCUMENT_ROOT'
'SCRIPT_FILENAME'
'PATH_TRANSLATED'
'SCRIPT_NAME'
in what situations do i need them?
thanks
'PHP_SELF'
'DOCUMENT_ROOT'
'SCRIPT_FILENAME'
'PATH_TRANSLATED'
'SCRIPT_NAME'
in what situations do i need them?
thanks
- MarK (CZ)
- Forum Contributor
- Posts: 239
- Joined: Tue Apr 13, 2004 12:51 am
- Location: Prague (CZ) / Vienna (A)
- Contact:
Code: Select all
<?php
if (!Empty($_POST['input_field'])) {
// handle the variable
// if not empty
} else {
// ask for the variable otherwise
?>
<form method="post" action="<?= $_SERVER['PHP_SELF'] ?>">
<input type="text" name="input_field"></input>
<button type="submit">Submit form</button>
</form>
<?php
}
?>-
Breckenridge
- Forum Commoner
- Posts: 62
- Joined: Thu Sep 09, 2004 11:10 pm
- Location: Breckenridge, Colorado
Assume that your script aka php file named myfile.php is located under: /var/www/public/
'PHP_SELF' is the script file name:
myfile.php
common use:
<form action='<? echo $_SERVER['PHP_SELF']?>'>
'DOCUMENT_ROOT' is the root dir of your web server /var/www/public/
common use:
<?
include $_SERVER['DOCUMENT_ROOT']."/lib/common.php";
?>
'SCRIPT_FILENAME' = PHP_SELF without path
'PATH_TRANSLATED' path to script i.e. / or /images/
'SCRIPT_NAME' file name + any $_GET variables I think. I will verify and fix this post if needed.
'PHP_SELF' is the script file name:
myfile.php
common use:
<form action='<? echo $_SERVER['PHP_SELF']?>'>
'DOCUMENT_ROOT' is the root dir of your web server /var/www/public/
common use:
<?
include $_SERVER['DOCUMENT_ROOT']."/lib/common.php";
?>
'SCRIPT_FILENAME' = PHP_SELF without path
'PATH_TRANSLATED' path to script i.e. / or /images/
'SCRIPT_NAME' file name + any $_GET variables I think. I will verify and fix this post if needed.