URL 함수 목록

Table of Contents

  • base64_decode — MIME base64로 인코드한 데이터를 디코드합니다
  • base64_encode — 데이터를 MIME base64로 인코드
  • get_headers — Fetches all the headers sent by the server in response to a HTTP request
  • get_meta_tags — 파일에서 모든 메타 태그 내용 요소를 추출하여 배열로 반환
  • http_build_query — URL 인코드한 쿼리 문자열 생성
  • parse_url — URL을 해석해서 구성요소를 반환
  • rawurldecode — URL 인코드된 문자열을 디코드
  • rawurlencode — RFC 1738에 따른 URL 인코드
  • urldecode — URL 인코드된 문자열을 디코드
  • urlencode — 문자열을 URL 인코드
add a note add a note

User Contributed Notes 11 notes

jrg45 at pantheon dot yale dot edu
17 years ago
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.
tumor at kkt dot bme dot hu
19 years ago
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...
verdy_p at wanadoo dot fr
18 years ago
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.
<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 + '">');
<FRAME src="your-page-script.php?js=0">

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).
php at malaker dot com
15 years ago
Following method do not show the URL in user browser (as the author claimed) if the code resides in the source page of  FRAME or IFRAME (say SRC="sourcepage.php") . In that case the URL of the SOURCE page is displayed.

$url = sprintf("%s%s%s","http://",$HTTP_HOST,$REQUEST_URI);
echo "$url";

Expected result: http://localhost/urltest/framedpage.php

Actual result: http://localhost/urltest/sourcepage.php
dday at cnscorp dot com
14 years ago
When using a multiple select on a form, I ran into a little issue of only receiving the last value form the select box.
I had a select box named organization_id with two values (92 and 93).
To get the values of both, I had to use the following:

    $temp_array = split("&", $_SERVER['QUERY_STRING']);
    foreach($temp_array as $key=>$value){
        if(substr($value, 0, 15) == "organization_id"){
            $_GET['organizations'][] = substr($value, 15, strlen($value));

this results in a $_GET array like this :

    [page] => idea_submission
    [organization_id] => 93
    [organizations] => Array
            [0] => =92
            [1] => =93

16 years ago
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'); ?>
martin at limitless dot co dot uk
13 years ago
Each %xx represents a letter. You would need to remove %68%74%74%70%3a%2f%2f (http://) from the beginning.
chemanfit at hotmail
16 years ago
just a side note to the above you will need to add the ?


stephane-wantiez at tiscalinet dot be
17 years ago
if you do this, it will be easier :
echo "http://{$HTTP_HOST}{$REQUEST_URI}";
ignacio paz posse
16 years ago
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: http://www.your_domain/somepage.php?variable=1;

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

adding $_SERVER['QUERY_STRING'], we pass that, plus [query]: variable=1
postmaster at asmatic dot ch
17 years ago
If you want to get the filename requested on a global error page like a 404, just use this code...

// get the full var...

// 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);
To Top