| Welcome to Webforumz.com. |
|
Apr 30th, 2008, 19:32
|
#1 (permalink)
|
Join Date: May 2007
Location: Buffalo
Posts: 241
|
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.
|
|
|
May 1st, 2008, 13:17
|
#2 (permalink)
|
|
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
|
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
|
|
|
May 1st, 2008, 14:56
|
#3 (permalink)
|
Join Date: May 2007
Location: Buffalo
Posts: 241
|
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.
|
|
|
May 1st, 2008, 18:19
|
#4 (permalink)
|
|
Chief Moderator
Join Date: Oct 2007
Location: UK
Posts: 715
|
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
|
|
|
May 1st, 2008, 18:59
|
#5 (permalink)
|
Join Date: May 2007
Location: Buffalo
Posts: 241
|
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.
|
|
|
May 1st, 2008, 20:06
|
#6 (permalink)
|
|
Section Manager - Website Critique
Join Date: May 2007
Location: inside the outside
Posts: 1,095
|
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.
|
|
|
May 1st, 2008, 20:14
|
#7 (permalink)
|
Join Date: May 2007
Location: Buffalo
Posts: 241
|
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.
|
|
|
May 1st, 2008, 21:19
|
#8 (permalink)
|
|
Chief Moderator
Join Date: Oct 2007
Location: UK
Posts: 715
|
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!
__________________
|
|
|
May 1st, 2008, 21:39
|
#9 (permalink)
|
|
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
|
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
|
|
|
May 1st, 2008, 22:56
|
#10 (permalink)
|
|
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,609
|
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...
|
|
|
May 2nd, 2008, 10:39
|
#11 (permalink)
|
|
Chief Moderator
Join Date: Oct 2007
Location: UK
Posts: 715
|
Re: Record the link you clicked to leave my page
Quote:
Originally Posted by aso186
|
You're not the only one 
__________________
|
|
|
May 3rd, 2008, 14:56
|
#12 (permalink)
|
|
Reputable Member
Join Date: Nov 2007
Location: India
Posts: 150
|
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.
|
|
|
May 3rd, 2008, 16:11
|
#13 (permalink)
|
|
Reputable Member
Join Date: Nov 2007
Location: India
Posts: 150
|
Re: Record the link you clicked to leave my page
|
|
|
May 3rd, 2008, 16:43
|
#14 (permalink)
|
|
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
|
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
|
|
|
May 3rd, 2008, 17:22
|
#15 (permalink)
|
|
Reputable Member
Join Date: Nov 2007
Location: India
Posts: 150
|
Re: Record the link you clicked to leave my page
Quote:
Originally Posted by CloudedVision
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?
Last edited by RohanShenoy; May 3rd, 2008 at 17:24.
|
|
|
May 3rd, 2008, 17:31
|
#16 (permalink)
|
|
Nerdy Moderator
Join Date: Feb 2008
Location: In My Own Little World
Age: 14
Posts: 521
|
Re: Record the link you clicked to leave my page
Quote:
Originally Posted by RohanShenoy
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.
|
| | | |