PHP  
downloads | documentation | faq | getting help | mailing lists | | php.net sites | links | my php.net 
search for in the  
<token_namebase64_decode>
view the version of this page
Last updated: Tue, 22 Apr 2003

CII. URL Functies

Introductie

Bewerken van URL strings: coderen, decoderen en parsen.

Afhankelijkheden

Deze functies zijn beschikbaar als onderdeel van de standarad module die altijd beschikbaar is.

Installatie

Er zijn geen handelingen nodig m.b.t. tot installatie voor deze functies, deze maken deel uit van de kern van PHP.

Configuratie tijdens scriptuitvoer

Deze extensie gebruikt geen configuratie regels.

Resource types

Deze extensie maakt geen gebruik van resources.

Voorgedefineerde constanten

Deze extensie definieert geen constanten.

Inhoudsopgave
base64_decode -- Decodeert gegevens ge�ncodeerd met MIME base64
base64_encode -- Encodeert gegevens met MIME base64
get_meta_tags --  Extracts all meta tag content attributes from a file and returns an array
parse_url -- Parse a URL and return its components
rawurldecode -- Decode URL-encoded strings
rawurlencode -- URL-encode according to RFC 1738
urldecode -- Decodeert een URL-gecodeerde string
urlencode -- URL-codeert een string


User Contributed Notes
URL Functies
add a note add a note
kasper at industree dot org
17-Feb-2000 10:30

Use $REQUEST_URI to get the most important part of the URL of the current page
(see predefined variables for more info)

assassin74 at hotmail dot com
13-Mar-2000 02:06

To acccess the previous URL in history:
$HTTP_REFERER

tumor at kkt dot bme dot hu
01-Apr-2000 06:18

To check if a URL is valid, try to fopen() it. If fopen() results an error (returns false), then PHP cannot open the URL you asked. This is usually because it is not valid...
jphilbin at portcitymail dot com
18-Aug-2000 07:56

To get the full url of what should be currently
in a users browser, try this:
$url = sprintf("%s%s%s",");
echo "$url";

cgmckeever at yahoo dot com
19-Aug-2000 12:20

$HTTP_HOST still grabs the redirected server name.

ROCK N ROLL

verdy_p at wanadoo dot fr
26-May-2001 04:55

Warning: when the PHP engine runs for your hosted web site, it may execute on a domain name which is completely different than the one the user requested in its browser. Many free web hosting site use proxies and/or multiple DNS entries for your hosted web site. This means that:
- the IP of the web server can change if multiple DNS entries are present (there may be several web servers running concurrently)
- reverse DNS name from the IP may give different domain name over time, or if the domain name is a CNAME only for a virtual web server hosting many domains
- the server running PHP may be different than the web server
- the web server may be hidden behind a proxy which balances the load between a farm of servers
- the queried host name in the HTTP headers may be different than the queried host name in the browser, if behind a redirecting proxy
- the actual path name of the ressource may be also different, with additional path elements: this is very common on free hosting servers, where you get a virtual CNAME domain, which gets translated by a proxy into an actual web server, and a domain-specific document root directory

So when thinking about using absolute path names you can retreive from PHP, beware that this may not be accurate to insert as absolute URL's in the HTML code built with PHP.

The best solution is then to ALWAYS USE relative URLs to reference documents and form scripts on your local server !

This applies to $PHP_SELF too, because it's an absolute pathname: don't use it directly but you can safely use basename($PHP_SELF) to reference your script within HTML forms:

<?
$self=basename($PHP_SELF);
?>
<HTML><HEAD>
...
</HEAD><BODY>
<FORM method="GET" action="$self">
...
</FORM>
</BODY></HTML>

verdy_p at wanadoo dot fr
26-May-2001 05:47

Note also that the URL shown in $HTTP_REFERER is not always the URL of the web page where the user clicked to invoke the PHP script.
This may instead be a document of your own web site, which contains an HTML element whose one attribute references the script. Note also that the current page fragment (#anchor) may be transmitted or not with the URL, depending on the browser.
Examples:
<FRAME src="your-page-script.php"8>
<IMAGE src="your-image-script.php">

In such case, browsers should transmit the URL of the container document, but some still persist in using the previous document in the browser history, and this could cause a different $HTTP_REFERER value be sent when the user comes back to the document referencing your script. If you wanna be sure that the actual current document or previous document in the history is sent, use client-side JavaScript to send it to your script:

<SCRIPT language="JavaScript"><!--
document.writeln('<FRAME src="your-page-script.php?js=1&amp;ref=' +
document.location + '">');
--></SCRIPT><NOSCRIPT>
<FRAME src="your-page-script.php?js=0">
</NOSCRIPT>

And then check the value of $js in your page script to generate appropriate content when the remote user agent does not support client-side scripts (such as most index/scan robots, some old or special simplified browsers, or browsers with JavaScript disabled by their users).

stephane-wantiez at tiscalinet dot be
07-Feb-2002 01:29

if you do this, it will be easier :
echo "

danker_ at hotmail dot com
21-Feb-2002 07:06

$micadena = $HTTP_SERVER_VARS["HTTP_REFERER"];

Obtienes la p�gina anteriormente visitada

postmaster at asmatic dot ch
29-Apr-2002 04:15

If you want to get the filename requested on a global error page like a 404, just use this code...

// get the full var...
$page = $HTTP_SERVER_VARS["QUERY_STRING"];

// part[1] is the url...
// part[0] is the http code (404, etc).
if(strpos($page,";")>0) {
  $pageParts = explode(";",$page);
  $page = $pageParts[1];
}

// get only the filename...
$page = basename($page);

aflorio 'at' ecp.inf.puc-rio.br
03-Jul-2002 05:36

If you want to check if a variable was passed in the querystring (ie., <url>?var=value&...), but don't want to use 'isset($var)' because maybe the var is in the session (and so you can get wrong
'true's), use the $_GET array.

For example:

isset($_GET['var']) == TRUE if var in querystring, but
isset($_GET['var']) == FALSE if var in session and not in querystring

jrg45 at pantheon dot yale dot edu
10-Jul-2002 09:14

Note that $_SERVER["HTTP_REFERER"] may not include GET data that was included in the referring address, depending on the browser.  So if you rely on GET variables to generate a page, it's not a good idea to use HTTP_REFERER to smoothly "bounce" someone back to the page he/she came from.
ignacio
12-Mar-2003 05:16

/*
May be this is obvious but helps me since I found it:
If I want to append a variable to the url and pass it to the same page. ( in this example I'm using action=email to include an email form on the user click) i do:
*/

// ...

<a href="<? echo $PHP_SELF,'?',$_SERVER['QUERY_STRING'],'&action=email' ?>">email to us</a>

// ...

/* somewhere in the the page (in my case at the bottom) I have: */

<? if ($action=='email') include('emailForm.htm'); ?>

ignacio paz posse
13-Mar-2003 12:31

Note on the above: the point is that is that using $_SERVER['QUERY_STRING'] along with $PHP_SELF we will have passed whatever variables are already appended (as they might be needed for database queries)

example, given the following url:

using $PHP_SELF" we are passing
[scheme]:(), [host]: www.your_domain/  and [path]: somepage.php

adding $_SERVER['QUERY_STRING'], we pass that, plus [query]: variable=1

add a note add a note

<token_namebase64_decode>
 Last updated: Tue, 22 Apr 2003
show source | credits | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: /
Last updated: Mon May 26 17:09:40 2003 CEST