PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<gmp_xorheader>
view the version of this page
Last updated: Thu, 21 Aug 2003

XXXVI. HTTP functions

Introduction

These functions let you manipulate the output sent back to the remote browser right down to the HTTP protocol level.

Requirements

No external libraries are needed to build this extension.

Installation

There is no installation needed to use these functions; they are part of the PHP core.

Runtime Configuration

This extension has no configuration directives defined in php.ini.

Resource Types

This extension has no resource types defined.

Predefined Constants

This extension has no constants defined.

Table of Contents
header -- Send a raw HTTP header
headers_sent -- Checks if or where headers have been sent
setcookie -- Send a cookie


add a note add a note User Contributed Notes
HTTP functions
mazsolt at yahoo dot com
18-Jul-2003 04:58
You can access the elements of an array either with {} or with []. But with cookie arrays it works only the []

setcookie("a{1}",1,time()+100);
setcookie("a{2}",1,time()+100);
setcookie("aa[1]",1,time()+100);
setcookie("aa[2]",1,time()+100);

You will have three cookies:

$_COOKIE["a{1}"], $_COOKIE["a{2}"] and the $_COOKIE["aa"] array
nstansbury at redbacksystems dot com
06-May-2003 12:35
I wanted to do an http redirect taking into account their current uri:

ie. authentication failed - redirect to login.php

$NewPage = 'login';
$NewURL = preg_replace( "[\w+(?=\.php)]", $NewPage, $_SERVER[ "SCRIPT_URI" ] );
header( "location: $NewURL\r\n" );

Hope this might be useful for someone.
breaker at coder dot hu
16-Mar-2003 12:15
[Editor's Note:] This method uses JavaScript which requires the visitor's browser to have javascript enabled [/Note]

Another way, to redirect to an url without any notification or message:
Print("window.location='$urlvar';");
nf at wh3rd dot net
06-Sep-2002 01:57
If you're wanting to perform an HTTP POST, I've written a small but useful function to do so:

http://nf.wh3rd.net/projects/http.inc/
tom at tom420 dot com
12-Aug-2002 01:42
The last post must be related with an older version of some browser. I've tried it with both IE 6.0 (which comes with XP) and Mozilla 1.1, both with \r\n and without it, and in both cases the new URL shows up in the address bar.

I do remember such a glitch with IE in the past however.
paul at siroccoh dot com
01-Jul-2002 01:04
Redirecting:
If you want the URL you are redirecting to with header("Location: $url") to appear in the location bar in your browser, you have to add a <CRLF> at the end of the string; ie header("Location: blah.com\r\n") It'll still redirect without the \r\n but for some reason the URL remains unchanged in the location bar.
krisj at blueridge dot net
24-Jan-2001 08:41
When using the $SERVER_NAME or other predefined variables within a function BE SURE to use $GLOBALS["SERVER_NAME"] in its place =)
jeffp-php at outofservice dot com
05-Jan-2001 12:37
$HTTP_RAW_POST_DATA --

You'll usually access variables from forms sent via POST method by just accessing the associated PHP global variable.

However, if your POST data is not URI encoded (i.e., custom application that's not form-based) PHP won't parse the data into nice variables for you.  You will need to use $HTTP_RAW_POST_DATA to access the raw data directly. (This should return a copy of the data given to the PHP process on STDIN; note that you wan't be able to open STDIN and read it yourself because PHP already did so itself.)
rob at OhReally dot com
08-Jul-2000 10:22
To redirect your visitors without interference (no warning/explanation) you should use
header("Location: http://some.server.com");
If you would first like to tell your visitors what is going to happen ('You'll be redirected in 5 secs') you should consider meta-tags or JavaScript.
rob at OhReally dot com
29-Jun-2000 10:59
To display the current URL, I'd rather use
$REQUEST_URI
or
$SERVER_NAME.$REQUEST_URI
This will include the query-string.
Make a phpinfo() file to see all environment variables.

Rob
dhpainter at msn dot com
27-Apr-2000 12:35
To create a link to the previous page you can use the
 getenv("HTTP_REFERER")
command and  set it up as a hyperlink. You might also want to put a IF condition on it so it won't get displayed if the user has gone straight in to the page.

<gmp_xorheader>
 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: http://php.mirrors.ilisys.com.au/
Last updated: Sat 01 Nov 2003 04:13:36 EST EST