Using SPLIT( ) to parse HTTP_REFERER

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John A. Irwin

    Using SPLIT( ) to parse HTTP_REFERER

    I'm very new to PHP and am trying to figure out how to parse out a
    variable "HTTP_REFER ER". 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.



    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>Untitl ed 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

  • Jeffrey Silverman

    #2
    Re: Using SPLIT( ) to parse HTTP_REFERER

    On Mon, 21 Jul 2003 11:45:32 -0700, John A. Irwin wrote:
    [color=blue]
    > I'm very new to PHP and am trying to figure out how to parse out a
    > variable "HTTP_REFER ER". My reason for this is my site was recently[/color]
    <snip!>[color=blue]
    > Here is the Code I'm using to display the results
    > -------------------------------------------------------------------------------------------
    > <html>
    > <head>
    > <title>Untitl ed 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[/color]

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

    $refer_array = split("\.",$_SE RVER['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/

    Comment

    • Actual Client

      #3
      Re: Using SPLIT( ) to parse HTTP_REFERER

      Jeff that seemed to work just fine, Thanks for taking the time to respond.


      Jeffrey Silverman wrote:[color=blue]
      > On Mon, 21 Jul 2003 11:45:32 -0700, John A. Irwin wrote:
      >
      >[color=green]
      >>I'm very new to PHP and am trying to figure out how to parse out a
      >>variable "HTTP_REFER ER". My reason for this is my site was recently[/color]
      >
      > <snip!>
      >[color=green]
      >>Here is the Code I'm using to display the results
      >>-------------------------------------------------------------------------------------------
      >><html>
      >><head>
      >><title>Untitl ed 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_arra y = 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[/color]
      >
      >
      > First of all, HTTP_REFERER is not a reliable variable to use. However,
      > ignoring that aspect, try the following code:
      > <?php
      >
      > $refer_array = split("\.",$_SE RVER['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...
      >[/color]

      Comment

      Working...