SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question if(!empty($HTTP_GET_VARS['j'])) - Help needed - script won't work!

    Hi all,

    I am having real trouble with a script at the mo and I have no idea why it don't work... I know it works on someone elses host (I think!) so is it just my host or can anyone point out an error with the script...

    PHP Code:
    <?php 

    $number_of_days 
    "20"
    $block="hilariousminds.com"// urls to block seperate by | 
    $number_of_referers "20"// number of referers to keep in the list 

    // enter your mysql username and password used to connect to database_name 

    $a=mysql_connect("localhost""*****""*****"); 
    $b=mysql_select_db("hilariousminds",$a); 

    if(!empty(
    $HTTP_GET_VARS['j'])) 

    $j=addslashes($HTTP_GET_VARS['j']); 
    $c=mysql_query("select id from TW_referers where url='$j' order by id desc limit 1"); 
    $d=mysql_fetch_object($c); 
    if(
    is_object($d)) 

    mysql_query("update TW_referers set hitsout=hitsout+1 where id={$d->id}"); 
    header("Location: http:\\/\\/$j"); 

    else echo 
    'send us some hits first :P'
    exit; 

    else 

    if(!empty(
    $HTTP_SERVER_VARS['HTTP_REFERER'])) 

    $HTTP_SERVER_VARS['HTTP_REFERER']=substr(addslashes(strip_tags($HTTP_SERVER_VARS['HTTP_REFERER'])),0,255); 
    eregi("^https?://([a-zA-Z0-9_\.\-]+)",$HTTP_SERVER_VARS['HTTP_REFERER'],$ref); 
    if(!
    eregi($block,$ref[1])) 
    mysql_query("insert into TW_referers (url,hitsout,time) values ('{$ref[1]}',0,'".time()."')"); 


    $c=mysql_query("select url,sum(hitsout) as hitsout,count(*) as hitsin from TW_referers group by url order by hitsin desc limit $number_of_referers"); 
    echo 
    '<table><tr><td>&nbsp;</td><td align=center>in</td><td align=center>out</td></tr>'
    while(
    $d=mysql_fetch_object($c)) 

    $d->url=stripslashes($d->url); 
    $do=explode('.',$d->url); 
    if(empty(
    $do[2])) 
    $do=$do[0]; 
    elseif(
    $do[0]=='www'
    $do=$do[1]; 
    else 
    $do=$do[0].'.'.$do[1]; 
    echo 
    "<tr><td><a href=\"{$HTTP_SERVER_VARS['PHP_SELF']}/inc/referers.php?j={$d->url}\" target=new>{$do}</a></td><td>{$d->hitsin}</td><td>{$d->hitsout}</td></tr>"
    unset(
    $do); 

    echo 
    '</table>'
    $seconds=time()-(60*60*24*$number_of_days); 
    mysql_query("delete from TW_referers where time < $seconds"); 

    ?>
    It just don't work... It doesn't add a new url to the DB and if I add one manualy then it deletes that also - or that could be becuase I left out the timestamp in the ones I added.

    It should take a referers URL and add it to the DB for 20 days and then display this referer's site address as a link with the number of hits out and the number of hits in...

    I doesn't!

    Many Thanks
    Rick
    Last edited by rboycey; Jan 28, 2002 at 12:32.
    RBoycey

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it is this line:

    PHP Code:
    header("Location: <a href="http://" target="_blank">[url]http://[/url]</a>$j"); 
    It looks like most of the line is being commented out. Could be wrong. Also check that register_globals is ON.

    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  3. #3
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What errors are you receiving? Why doesn't it work?
    Enlighten us.


    Cheers.

  4. #4
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by weirdbeardmt
    PHP Code:
    header("Location: <a href="http://" target="_blank">http://</a>$j"); 
    That's true, rewrite it something like this:
    PHP Code:
    header("Location: http://$j"); 

    Also check that register_globals is ON.

    register_globals isn't an issue here, because rboycey is accessing the variables with $HTTP_*_VARS.



    Cheers.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok...

    I have edited the script above... (changed that HeaderLine - that wasn't part of the script, just that SPF has autoparsed the http:// bit and made it a link and becuase it was inside [php] tags it had turned the link into safecode (I think! - well I assume)

    Errors: No errors spat out...

    It will display something if I add it manualy in the database but will delete it automaticly but as I said I guess thats becuase I left the timestamp off when I added in the DB

    Many Thanks for any help offered!

    Rick
    RBoycey

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What rick is trying to accomplish is take the referrers URL, add it to a db and echo that back as a link for 20 days....having said that, if the URL is manually entered in to the db, he gets his desired result. Which of course tells me that the problem is in the insertion portion of the script. Either it is not entering the referer into the db for whatever reason, or the referrer is not being registered.

    Rick, if I were you bud, I'd try some error checking. Try echoing the Referer variable back, and also verify that the data is actually making it from your script to the db.

    Sketch
    Aaron Brazell
    Technosailor




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •