Web Design and Development Forums

Record the link you clicked to leave my page

This is a discussion on "Record the link you clicked to leave my page" within the PHP Forum section. This forum, and the thread "Record the link you clicked to leave my page are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > PHP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 30th, 2008, 19:32   #1 (permalink)
 
TheSealPortalTeam's Avatar
 
Join Date: May 2007
Location: Buffalo
Posts: 241
Blog Entries: 12
Record the link you clicked to leave my page

Because My site is a list of web sites and web portals I want to record hits, so when I show you a link to google.com and you click it. I want to record that event with out having google frown on me because I'm redirecting (which I already have a script to do, If i must)

Here is the script I'm using to write the mysql record of the "hit". First thing I need to do is get the URF for the web site then I can write the record.

The site is http://egtworlds.com

PHP: Select all

//This is the include statement that goes on top of the index.php page before a page is declared.
<?php
if (!($HTTP_REFERER) == '') {
include 
"core/pageprocess.php";
}
?>
Here is the real code called "PageProcess.php" it works with a hard coded value and when it is called with out the if statement above, but it doesn't work with the refer value. If thats even the right value.
PHP: Select all

<?php
include 'lang.php'
include_once 
'MySql.php';
$varWebId 0;
$varWebUserIp 0;
$varWebPage '';
$varWebScreenPage '';
$varType 0;
$varHasError 0;
$varWebPageId ='';

$varWebPageId $HTTP_REFERER;
$varWebUserIP $_SERVER['REMOTE_ADDR'];

echo 
$varWebPageId;

$con mysql_connect("localhost","a user name"," a password");                if (!$con)    
    {
        echo 
'Could not connect: ' mysql_error();
    }
            
    If (!
mysql_select_db("a database"$con)) {
        echo 
'Could not process: ' mysql_error();
    }
            
    
$varSqlString "Select * From websites"
    
$varSqlString $varSqlString " where WebPage like '" $varWebPageId  "%'";
    echo     
$varSqlString ;

    
$result mysql_query($varSqlString);
    
$varNumberOfRows mysql_num_rows($result);
    
    
    
    if (
$varNumberOfRows == 0) { 
    
$varHasError 1;
    echo 
'<div class="error"> Your Page could not be accessed</div>';
    
    } elseif (
$varNumberOfRows 1) {
    echo 
'<div class="error"> Your request returned to many websites</div>';
    
$varHasError 1;
    }
    
    while(
$row mysql_fetch_array($result)){
        
$varWebPage $row['WebHomePage'];
        
$varWebScreenPage $row['WebPage'];
        
$varWebPageId =  ($row[0]);
    }
    
