Reputation: 33
I have a php file that was given to me by a company that produces online coupons. The file is supposed to generate a dynamic url and then redirect you to that page. All they told me i needed to do was to create an echo call at the bottom. The $cpt is the only thing that should be dynamically generated in the url so this is what I have and it is not working properly.
<?php
//Generate cipher
function EncodeCPT($pinCode, $offerCode, $shortKey, $longKey){
$decodeX = " abcdefghijklmnopqrstuvwxyz0123456789!$%()*+,-.@;<=>?[]^_{|}~";
$encodeModulo = array_fill(0, 256, 0);
$vob[0] = $offerCode % 100;
$vob[1] = (($offerCode - $vob[0]) / 100) % 100;
for ($i = 0; $i < 61; $i++)
$encodeModulo[substr($decodeX, $i, 1)] = $i;
$pinCode = strtolower($pinCode) . strval($offerCode);
if (strlen($pinCode) < 20){
$pinCode .= ' couponsincproduction';
$pinCode = substr($pinCode, 0, 20);
}
//$checkCode = "LC";
//$pinCode = "LC10";
//$offerCode = "115694";
//$shortKey = "6oigl3qf5e";
//$longKey = "Lm9A7w8tjpUCaoMidGFSYXrHZnyDRKhlTbk1Oz4f5QBsqveEWuxg6PNV2cJ3I";
$q = 0;
$j = strlen($pinCode);
$k = strlen($shortKey);
$s1 = $s2 = $s3 = null;
$cpt = '';
for ($i = 0; $i < $j; $i++){
$s1 = $encodeModulo[substr($pinCode, $i, 1)];
$s2 = 2 * $encodeModulo[substr($shortKey, $i % $k, 1)];
$s3 = $vob[$i % 2];
$q = ($q + $s1 + $s2 + $s3) % 61;
$cpt .= substr($longKey, $q, 1);
}
return $cpt;
}
echo("http://bricks.coupons.com/enable.asp?0=115694&c=LC&p=LC10&" .$cpt);
//echo '<META HTTP-EQUIV="Refresh" Content="0; URL=http://bricks.coupons.com /enable.asp?0=115694&c=LC&p=LC10&"($cpt)">';
?>
I have tried a couple things but nothing seems to be working. Does any one have any ideas? Thank you in advance.
Upvotes: 0
Views: 737
Reputation:
In your code you’ve defined the function EncodeCPT
but you’ve never actually called it. You may think of function definitions as separate from other parts of your script. Any variable used inside a function (unless used with the global
keyword) has only a local scope. Therefore, the variables $pinCode
, $offerCode
, $shortKey
, $longKey
and $cpt
don’t even exist outside the scope of your function (if in doubt, check it with isset
). To make them exist, you have to do something like the following:
/* Change these values if necessary */
$pinCode = "LC10";
$offerCode = "115694";
$shortKey = "6oigl3qf5e";
$longKey = "Lm9A7w8tjpUCaoMidGFSYXrHZnyDRKhlTbk1Oz4f5QBsqveEWuxg6PNV2cJ3I";
/* Do not change after this line */
$cpt = EncodeCPT($pinCode, $offerCode, $shortKey, $longKey);
$url = "http://bricks.coupons.com/enable.asp?0=115694&c=LC&p=LC10&".$cpt;
In spite of having identical names, $pinCode
, $offerCode
, $shortKey
, $longKey
and $cpt
are global variables in the code above. To avoid confusion, you may use different names like $a
, $b
, $c
, $d
, $e
or any valid variable names of your choice. For a clearer understanding of the matter, read more about variable scope from the PHP manual.
Now comes the redirect part. If you want the script to redirect automatically:
header("location: $url");
On the other hand, if you want the user to click on a link for the redirect:
print("<a href=\"$url\">Click Here</a>");
Upvotes: 1
Reputation: 500
if you want to use the return value of the function EncodeCPT($pinCode, $offerCode, $shortKey, $longKey) You need to find where this function is called and do something like this:
$cpt = EncodeCPT(parameter1,parameter2,parameter3,parameter4);
and at the end of the script you can then use $cpt, as mentioned by someone else.
header("location:http://bricks.coupons.com/enable.asp?0=115694&c=LC&p=LC10&$cpt");
Upvotes: 0
Reputation: 68556
Just use header()
Replace this
echo("http://bricks.coupons.com/enable.asp?0=115694&c=LC&p=LC10&" .$cpt);
with
$cpt = EncodeCPT("yourparameters");
header("location:http://bricks.coupons.com/enable.asp?0=115694&c=LC&p=LC10&$cpt");
Upvotes: 2