php-Pre-Def variable
<Beginner PHP><Array><Loop><Function><Pre-Def variable><Session><Read Write File><CRUD>
General
A superglobal is a predef var, that is alwaysa ccessible, regardless of scope.
Yu can access the PHP superglobalsthrough function, class or file.
Superglobal variables
$_SERVER
$GLOBALS
$REQUEST
$_POST
$_GET
$_FILES
$_ENV
$_COOKIE
$_SESSION
$SERVER
it returns the path of the current script. Includes: headers, paths, K script location.
<?php
echo $_SERVER[`SCRIPT_NAME`];
?> // /Playground/file().php
elements for $_SERVER
Some of the most important elements going inside $Server
$_SERVER[`SERVER_NAME`]
$_SERVER[`REQUEST_METHOD`]
$_SERVER[`QUERY_STRING`]
$_SERVER[`HTTP_HOST`]
$_SERVER[`REMOTE_ADDR`]
$_SERVER[`REMOTE_HOST`]
$_SERVER[`SERVER_PORT`]
$_SERVER[`SCRIPT_NAME`]
$_SERVER[`SCRIPT_URI`]
$_SERVER variable: Host name
$_SERVER[`HTTP_HOST`]
Returns the host header from the current request
<?php
echo $_SERVER[`HTTP_HOST']; // output "localhost"
?>
Exemple:
To transfer website to another host, instead of changing the path for each image, create a config.php file that holds the path for your images:
<?php
$host=$_SERVER['HTTP_HOST'];
$image_path=$host.'/images/';
?>
use config.php file in your scripts
<?php
require 'config.php';
echo'<img src='.$image_path.'header.png' />';
?>
<?php
?>
<?php
?>
<?php
?>
Comments
Post a Comment