Go Back   Free website templates > Web Template Help > PHP and MySQL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read


Join now to download all the free website templates or post on the forum. If you have never been on a forum before read the FAQ. It's quick, easy and free to join!
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-27-2008, 06:23 PM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Post PHP Refer

Hi folks,
I need a script which enables me to refer users to a specific websites according to a parameter.

Example:
URL of page with script: www.abc.de/page.php?out=vareside.com
Refered to URL: www.vareside.com

How to do this? Tutorials, links, snippets or hints are welcome.
Reply With Quote
  #2 (permalink)  
Old 06-29-2008, 02:29 AM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,360
ishkey will become famous soon enough
Default

Better to use $_SERVER["HTTP_REFERER"] to know the referer URL. If the user followed a link to the current page then the referer is theURL that the user has come to the current page from. If they typed in the URL directly or came from their bookmarks then the referer is generally empty. PHP makes the referer automatically available in the variable: $HTTP_REFERER - the url the client just came from. The referer is actually stored in an environment variable which you canget using getenv():

A basic script
<?php
if (!isset($_SESSION['referrer'])) $_SESSION['referrer']=$_SERVER['HTTP_REFERRER'];
if((strpos($a, 'www.foo.com') > -1) || ($a == ''))
{
// good referer
}

?>
__________________
RIF= Reading Is Fun - Understanding Funner
cleandeck - lawn mower undercoating and wilmargraphite - graphite lubricants
Reply With Quote
  #3 (permalink)  
Old 06-29-2008, 11:37 AM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Default

Thanks, but isn't the following script much better?

<?
foreach ($_GET as $key => $value) {
$site .= $key."=".$value."&";
}
$site = substr($site, 4, -1);
intact
?>
<?php
header("location:$site");
?>
Reply With Quote
  #4 (permalink)  
Old 07-05-2008, 12:31 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,360
ishkey will become famous soon enough
Default

I have been looking at this one and it would depend upond your version of php.
the foreach construct in php 4 gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it.
Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset(). You will get extremely hard-to-find bugs if you leave out the unset().

$_GET['id'] In PHP 4.2.0 and later, the default value for the PHP directive register globals is off. To get DOCUMENT_ROOT you'll use $_SERVER['DOCUMENT_ROOT']

substr Returns the portion of string specified by the start and length parameters.
substr($site, 4, -1); If start is negative, the returned string will start at the start 'th character from the end of string. If start is non-negative, the returned string will start at the start 'th position in string , counting from zero. so I'm not understanding the 4.
__________________
RIF= Reading Is Fun - Understanding Funner
cleandeck - lawn mower undercoating and wilmargraphite - graphite lubricants
Reply With Quote
  #5 (permalink)  
Old 07-05-2008, 02:39 PM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Default

Thanks.

Max
Reply With Quote
  #6 (permalink)  
Old 07-05-2008, 03:43 PM
ishkey's Avatar
Moderator
 
Join Date: Aug 2007
Location: North GA USA
Posts: 1,360
ishkey will become famous soon enough
Default

Here is a Java IP (InetAddress) Locator from SourceForge
Java and ColdFusion libraries to lookup country code and language from IP address. It uses a local copy of the WHOIS database to perform fast, accurate lookups of country codes. Useful for log analysis, internationalization, geolocation, etc..
http://sourceforge.net/projects/javainetlocator/

How about taking the variables from the script and passing them to a php file to process the reffer site. Most people have java turned on, you would only miss out on private servers. And why not set a cookie so when they return you can process them.
__________________
RIF= Reading Is Fun - Understanding Funner
cleandeck - lawn mower undercoating and wilmargraphite - graphite lubricants
Reply With Quote
  #7 (permalink)  
Old 07-05-2008, 05:09 PM
vareside's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 254
vareside is on a distinguished road
Default

Thank you very much.
Reply With Quote
  #8 (permalink)  
Old 07-12-2008, 10:38 PM
Junior Member
 
Join Date: Jul 2008
Posts: 2
DanielXP is on a distinguished road
Default

PHP Code:
<?
header
("Location: " $_GET[out])
?>
Reply With Quote
  #9 (permalink)  
Old 07-13-2008, 03:41 PM
pezboy45's Avatar
Mod/Design & Coder [Pro]
 
Join Date: Nov 2006
Location: Hawaii
Posts: 686
pezboy45 is on a distinguished road
Send a message via AIM to pezboy45 Send a message via MSN to pezboy45
Default

Quote:
Originally Posted by DanielXP View Post
PHP Code:
<?
header
("Location: " $_GET[out])
?>
where do you define which link corresponds to which outside link?
__________________


If I ever don't follow up on something, please feel free to PM me. I've got a lot going on, so a friendly reminder helps.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:57 PM.



mouseover mouseover mouseover