Jump to content

Help with Array


young_coder

Recommended Posts

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" => "http://yahoo.com",

"google" => "http:// google.com"

);

 

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

 

http://yahoo.com.

 

<?php

//Standalone CPA Redirector v2.1 with multioffers

//Settings http://dexony.com/insurance2/?mn=google

//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 http://www.yourdomain.com/?mn=offernumber


$offers = array ( 
"",                          // must be empty 
"http://www.yahoo.com/",     // ?mn=1
"http://www.google.com/"     // ?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="' . 'http://'.$_SERVER['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="' . 'http://'.$_SERVER['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( "/^www\./", "", $_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> 

 

Link to comment
https://forums.phpfreaks.com/topic/228512-help-with-array/
Share on other sites

The easiest method is a "lookup" array - otherwise you would pretty much rewrite the whole "redirector" code.

 

Make the lookup array like so:

// MAKE SURE that the values correspond to the keys in the $offers array!
$loopkup = array(
"yahoo" => 1,
"google" => 2
);

 

Then make a little switch that will use the lookup table, you can code it so you can use numbers or strings quite easily.

// This will let your code take EITHER; the number, or the string;
if(isset($_GET['mn']) && is_string($_GET['mn'])){
// Is string, use lookup array

// First always error-check, does this item exist?
if(isset($lookup[$_GET['mn']])){
	$offer_id = $lookup[$_GET['mn']];
}else{
	// Error - The requested redirect wasn't found
}
}else if(isset($_GET['mn']) && is_numeric($_GET['mn'])){
// Is number, use as-is
$offer_id = $_GET['mn'];
}else{
// Error handling - not a number OR a string.
}

 

Then you just edit this part:

if (isset($offer_id)) {
$magic_number = $offer_id - $safemode;

 

 

Hope this helps

Link to comment
https://forums.phpfreaks.com/topic/228512-help-with-array/#findComment-1178256
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.