Understanding $_SERVER['PHP_SELF'], $PHP_SELF, $_SERVER['REQUEST_URI'] and $_SERVER['SCRIPT_NAME'] in PHP and when to use what Comprendre $ _SERVER [ 'PHP_SELF'], $ PHP_SELF, $ _SERVER [ 'REQUEST_URI'] et $ _SERVER [ 'SCRIPT_NAME'] en PHP et quand utiliser ce que
The above PHP variables have slight differences which are often ignored, often leading to problems in large scale deployments or product solutions. Les variables PHP ont de légères différences qui sont souvent ignorées, ce qui entraîne souvent des problèmes dans des déploiements à grande échelle de produits ou de solutions. I have attempted to debug them for you. J'ai essayé de déboguer pour vous.
$_SERVER['SCRIPT_NAME'] $ _SERVER [ 'SCRIPT_NAME']
This contains the current script’s path. Celui-ci contient le script courant du chemin. If you access Si vous accédez http://blog.taragana.com/ or ou http://blog.taragana.com/index.php the $_SERVER['SCRIPT_NAME'] will be same - /index.php . $ _SERVER [ 'SCRIPT_NAME'] sera même - / index.php. It is irrespective of the actual URI ($_SERVER['REQUEST_URI']) used to access the site. Il est quel que soit le URI ($ _SERVER [ 'REQUEST_URI']) utilisés pour accéder au site.
As it returns the actual script name, it fails provide additional path information that may be present. Comme elle retourne le nom de script, il ne parvient pas fournir des informations de chemin que la présence mai. So if the $_SERVER['REQUEST_URI'] is /index.php/big/directory/ then too the $_SERVER['SCRIPT_NAME'] will be same - /index.php . Ainsi, si l'$ _SERVER [ 'REQUEST_URI'] est / index.php / big / répertoire / alors trop le $ _SERVER [ 'SCRIPT_NAME'] sera même - / index.php.
$_SERVER['SCRIPT_NAME'] is supported on all platforms $ _SERVER [ 'SCRIPT_NAME'] est pris en charge sur toutes les plates-formes
$_SERVER['PHP_SELF'] $ _SERVER [ 'PHP_SELF']
This is the filename of the currently executing script, relative to the document root. C'est le nom de fichier du script en cours d'exécution, par rapport à la racine du document. However, unlike $_SERVER['SCRIPT_NAME'], it provides additional path information like $_SERVER['REQUEST_URI'] when the actual php file is present in the path. Toutefois, à la différence de $ _SERVER [ 'SCRIPT_NAME'], il fournit des informations de chemin comme $ _SERVER [ 'REQUEST_URI'] lorsque le fichier php est présent dans le chemin. So when the $_SERVER['REQUEST_URI'] is /index.php/big/directory/ then $_SERVER['PHP_SELF'] will be /index.php/big/directory/ . Ainsi, lorsque l'$ _SERVER [ 'REQUEST_URI'] est / index.php / big / répertoire / alors $ _SERVER [ 'PHP_SELF'] sera / index.php / big / répertoire /.
However if all the URI’s under http://www.example.com/ is mapped to http://www.example.com/index.php, then, for example, http://www.example.com/abc/def will return /index.php like $_SERVER['SCRIPT_NAME']. Toutefois, si tous les URI de la sous http://www.example.com/ est mis en correspondance avec http://www.example.com/index.php, puis, par exemple, http://www.example.com/ abc / def sera de retour / index.php like $ _SERVER [ 'SCRIPT_NAME']. Note that $_SERVER['REQUEST_URI'] data is ignored for this request. Note that $ _SERVER [ 'REQUEST_URI'] n'est pas pris en compte les données pour cette demande.
$_SERVER['PHP_SELF'] is supported on all platforms. $ _SERVER [ 'PHP_SELF'] est pris en charge sur toutes les plates-formes.
Pages: 1 Pages: 1 2
Filed under Classé sous Headline News Headline News , How To Comment , PHP , Web , Web Hosting Web Hosting , Web Services Services Web | |
| |
RSS 2.0 RSS 2,0 | |
Email this Article Envoyer cet article
You may also like to read Vous mai également à lire |





