WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : getting the name of the current script and query string
Categories : PHP, Global Variables, Variables, URLs Click here to Update Your Picture
Justin French
Date : May 23rd 2003
Grade : 3 of 5 (graded 4 times)
Viewed : 17944
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Justin French
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

Someone asked this on the PHP list today, so here it is for everyone!

$_SERVER['PHP_SELF'] (or even just $PHP_SELF on most PHP installs) is great for getting the name of
the script/url currently being executed, or for pointing a script to itself, etc etc.

But sometimes you also need the querystring (everything after the '?') as well.

The one line version:
<?php
$foo
= $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
?>


... this works fine, but if there's no query string, it will still have the '?', so the better
version:

<?php
if($_SERVER['QUERY_STRING']) {
   
$foo = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
} else {
   
$foo = $_SERVER['PHP_SELF'];
}
?>


In the case of a URL like http://www.preshrunk.com/history.php?page=browse&year=2002, $foo would
contain 'page=browse&year=2002'.

The above assumes PHP >= 4.1 (superglobal arrays used).



pick up an array of variables from a query string such as: http://www.archipro.com/test.php?state=AB&state=BC
Categories : PHP, Strings, URLs, Global Variables
Initialize global variables for every field in a table. This version requires that phplib is installed on your server.
Categories : Global Variables, MySQL, PHP, Variables
Simple script to passing persistent and growing array between recalls of one page (manipulate little stack).
Categories : Arrays, Global Variables, PHP, HTML and PHP, Variables
How to make sure a that $foo is from a cookie and not from the URI.
Categories : PHP, Variables, Global Variables, Cookies
Make old style (PHP3) scripts using GET, POST, COOKIE and File uploads (POST) compatible with PHP 4.2.0
Categories : PHP, HTML and PHP, Global Variables, Cookies, Variables
Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI
Categories : Variables, PHP Options and Info, Arrays, URLs, PHP
Global Dump Highlighted
Categories : PHP, Variables, Global Variables
Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET
Categories : Algorithms, HTML and PHP, PHP, Variables
Display variables when a form is submitted using POST/GET
Categories : PHP, Functions, Variables, Debugging
phpHoo2 (Xhoo using php3/MySQL) is a Yahoo-like link directory. Much like the Open Directory Project (dmoz.org).
Categories : PHP, Complete Programs, Directories, MySQL, URLs
Functions to read a template file and fill in PHP variables. It will also fill in array variables, displaying parts of the template multiple times.
Categories : PHP, Variables, Filesystem
SubmitForce URL power submitter (searchengine submission class)
Categories : PHP, Search Engines, URLs, PHP Classes
PHPRecommend v1.0 - Recommend this page to a friend script written in PHP. Easy to install
Categories : PHP, URLs, Complete Programs, Email, Site Planning
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
Proper way to do a header redirection with PHP.
Categories : PHP, Headers, URLs
 Sarah King wrote :979
Consider the case of an included script 

If it needs to know it`s own location (and you don`t want to hardcode it) how does that script know it`s location?