Need Help With Short PHP Script

haydenm92

Junior Member
Joined
Apr 24, 2008
Messages
142
Reaction score
41
I'm new to PHP and I need help with a short script to put on a webpage.

Basically I want it to redirect the visitor someplace else if the referrer is blank, and if the referrer is anything else, then just leave them on the page.

There are a bunch of smart people around here, I'm sure someone will be able to help me. Any help is greatly appreciated, thanks in advance!

haydenm92
 
i wont give mine out for free as im planning to sell it in the future. it works exactly as you described it but it has better options etc,
 
I don't need much from the script, just a simple line that redirects if the referrer is blank.
 
this is incredibly easy, something like this:
Code:
$ref = $_SERVER['HTTP_REFERER'];

# if the referer is blank redirect to somewhere
if ($ref=='')

header("Location: http://yoursite1");

# if the referer is not blank redirect to another place
else header("Location: http://yoursite2");
 
hmm, not sure if that'll work without squiggly brackets - and haydenm92 doesn't know much PHP so -
PHP:
$ref = $_SERVER['HTTP_REFERER'];

# if the referer is blank redirect to somewhere
if ($ref==''){

header("Location: http://yoursite1");
die();

# if the referer is not blank redirect to another place
} else {
header("Location: http://yoursite2");
die();
}
 
This should leave you on the same page if your still looking
Code:
<?php 
if($_SERVER['HTTP_REFERER'] == NULL)
{
	header("HTTP/1.1 301 Moved Permanently");
	header("Location: http://www.example.com/");
	exit;
}
?>
<html>
blah blah blah
</html>
 
Alright, great, so the script is working, but that's only if I post it it like this:

Code:
<?php
$ref = $_SERVER['HTTP_REFERER'];

# if the referer is blank redirect to somewhere
if ($ref==''){

header("Location: http://yoursite1");
die();

# if the referer is not blank redirect to another place
} else {
header("Location: http://yoursite2");
die();
} 
?>

and save it to test.php

when I try to add some html though, it doesn't work. How can I add this PHP script in an html page??
 
Ok, let me give a quick rundown of my situation so everyone can understand what I'm trying to do.

I'm sure you've all heard of and are may be using BHCB. Well faking the referrer isn't supported, but can be done. The way that was explained to me is to send the your link to your white hat site. Then in your white hat site, put a bit of php code stating that if your referrer is blank, it'll forward to your CPA offer.

Obviously BHCB blanks the referrer, so any traffic from your black hat site would go to your white hat site, then the CPA offer so it looks like the referring site is your white hat site.

This may sound good, but after thinking about it, what if my AM types my white hat site into his URL? He'll be redirected to CPA offer and I'll be done.

So my idea was to turn off blanking in BHCB, but still send the traffic to your white hat site. Put a bit of php code in your white hat site saying if the referrer is your black hat site, then pass traffic to the CPA offer, otherwise leave the traffic there. That way any blank traffic would stay on the site. I think this is the best way to do it, b/c if your AM is coming through your black hat site you're screwed anyways.

So basically I'm trying to find a code that I can put into my white hat site that will allow referring traffic from my blackhat site to pass on to my CPA offer.

Anyone know how to do this in php??

Thanks in advance!
 
If they are coming from your blackhat site you could do

if($_SERVER['HTTP_REFERER']=='myblackhatsite.something')
//do stuff

else
//dont because it is my aff manager

But if your driving traffic from multiple places this wont work
 
ohhh your looking for THAT redirect script.. ahh.. it should be floating around in the forum somewhere i think. it actually using a form post method to send the visitor off to the cpa offer from a blackhat site.. let me check my computer.. i think i have it
 
when I try to add some html though, it doesn't work. How can I add this PHP script in an html page??

You can't add php script to html page as far as i know, extension must be *.php in order to work.
 
If they are coming from your blackhat site you could do

if($_SERVER['HTTP_REFERER']=='myblackhatsite.something')
//do stuff

else
//dont because it is my aff manager

But if your driving traffic from multiple places this wont work

I'm only driving traffic to my CPA offer from one location, so something like that could work.

ohhh your looking for THAT redirect script.. ahh.. it should be floating around in the forum somewhere i think. it actually using a form post method to send the visitor off to the cpa offer from a blackhat site.. let me check my computer.. i think i have it

That would be absolutely great if you could find this because I've been trying to work this out for a while now. I've searched for forum high and low and haven't found any code that will do this.
 
Alright, I've found a way for this to work, just in case anyone was following this thread in hopes for an answer.

Check this post out:

Code:
http://www.blackhatworld.com/blackhat-seo/black-hat-seo/48908-cpa-redirector-standalone-version.html

Thx for eveyone's time, this really is the greatest forum ever!
 
You can't add php script to html page as far as i know, extension must be *.php in order to work.

Of course you can...

Add this to your .htaccess
Code:
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
and apache will parse .html files as if they were .php. See my post above for an example.
 
Back
Top