1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Advanced Php Issue - Will Give Green Rep For Help

Discussion in 'PHP' started by SeoVeteran33, Jun 11, 2008.

  1. #1
    My site is a video site and I just installed a link dump (phplinkdropper) into a subdirectory of the site. So I have:

    www.mysite.com - the video part
    www.mysite.com/link-dump - the link dump part
    SEMrush
    The problem is with the way the link dump script tracks hits in. The link dumps index.php (www.mysite.com/link-dump/index.php) must be called to track the hits in.

    So say someone arrives at www.mysite.com. No hits are tracked because the tracking code is part of the link dump index.
    Now if someone arrives at www.mysite.com/link-dump, hits are tracked just fine.


    So what I did was put the tracking code in its own php file and include it whenever www.mysite.com loads. Below is the file I made("http://www.mysite.com/link-dump/plugs.php"):

    The problem is that $_SERVER['HTTP_REFERER'] is "" while in this file. Both before and after the include, $_SERVER['HTTP_REFERER'] is setup perfectly.

    So:
    echo $_SERVER['HTTP_REFERER']; works perfectly
    include ("http://www.mysite.com/link-dump/plugs.php"); <-- while in here it doesn't work
    echo $_SERVER['HTTP_REFERER']; works perfectly

    <?php
    include ("config.php");
    include ("functions.php");
    
    	$referral = $_SERVER['HTTP_REFERER'];
    	$array=parse_url($referral);
    	$referral1 = $array['host'];
    	$referral2 = str_replace("www.", "", $referral1);
    	$referral3 = "http://".trim($referral2);
    	$referral4 = "http://www.".$referral2;
    	// If referrer is in database, then add a hit!
    	if (!empty($referral1)){
    	$add_hit = mysql_query("update links
    				 set totalin=totalin+1,
    				 dayin=dayin+1 
    				 where url like '$referral1%' || url like '$referral3%' || url like '$referral4%' LIMIT 1");
    
    	// Update the user & domain stats if it was a user domain who the hit came from
    	credit_user_domain($referral1,$referral2);
    	// End user and domain update
    
    	} 
    ?>
    PHP:

    How can I get $_SERVER['HTTP_REFERER'] to work in the include file?
     
    SeoVeteran33, Jun 11, 2008 IP
    SEMrush
  2. coffeesonnow

    coffeesonnow Peon

    Messages:
    34
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    include ("config.php");
    include ("functions.php");

    should probably be

    include ("full/path/to/your/script/config.php");
    include ("/and/full/path/to/your/script/functions.php");
     
    coffeesonnow, Jun 11, 2008 IP
    SeoVeteran33 likes this.
  3. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #3
    Man, why spend much time when it can be achieved in a simple way? If the file does not want to see the referrer, add a line to get the referrer before you include the file!

    $referrer = $_SERVER['HTTP_REFERER'];
    include ("http://www.mysite.com/link-dump/plugs.php");

    And in the plugs file, just treat $referrer with no need to use $_SERVER again!
     
    Lordo, Jun 11, 2008 IP
    SeoVeteran33 likes this.
  4. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    could just be
    include('../link-dump/plugs.php');
    some servers dont allow including codebases on http:// urls.
     
    juust, Jun 11, 2008 IP
    SeoVeteran33 likes this.
  5. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #5
    I agrre with Lordo and explain bit more

    $referral=$_SERVER['HTTP_REFERER']; //In main index file
    include ("http://www.mysite.com/link-dump/plugs.php");

    In plugs.php
    <?php
    include ("config.php");
    include ("functions.php");
    //$referral = $_SERVER['HTTP_REFERER'];
    $array=parse_url($referral);
    $referral1 = $array['host'];
    $referral2 = str_replace("www.", "", $referral1);
    $referral3 = "http://".trim($referral2);
    $referral4 = "http://www.".$referral2; // If referrer is in database, then add a hit!
    if (!empty($referral1))
    {
    $add_hit = mysql_query("update links set totalin=totalin+1, dayin=dayin+1 where url like '$referral1%' || url like '$referral3%' || url like '$referral4%' LIMIT 1"); // Update the user & domain stats if it was a user domain who the hit came from
    credit_user_domain($referral1,$referral2); // End user and domain update
    }
    ?>
     
    kmap, Jun 12, 2008 IP
    SeoVeteran33 likes this.
  6. SeoVeteran33

    SeoVeteran33 Well-Known Member

    Messages:
    390
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #6
    Yeah I tried something similar to this. The problem is very much the same.

    When I do this:
    $referral=$_SERVER['HTTP_REFERER'];
    include ("http://www.mysite.com/link-dump/plugs.php");

    $referral is considered nil once I enter my include file. As soon as I leave the include file, $referral is its correct value again.

    I appreciate the help so far. Any other suggestions?
     
    SeoVeteran33, Jun 12, 2008 IP
  7. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #7
    a server side 'include' works on your server directory structure, it doesnt use the http protocol. The include function itself doesnt generate an error message if the library isn't found. So unless you set 'warnings' on, you wont know if the include fails.

    using an echo statement gives you some feedback.

    if you add a line to plugs.php
    echo 'okay';
    then you know if the include-function loads the file

    the http-include wont work
    so then you can try
    include('../link-dump/plugs.php');
    and that should produce that echo
     
    juust, Jun 12, 2008 IP
  8. SeoVeteran33

    SeoVeteran33 Well-Known Member

    Messages:
    390
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #8
    Ok, I left it as include ("http://www.mysite.com/link-dump/plugs.php"); and put an echo in "plugs.php". The echo displays so the include is functioning correctly.
     
    SeoVeteran33, Jun 14, 2008 IP
  9. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #9
    interesting
    i recreated it on my own server
    using a http:// include fails on my server because of an openbasedir restriction
    and a ../ reference works fine
    apart from that solution I wouldnt know any.
     
    juust, Jun 15, 2008 IP
  10. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #10
    This is the base ideas you can use :)


    <?php
    //plugs.php
    
    include ("config.php");
    include ("functions.php");
    
    class REFERER{
    
       public function check_referer($referer){
       
       
          // referer code here
       
       }
    
    }//class end
    
    
    
    //you can include and use your referer class in any page your website like this
    //let say you call from index.php
    
    //index.php
    
    include('plugs.php');
    
    $referer = new REFERER;
    $referer->check_referer($_SERVER['HTTP_REFERER']);
    
    //continue your code for this page 
    
    //done
    
    ?>
    PHP:
     
    php-lover, Jun 15, 2008 IP
    SeoVeteran33 likes this.
  11. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #11
    there must be some error in plugin.php

    Try to include other file with only line echo $refferal in plugin.php

    and see if it prints or not

    Regards

    Alex
     
    kmap, Jun 15, 2008 IP
  12. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #12
    is this all working as it should now?
     
    crath, Jun 15, 2008 IP
  13. SeoVeteran33

    SeoVeteran33 Well-Known Member

    Messages:
    390
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    108
    #13
    Thanks for all the help guys, I got it working now - phplover, I used a modified version of your suggestion to get it working thanks buddy.

    I left green rep to those suggesting code fixes.
     
    SeoVeteran33, Jun 25, 2008 IP