mysql_close($con);

    if (
$varHasError == 0) {
    
$strSqlString "INSERT INTO webHits 
        (WebUrfId, WebUserIP) VALUES 
        ('" 
$varWebPageId "', '" $varWebUserIP "')";
    
WriteMySqlRecord($strSqlString);

    }
?>
This would be like Google recording web hits of there search engine. If they can do it, why can't I?
__________________
If only life came with an Energy Button.
If Firefox came bundled with Microsoft, I'd be happy.

Last edited by TheSealPortalTeam; Apr 30th, 2008 at 19:35.
TheSealPortalTeam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 13:17   #2 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
Blog Entries: 4
Re: Record the link you clicked to leave my page

What is $HTTP_REFERER equal to?
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 14:56   #3 (permalink)
 
TheSealPortalTeam's Avatar
 
Join Date: May 2007
Location: Buffalo
Posts: 241
Blog Entries: 12
Re: Record the link you clicked to leave my page

I have no idea, every time i try to print the value somewhere it doesn't. I think its just a blank value, I was told that $HTTP_REFERER is the site they are going to from my site.

I have no idea.
__________________
If only life came with an Energy Button.
If Firefox came bundled with Microsoft, I'd be happy.
TheSealPortalTeam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 18:19   #4 (permalink)
Chief Moderator
 
aso186's Avatar
 
Join Date: Oct 2007
Location: UK
Posts: 715
Blog Entries: 2
Send a message via Skype™ to aso186
Re: Record the link you clicked to leave my page

$_SERVER['HTTP_REFERER'] is the address that referred the user to your site i.e. the website the user came from.

It's not reliable though, since it's set by the user agent (the browser).

http://uk.php.net/manual/en/reserved...les.server.php
aso186 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 18:59   #5 (permalink)
 
TheSealPortalTeam's Avatar
 
Join Date: May 2007
Location: Buffalo
Posts: 241
Blog Entries: 12
Re: Record the link you clicked to leave my page

shoot, what I need is the ability to get the name of the site you clicked on to leave my site. Like how google keeps track of search inquires.
__________________
If only life came with an Energy Button.
If Firefox came bundled with Microsoft, I'd be happy.
TheSealPortalTeam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 20:06   #6 (permalink)
Section Manager -
Website Critique
 
welshstew's Avatar
 
Join Date: May 2007
Location: inside the outside
Posts: 1,095
Blog Entries: 10
Re: Record the link you clicked to leave my page

I don't think that is possible, because as soon as they are away from your site you loose connection, unless you plan on installing some spyware on every visitors machine, al la phorm.
__________________
WelshStew
Section Manager

tierney rides tboard - uk site : xtreme wales - extreme clothing
welshstew is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 20:14   #7 (permalink)
 
TheSealPortalTeam's Avatar
 
Join Date: May 2007
Location: Buffalo
Posts: 241
Blog Entries: 12
Re: Record the link you clicked to leave my page

its got to be possible, because google does it as well as many web directories.
__________________
If only life came with an Energy Button.
If Firefox came bundled with Microsoft, I'd be happy.
TheSealPortalTeam is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 21:19   #8 (permalink)
Chief Moderator
 
aso186's Avatar
 
Join Date: Oct 2007
Location: UK
Posts: 715
Blog Entries: 2
Send a message via Skype™ to aso186
Re: Record the link you clicked to leave my page

The only way you can do this is a redirect script (e.g. http://www.example.com?redirect=http...ernal-site.com).

This is exactly what Google does, more or less . Just check out the link href's in their search results!
__________________

aso186 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 21:39   #9 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
Blog Entries: 4
Re: Record the link you clicked to leave my page

lets say the file redirect/index.php is the file where you redirect the site to.

So each link going outside the site is sent to redirect/index.php, something like this:

HTML: Select all
<a href="redirect/?to=http://google.com">Google!</a>
redirect/index.php connects to the database, inserts the value of $_GET['to'] into the database, and then uses header("location: ".$_GET['to']) to send the user to the site.

This stone can also hit another bird. Use robots.txt to prevent any webcrawlers from going to redirect/index.php, thereby deleting (from the crawlers perspective) any outgoing links, which is a great SEO tactic.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 1st, 2008, 22:56   #10 (permalink)
Moderator
 
spinal007's Avatar
 
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
Blog Entries: 1
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: Record the link you clicked to leave my page

Am I the only one who can see the obvious confusion here?

HTTP_REFERRER is the address of the page where the user clicked on a link to come to your website. HTTP_REFERRER tells you where your visitors came from.

HTTP_REFERRER has absolutely nothing to do with anything that allows you to Record the link you clicked to leave my page.

Did you mean to ask something else? Or am I the one who's confused?

If you want to record the links people use to leave your pages, you can:
1. Use javascript (ajax) to make a call to a script that will register the click (and url) before the user leaves
OR
2. Use a redirection script (something like /go.php?url=XXX) where you can register the outgoing link, THEN redirect the user to whatever URL they clicked on

Google uses the 1st method, which requires a little more technical knowledge, but the 2nd method is very easy to implement and the most popular...
__________________
Diego - SEO Consultant London (My Blog | Fight Me)
jQuery: Star Rating - Multiple File Upload - FCKEditor/Codepress
Before we work on artificial intelligence why don't we do something about natural stupidity?
spinal007 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 2nd, 2008, 10:39   #11 (permalink)
Chief Moderator
 
aso186's Avatar
 
Join Date: Oct 2007
Location: UK
Posts: 715
Blog Entries: 2
Send a message via Skype™ to aso186
Re: Record the link you clicked to leave my page

Quote:
Originally Posted by aso186 View Post
$_SERVER['HTTP_REFERER'] is the address that referred the user to your site i.e. the website the user came from.

It's not reliable though, since it's set by the user agent (the browser).

http://uk.php.net/manual/en/reserved...les.server.php
You're not the only one
__________________

aso186 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2008, 14:56   #12 (permalink)
Reputable Member
 
Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Re: Record the link you clicked to leave my page

This is possible, its in my mind. Just give me some time. I will write down the script.
__________________
My w3 blog: w3hobbyist.com
RohanShenoy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2008, 16:11   #13 (permalink)
Reputable Member
 
Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Re: Record the link you clicked to leave my page

I am done.
Record the link that the visitor clicked to leave your site, track where your visitors go

__________________
My w3 blog: w3hobbyist.com
RohanShenoy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2008, 16:43   #14 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
Blog Entries: 4
Re: Record the link you clicked to leave my page

I wouldn't do it with javascript. Thats the lazy mans way out. I don't see why somebody couldn't just do the links by hand.

plus, the crawlers won't care about the javascript, so it'll still count as a link out of your site, which isn't good SEO.

And additionally, with the increasing popularity of no-script for firefox, anybody with javascript disabled won't be counted.
__________________
Take it easy

Other Road Design

WebForumz Moderator: HTML | Javascript | PHP
CloudedVision is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2008, 17:22   #15 (permalink)
Reputable Member
 
Join Date: Nov 2007
Location: India
Posts: 150
Blog Entries: 4
Re: Record the link you clicked to leave my page

Quote:
Originally Posted by CloudedVision View Post
I wouldn't do it with javascript. Thats the lazy mans way out. I don't see why somebody couldn't just do the links by hand.
How many links are you gonna convert that way? What is the use of having so many functions if we can't automate the tasks.

Quote:
plus, the crawlers won't care about the javascript, so it'll still count as a link out of your site, which isn't good SEO.
Why would one want to record where a SE bot left for? They would anyways follow all links.

Quote:
And additionally, with the increasing popularity of no-script for firefox, anybody with javascript disabled won't be counted.
Yes, this may be a barrier.
But javascript is used so much on the web nowadays that surfing with javascript cripples the usability of many websites. So even if most know that javascript could be used maliciously, they still have no option other than to let it function.

And even if the link is not recorded due to javascript being disabled, what great harm is it gonna cause?
__________________
My w3 blog: w3hobbyist.com

Last edited by RohanShenoy; May 3rd, 2008 at 17:24.
RohanShenoy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old May 3rd, 2008, 17:31   #16 (permalink)
Nerdy Moderator
 
CloudedVision's Avatar
 
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
Blog Entries: 4
Re: Record the link you clicked to leave my page

Quote:
Originally Posted by RohanShenoy View Post
Even if its a lazy man's way, it still needed some brain atleast more than what is needed for hand-coding it. And moreover, how many links are you gonna convert that way? What is the use of having so many functions if we can't automate the tasks.