June 15th, 2006 at 3:45 pm Juin 15th, 2006 at 3:45 pm
$_SERVER variables not set by Tomcat $ _SERVER Variables non établies par Tomcat
Not able to get the value for variable in Tomcat 5.5 and PHP Version 5.1.4 configuration Pas en mesure de récupérer la valeur de la variable dans Tomcat 5,5 et PHP version 5.1.4 de configuration
In fact, only values in _SERVER are En fait, seules les valeurs sont en _SERVER
_SERVER is array 3 _SERVER Est tableau 3
Key: REQUEST_TIME value: 1150399842 Légende: REQUEST_TIME valeur: 1150399842
Key: argv value: Array Légende: valeur argv: Array
Key: argc value: 0 Légende: argc valeur: 0
Searched but couldn’t find anything relevant. Vous avez cherché, mais n'a pas pu trouver quoi que ce soit pertinent. Any pointers? Les pointeurs?
August 17th, 2006 at 12:08 am Août 17th, 2006 at 12:08 am
Hey…I was wondering how to call a particular function by using the $_SERVER['PHP_SELF'] command. Hey… Je me demandais comment appeler une fonction particulière en utilisant le $ _SERVER [ 'PHP_SELF'] commande. Is there any supported way of calling a function from this? Existe-t-il le tout soutenu manière d'appeler une fonction de cela?
-Dan P. - Dan P.
December 3rd, 2006 at 4:40 am Décembre 3rd, 2006 chez 4:40 am
hey, hé,
I have a problem in which the url isn’t parsed properly so it doesnt add the .php to the end of the address in the url bar. J'ai un problème dont l'url n'est pas analysé correctement, il ne ajouter le fichier. Php à la fin de l'adresse dans la barre d'URL. for example, par exemple, http://www.mysite.com/test/11 is suppose to be est supposé être http://www.mysite.com/test/11.php the .php is missing. l'. php est manquant.
My code: Mon code:
Options +FollowSymlinks Options + FollowSymLinks
RewriteEngine On RewriteEngine on
RewriteBase / RewriteBase /
AddType text/xml .xslt AddType text / xml. Xslt
SetHandler text/xml SetHandler text / xml
# PHP is in CGI Mode, so we need a different mod_rewrite # PHP est en mode CGI, que nous besoin d'un autre mod_rewrite
RewriteCond %{REQUEST_URI} !categories\.php RewriteCond% (REQUEST_URI)! Catégories \. Php
RewriteRule ^categories(.*) /categories.php?$1 [L] Catégories RewriteRule ^ (.*) / categories.php? $ 1 [L]
RewriteCond %{REQUEST_URI} !questions\.php RewriteCond% (REQUEST_URI)! Questions \. Php
RewriteRule ^questions(.*)$ /questions.php?$1 [L] RewriteRule ^ questions (.*)$ / questions.php? $ 1 [L]
RewriteCond %{REQUEST_URI} !search\.php RewriteCond% (REQUEST_URI)! Recherche \. Php
RewriteRule ^search(.*)$ /search.php?$1 [L] RewriteRule ^ recherche (.*)$ / search.php? $ 1 [L]
December 20th, 2006 at 12:55 pm 20 décembre 2006 chez 12:55 PM
Hi there, Salut,
I need to retrieve just the page name from the URL - anyone knows how could I do it? Je dois juste récupérer le nom de la page du Web - tout le monde sait comment pourrais-je faire?
I want then assing its value to a variable and use it in sql query for comparasion. Je veux ensuite assing sa valeur à une variable et l'utiliser dans la requête SQL pour comparasion.
Any help would be appreciated. Toute aide serait appréciée.
I look forward. J'attends avec impatience.
Sebastian
May 2nd, 2007 at 11:33 pm 2 mai 2007 à 11:33 pm
how can i get the file name without the directory name Comment puis-je obtenir le nom du fichier sans le nom du répertoire
June 19th, 2007 at 8:05 am Juin 19, 2007 at 8:05 am
subash have searching ajob Subash recherche ont ajob
August 7th, 2007 at 6:42 am 7 août 2007 à 6:42 am
Is this better to call php_self function or create a new file.Because when people refresh it submit the message twice, how can overcome this issue. Est-ce mieux d'appeler PHP_SELF fonction ou créer un nouveau file.Because lorsque les gens de rafraîchissement de présenter le message deux fois, comment peut surmonter ce problème.
October 8th, 2007 at 6:22 am 8 octobre 2007 à 6:22 am
Hello.. Bonjour ..
I’ve done with a program which send copy from local machine to server. Je l'ai fait avec un programme qui envoie la copie locale de la machine vers le serveur.
I m having problem while copying the file. Je m avoir de problème de copier le fichier. Its copied, but goes in Apache server. Son copié, mais va dans le serveur Apache. Please help me to copy that file in server(www)folder. S’il vous plaît aidez-moi à copier ce fichier du serveur (www) dossier.
November 1st, 2007 at 1:24 am 1er novembre 2007 à 1:24 am
Very useful … did clarify some technicalities for me. Très utile… n'a clarifier certains aspects techniques pour moi. Thanks for the headsup! Merci pour la HeadsUp! =)
February 17th, 2008 at 7:00 am 17ème Février, 2008 à 7h00
While I am excecuting $_SERVER['PHP_SELF']then I am getting one message in my browser Forbidden Même si je suis d'exécution $ _SERVER [ 'PHP_SELF'], puis Je reçois un message dans mon navigateur interdite
You don’t have permission to access / Vous n'avez pas l'autorisation d'accès /
March 10th, 2008 at 10:02 am 10 mars 2008 à 10:02 am
thankyou for the informative article. merci pour l'article informatif.
June 10th, 2008 at 8:25 am 10ème Juin, 2008 à 8:25 am
Hi the inforamtin on this site is really helpfull Salut la inforamtin sur ce site est vraiment utile
Thanks Merci
! ! BYE BYE