PHP $_REQUEST['URL'] and $_REQUEST['title'] not working

I am trying to get PHP to add a line in a web page about where the user came from. It is so I can have a contact page that the user fills out and when it sends me the info the user fills out it also tells me what page the user chose to contact me from.

it seems that the standard PHP that is part of OS X Server 10.4.9 does not do it. Is there something I am missing? Is there another way to make it happen?

Thanks,
Tom

PowerMac G4, Mac OS X (10.4.9)

Posted on Mar 23, 2007 12:44 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 23, 2007 3:25 PM

Firstly, I'm suspecting that "URL" and "title" are fields on the submitting form?

Secondly, $_REQUEST is defined as "An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE."

Maybe try using $_POST or $_GET depending on the method of the form. For example, if your form is posted, try $_POST["URL"] and $_POST["title"].

Alternatively, you can always use server variables to find out the URL requested, it's referring URL, and info about the requesting browser, e.g.:

$HTTP SERVER_VARS['HTTPREFERER'];
$HTTP SERVER_VARS['HTTP_USERAGENT'];
$HTTP SERVER_VARS['REMOTEADDR'];
$HTTP SERVER_VARS['SCRIPTURI']

It appears that using $_SERVER is more modern and more functional than $HTTP SERVERVARS. I've switched one of my pages and the functionality is the same.

More info on all of this here: http://us2.php.net/manual/en/reserved.variables.php



MacBook Mac OS X (10.4.8)

Message was edited by jaydisc to include $_SERVER info
5 replies
Question marked as Top-ranking reply

Mar 23, 2007 3:25 PM in response to Tom Wootton

Firstly, I'm suspecting that "URL" and "title" are fields on the submitting form?

Secondly, $_REQUEST is defined as "An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE."

Maybe try using $_POST or $_GET depending on the method of the form. For example, if your form is posted, try $_POST["URL"] and $_POST["title"].

Alternatively, you can always use server variables to find out the URL requested, it's referring URL, and info about the requesting browser, e.g.:

$HTTP SERVER_VARS['HTTPREFERER'];
$HTTP SERVER_VARS['HTTP_USERAGENT'];
$HTTP SERVER_VARS['REMOTEADDR'];
$HTTP SERVER_VARS['SCRIPTURI']

It appears that using $_SERVER is more modern and more functional than $HTTP SERVERVARS. I've switched one of my pages and the functionality is the same.

More info on all of this here: http://us2.php.net/manual/en/reserved.variables.php



MacBook Mac OS X (10.4.8)

Message was edited by jaydisc to include $_SERVER info

Mar 23, 2007 3:33 PM in response to Tom Wootton

I thought I would be able to retrieve the same information by using something like

<?php
$referrer = $_SERVER['HTTP_REFERRER'];
echo "referrer is: $referrer \n";
?>

but alas, no referrer gets output... other elements of $_SERVER array can get output, such as HTTP_USER_AGENT, but not the HTTP_REFERRER.

So to see which elements were populated by default, I saved the following script as show_elements.php

<?php
print_r($_SERVER);
?>

and when I point my browser to this file, it yields:


Array ( [DOCUMENT_ROOT] => /Library/WebServer/Documents/my.example.com [HTTP_ACCEPT] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8 ,image/png,*/*;q=0.5 [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_ACCEPT_ENCODING] => gzip,deflate [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5 [HTTP_CONNECTION] => keep-alive [HTTP_HOST] => my.example.com [HTTP_KEEP_ALIVE] => 300 [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11 [PATH] => /bin:/sbin:/usr/bin:/usr/sbin:/usr/libexec:/System/Library/CoreServices [REMOTE_ADDR] => ##.##.##.###(my.remote.ip) [REMOTE_PORT] => 54136 [SCRIPT_FILENAME] => /Library/WebServer/Documents/my.example.com/show_elements.php [SCRIPT_URI] => http://my.example.com/show_elements.php [SCRIPT_URL] => /show_elements.php [SERVER_ADDR] => 192.168.2.224 [SERVER_ADMIN] => admin@example.com [SERVER_NAME] => my.example.com [SERVER_PORT] => 80 [SERVER_SIGNATURE] =>
Apache/1.3.33 Server at my.example.com Port 80
[SERVER_SOFTWARE] => Apache/1.3.33 (Darwin) mod_jk/1.2.6 DAV/1.0.3 mod_ssl/2.8.24 OpenSSL/0.9.7i PHP/4.4.1 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /show_elements.php [SCRIPT_NAME] => /show_elements.php [PATH_TRANSLATED] => /Library/WebServer/Documents/my.example.com/show_elements.php [PHP_SELF] => /show_elements.php [argv] => Array ( ) [argc] => 0 )


The php manual says that the entries of the $_SERVER array are set by the web server, so, the question, in my mind, is how to get Apache to populate the HTTP_REFERRER element of the $_SERVER array?

I would find this useful for tracking effectiveness of link exchanges, paid advertising, and much more, and would love it if this topic gets resolved...

Dual G4 colocated xserves Mac OS X (10.4.7)

Mar 23, 2007 4:17 PM in response to jaydisc

sorry... variable names don't work when they are mispelled...

the $ SERVER['HTTPREFERER'] works great. I made an arbitrary file called origin.html that just contained a link to a php script duely named referer.php, which was just

<?php
$referer=$ SERVER['HTTPREFERER'];
echo "referring page was: $referer\n";
?>

and when I pointed browser to the origin page and clicked on link to the referer.php script, the result was

referring page was: http://my.example.com/orgin.html

So it works.


Thanks jaydisk.


Dual G4 colocated xserves Mac OS X (10.4.7)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

PHP $_REQUEST['URL'] and $_REQUEST['title'] not working

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.