Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Array

Status
Not open for further replies.

youngcoder

Technical User
Nov 15, 2010
8
0
0
RS
Please, can somebody help me with this script? :(
This redirect script takes the number from the end of link and assigns to URL from array.
Number 1 is second element (yahoo), number 2 is third element (google) etc.
I would like to change number at the end of URL with keyword and put pairs in array like:

array (
"yahoo" => ""google" => "http:// google.com"
);

So, when somebody come on page via URL "domain.com/?mn=yahoo" I would like to redirected him to


PHP:
<?php
 
//Standalone CPA Redirector v2.1 with multioffers

//Settings [URL unfurl="true"]http://dexony.com/insurance2/?mn=google[/URL]

//put in your desired offers in the array below , you can add as many as you want , but make sure 

to enclose them with ""
// to match the desired domain you wonna link to , set the magicnumber to the position in the array 

below 
// to use your desired offer use [URL unfurl="true"]http://www.yourdomain.com/?mn=offernumber[/URL]


$offers = array ( 
"",                          // must be empty 
"[URL unfurl="true"]http://www.yahoo.com/",[/URL]     // ?mn=1
"[URL unfurl="true"]http://www.google.com/"[/URL]     // ?mn=2
);


//you can specify a safenumber here, what it does it sets the magicnumber of the offer you would 

like + it's value
//you normally don't need this, but if you don't want your magic numbers to start at 1 you can 

change it here
// example if you set this to 50 and you want to use your first number it would be index.php?mn=51
$safemode = 0;


//Don't edit below this line unless you know what you are doing.
$PHP_SELF = preg_replace( "/index.php/", "", $_SERVER['PHP_SELF'] );


if (isset($_GET['mn'])) {
$magic_number = $_GET['mn'] - $safemode;
$cpa_offer_url = $offers[$magic_number];
setcookie("mnval",$magic_number,time()+10,"/");
setcookie("cpaval",$cpa_offer_url,time()+10,"/");

	echo '<html><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"></head><body><form 

action="' . '[URL unfurl="true"]http://'.$_SERVER[/URL]['HTTP_HOST'].$PHP_SELF. '" method="post" id="form1">

<input type="hidden"  name="mn" value="' . $magic_number . '" /></form>

<script language="JavaScript"> 
	document.getElementById(\'form1\').submit();</script></body></html>';
		return true; 
		exit();
		
}

if (($_POST['mn']== $_COOKIE['mnval']) && (isset($_COOKIE['mnval'])))  {
$magic_number = $_COOKIE['mnval'];

	echo '<html><head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"></head><body><form 

action="' . '[URL unfurl="true"]http://'.$_SERVER[/URL]['HTTP_HOST'].$PHP_SELF. '" method="post" id="form1">

<input type="hidden"  name="mn" value="' . $magic_number . $magic_number . '" /></form>

<script language="JavaScript"> 
	document.getElementById(\'form1\').submit();</script></body></html>';
		return true; 
		exit();
}	

$dom = preg_replace( "/^[URL unfurl="true"]www\./",[/URL] "", $_SERVER[ 'HTTP_HOST' ] ) ;
$ref= $_SERVER['HTTP_REFERER'];


if (((strpos($ref, $dom)!=FALSE) || (trim($ref)=="" ) ) && (!isset($_GET['mn']))  && 

($_POST['mn']==$_COOKIE['mnval'].$_COOKIE['mnval']) && (isset($_COOKIE['mnval']))){
$cpa_offer_url = $_COOKIE['cpaval'];		
header( 'Location: ' . $cpa_offer_url);
		exit();
setcookie("mnval","",time()-60);
setcookie("cpaval","",time()-60);
	}


?>


<html>
  <head>
    <title>your fake landing page</title>
  </head>
  <body>
	<br><br><br><br>
	 <center><h1>text</h1></center>
 
  </body>
</html>
 
So what's the trouble?

Just set the offers array to your format:

Code:
$offers=array (
"yahoo" => "[URL unfurl="true"]http://yahoo.com",[/URL] 
"google" => "http:// google.com"
);

And Instead of the $magic_number variable just use your query string variable.

Code:
[s]
$magic_number = $_GET['mn'] - $safemode;
$cpa_offer_url = $offers[$magic_number];
[/s]
$offerId=$_GET['mn'];
$cpa_offer_url = $offer[$offerId];


Of note though is that if the value in 'mn' is not a valid index for your offers array you'll get Notices in that regard.

You may want to check for the existance of the keys.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top