By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,034 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,034 IT Pros & Developers. It's quick & easy.

Using SPLIT( ) to parse HTTP_REFERER

P: n/a
I'm very new to PHP and am trying to figure out how to parse out a
variable "HTTP_REFERER". My reason for this is my site was recently
"FEATURED" (sic) on a website called FARK.COM. Because of this I
received over 100,000 Hits in less then one hour and it caused my host's
server farm to crash. While I understand that I could move to a more
robust Web Host, I would rather trap any further links from FARK and
redirect them to a rejection page at the following URL.

http://www.angelfire.com/crazy/actua...farkreject.htm

In doing this I should be able to avoid another crash and save myself
some phenomenal bandwidth charges.

I tried the following code to attempt to isolate the word FARK from
HTTP_REFERER thinking that the 2nd element of the array would be FARK
(assuming that the HTTP_REFERER = "http://www.fark.com")

My expected output would be
$refer_array(1) = http://www
$refer_array(2) = fark
$refer_array(3) = com

However what I get is the following message
Parse error: parse error in /refer_test.php on line 11

Here is the Code I'm using to display the results
-------------------------------------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php //PHP ADODB document - made with PHAkt 2.2.0
PRINT HTTP_REFERER

$refer_array = split(".",HTTP_REFERER);
foreach ( $refer_array as $item )
print "$item<BR>";
?>
</body>
</html>
---------------------------------------------------------------------------------------------

Any help anyone could offer would be greatly appreciated by this
bumbling n00bie

Thanks
John

Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Mon, 21 Jul 2003 11:45:32 -0700, John A. Irwin wrote:
I'm very new to PHP and am trying to figure out how to parse out a
variable "HTTP_REFERER". My reason for this is my site was recently <snip!> Here is the Code I'm using to display the results
-------------------------------------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php //PHP ADODB document - made with PHAkt 2.2.0 PRINT HTTP_REFERER

$refer_array = split(".",HTTP_REFERER); foreach ( $refer_array as $item )
print "$item<BR>";
?>
</body>
</html>
---------------------------------------------------------------------------------------------

Any help anyone could offer would be greatly appreciated by this bumbling
n00bie

Thanks
John


First of all, HTTP_REFERER is not a reliable variable to use. However,
ignoring that aspect, try the following code:
<?php

$refer_array = split("\.",$_SERVER['HTTP_HOST']); foreach ( $refer_array as $item )
print "$item<BR>";
?>

You need to escape the dot "." with a backslash "\." and you also forgot
the dollar sign "$" indicating that HTTP_REFERER is a variable --
$HTTP_REFERER.
later...

--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/

Jul 16 '05 #2

P: n/a
Jeff that seemed to work just fine, Thanks for taking the time to respond.
Jeffrey Silverman wrote:
On Mon, 21 Jul 2003 11:45:32 -0700, John A. Irwin wrote:

I'm very new to PHP and am trying to figure out how to parse out a
variable "HTTP_REFERER". My reason for this is my site was recently


<snip!>
Here is the Code I'm using to display the results
-------------------------------------------------------------------------------------------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php //PHP ADODB document - made with PHAkt 2.2.0 PRINT HTTP_REFERER

$refer_array = split(".",HTTP_REFERER); foreach ( $refer_array as $item )
print "$item<BR>";
?>
</body>
</html>
---------------------------------------------------------------------------------------------

Any help anyone could offer would be greatly appreciated by this bumbling
n00bie

Thanks
John

First of all, HTTP_REFERER is not a reliable variable to use. However,
ignoring that aspect, try the following code:
<?php

$refer_array = split("\.",$_SERVER['HTTP_HOST']); foreach ( $refer_array as $item )
print "$item<BR>";
?>

You need to escape the dot "." with a backslash "\." and you also forgot
the dollar sign "$" indicating that HTTP_REFERER is a variable --
$HTTP_REFERER.
later...


Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.