0

Hello,

Could anyone help me with next problem:

Visitors come to a website through a Clickbank affiliatelink
http: //nick.vendor.hop.clickbank.net
But they will land on different websites based on an URL parameter, for example
http: //nick.vendor.hop.clickbank.net?x=prod1 they’ll go to www.websiteA.com
http: //nick.vendor.hop.clickbank.net?x=prod2 they’ll go to www.websiteB.com
http: //nick.vendor.hop.clickbank.net?x=prod3 they’ll go to www.websiteC.com

remark : nick is also variable (it is the affiliates name), so links could be:
http: //NICK.vendor.hop.clickbank.net?x=PROD1 or prod2 etc…
or
http: //JOHN.vendor.hop.clickbank.net?x=PROD1 or prod2 etc…
or
http: //CHARLES.vendor.hop.clickbank.net?x=PROD1 or prod2 etc…


Clickbank is linking to a page (based on the Clickbank account configuration) including following parameters, where a script will redirect the visitor to the right website
http: //www.mylandingwebsite.com/linkpage.php?hop=nick&x=prod1
So there are 2 variable parameters (value of hop and value of x)!

The problem is that with the ‘meta refresh content’ the parameters are not passed to the new URL.
For example:
The link http: //nick.vendor.hop.clickbank.net?x=prod1 should lead to or result in
http: //www.websiteA.com?hop=nick (with a 60 days cookie so that the affiliate still gets his commission if the visitor decide to come back later and buy). Obviously I only need the hop=’value’ at the final website.

This is the code I have so far (it leads to the right website based on ‘x=’ but it doesn’t pass the ‘hop=’ value , nick or john or charles or whatsoever)
Linkpage.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Doorlinken</title>
</head>

<body>
<?php
if(isset($_GET['x']))
{
if($_GET['x'] == "prod1")
{
echo '<meta http-equiv="refresh" content= "0;URL=http://www.websiteA.com" />';
}
elseif($_GET['x'] == "prod2")
{
echo '<meta http-equiv="refresh" content= "0;URL=http://www.websiteB.com" />';
}
elseif($_GET['x'] == "prod3")
{
echo '<meta http-equiv="refresh" content= "0;URL=http://wwwwebsiteC.com" />';
}
}
else echo '<meta http-equiv="refresh" content= "0;URL=http://www.website.com/products.php" />';

?>
</body>
</html>

So the result should be content= "0;URL=http://www.websiteA.com?hop=nick" or john or …
And do I need the head-section? Or just the script between < ?php and ? >

Thanks in advance for your help,

x

2
Contributors
10
Replies
11
Views
6 Years
Discussion Span
Last Post by belper
0

the code is wrong, those redirects belong in the <head>, but why ???
do a php redirect on the server, and seamlessly display only the correct page no html required

<?php if(isset($_GET['x'])) {
if($_GET['x'] == "prod1") { header( 'Location: http://www.websiteA.com'); }
elseif($_GET['x'] == "prod2") { header( 'Location: http://www.websiteB.com'); }
elseif($_GET['x'] == "prod3") { header( 'Location: http://wwwwebsiteC.com'); }
}
header( 'Location: http://www.website.com/products.php'); ?>

nothing but the correct page will be output to the browser

0

Hello,

I notice that I didn’t explain my problem clearly and simply enough.
So I will try to reformulate it.

Visitors come to a webpage through following URL
http: //www.mywebsite.com/linkpage.php?hop=affiliatename&x=productname
affiliatename is a variable parameter, so it can be anything
productname is also a variable parameter, and the value of it is used to redirect to another website;
Example:
If x=prod1 redirect to http: //www.websiteA.com
Or if x=prod2 redirect to http: //www.websiteB.com
Or if x=prod3 redirect to http: //www.websiteC.com
If none of these values redirect to http: //www.myotherwebsite.com

However the new URL should also contain the variable parameter hop=affiliatename
(from http: //www.mywebsite.com/linkpage.php?hop=affiliatename&x=productname)

So in case of
x=prod1 the new URL should be http: //www.websiteA.com?hop=affiliatename
x=prod2 the new URL should be http: //www.websiteB.com?hop=affiliatename
x=prod3 the new URL should be http: //www.websiteC.com?hop=affiliatename
or else http: //www.myotherwebsite.com?hop=affiliatename

and together with the new URL there should be set a 60 days cookie so that the affiliate still gets his commission if the visitor decide to come back later and buy.

Based on the parameter x=prod redirect to a new website is not a problem. It is working in my script (maybe a newbie script, but it is working. However a more simple and/or professional script would be welcome). The real problem is that the variable parameter hop=affiliatename should be passed in the new URL and to set a 60 days cookie.

I really hope I exposed my problem more clearly now.

Once again thanks in advance to everyone willing to help me.

0
<?php if(isset($_GET['x'])) {
$keyarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c'); /* an unlimited number of codes, linked to parts of website names
I hit abc, but they could be everything of the name, or as much as is needed to differentiate
cookie handling out of the php manual */
header( 'Location: http://www.website'.$keyarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']); 
}
else header( 'Location: http://www.website.com/products.php'); ?>

just a possibility

Edited by almostbob: n/a

0

Hurray almostbob,

This is working!
Except for 1 thing:
when there IS a URL parameter x but the value is something else than A, B or C, the server isn't found.
In this case the visitor should also be redirected to the same site as the 'else header' (http: //www.myotherwebsite.com or in your solution example http: //www.website.com/products.php)
I tried to figure out how to do it, based on your solution, but didn't find the solution yet (still too noob probably).

Would you be so kind to give me another helping hand?

Many many thanks.

Edited by belper: n/a

0
<?php if(isset($_GET['x'])) {
$keyarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c'); /* an unlimited number of codes, linked to parts of website names
I hit abc, but they could be everything of the name, or as much as is needed to differentiate
cookie handling out of the php manual */
header( 'Location: http://www.website'.$keyarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']); 
}
else header( 'Location: http://www.website.com/products.php'); ?>

just a possibility

-

Edited by belper: n/a

0

Dear almostbob,

Now I have this code:

<?php if(isset($_GET['x'])) {
$keyarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c'); /* an unlimited number of codes, linked to parts of website names
I hit abc, but they could be everything of the name, or as much as is needed to differentiate
cookie handling out of the php manual */
if(!in_array($_GET['x'],$keyarr) { header( 'Location: http://www.website.com/products.php'); }
header( 'Location: http://www.website'.$keyarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']); 
}
else header( 'Location: http://www.website.com/products.php'); ?>

but it gives a syntax error in line 5
and if I put in line 6

else { header( 'Location: http://www.website'.$keyarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']); 
}

it gives a syntax error on line 5, 6 and 8

I tried to understand, re-reading PHP manual, change quotes, brackets... but still doesn't work.
I feel so stupid...
Lucky-me there are people like almostbob to help and teach me.

I asked a few php 'specialists' close to my home (since a few years I am living in Peru) but they couldn't help me?????

Edited by belper: n/a

0

the benefits of code highlighting, I didnt use one, so left out a cloasing baracket

if(!in_array($_GET['x'],$keyarr)) { header( 'Location: http://www.website.com/products.php'); }

everything after that is wrong,
tighter code

<?php if(isset($_GET['x'])) {
$prodarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c'); 
$keyarr = array_keys( $prodarr); 
if(in_array($_GET['x'],$keyarr)) { header( 'Location: http://www.website'.$prodarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']);  }}
header( 'Location: http://www.website.com/products.php'); ?>


if x is set
create fast search array of the products (great for huge product lists, I expect your business to grow)
check search array for x, on my wamp install, creating the key array is faster if there are more than 10 products than searching the 2 element array
if x found in array go to the the page,
goto default page

Edited by almostbob: n/a

0

or you can have this page BE products.php if the $_get values arent set

<?php if(isset($_GET['x'])) {
$prodarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c'); 
$keyarr = array_keys( $prodarr); 
if(in_array($_GET['x'],$keyarr)) { header( 'Location: http://www.website'.$prodarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']);  }}
include('http://www.website.com/products.php'); ?>

Edited by almostbob: n/a

0

the benefits of code highlighting, I didnt use one, so left out a cloasing baracket

if(!in_array($_GET['x'],$keyarr)) { header( 'Location: http://www.website.com/products.php'); }

everything after that is wrong,
tighter code

<?php if(isset($_GET['x'])) {
$prodarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c'); 
$keyarr = array_keys( $prodarr); 
if(in_array($_GET['x'],$keyarr)) { header( 'Location: http://www.website'.$prodarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']);  }}
header( 'Location: http://www.website.com/products.php'); ?>


if x is set
create fast search array of the products (great for huge product lists, I expect your business to grow)
check search array for x, on my wamp install, creating the key array is faster if there are more than 10 products than searching the 2 element array
if x found in array go to the the page,
goto default page

Dear almostbob,

Your solution:

<?php if(isset($_GET['x'])) {
$prodarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c'); 
$keyarr = array_keys( $prodarr); 
if(in_array($_GET['x'],$keyarr)) { header( 'Location: http://www.website'.$prodarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']);  }}
header( 'Location: http://www.website.com/products.php'); ?>

When testing it, the visitor is always redirected to
http: //www.website.com/products.php ??????
I've tried to understand why but without result...


Your solution:

<?php if(isset($_GET['x'])) {
    $prodarr = array('prod1' => 'A', 'prod2' => 'B','prod3'=> 'c');
    $keyarr = array_keys( $prodarr);
    if(in_array($_GET['x'],$keyarr)) { header( 'Location: http://www.website'.$prodarr[$_GET['x']].'com?x='.$_Get['x'].'&hop='.$_GET['hop']); }}
    include('http://www.website.com/products.php'); ?>

If x=prod1 or prod2 o prod3 ==> it is working jus fine.
When x does not exist or is a nonvalid value,then it
isn't working because my hosting (godaddy) has PHP5 and doesn't allow the function 'include'
(explanation here : http: //blog.everymanhosting.com/php-coding/warning-include-functioninclude-url-file-access-is-disabled-in-the-server-configuration/ )

So the problem is solved when I use include(products.php).

However it can also be done when I put all the code at the very beginning of my page 'www.website.com/products.php'.
Logical not? But I didn't understand it before. When x does not exist or is a nonvalid value, just follow the 'normal' procedure on the page 'products.php', in other words the 'else statement' has not to be executed.

I also found another solution, used by other Clickbank vendors and that seems to do the job as needed for a Clickbank vendor.

Create a page (let us call it redirect.php)

<?php
$redirects = array(
“prod1″ => “http://www.websiteA.com”,
“prod2″ => “http://www.websiteB.com”,
“prod3″ => “http://www.websiteC.com”
);
$x = $_GET["x"];
if (array_key_exists($x, $redirects)) {
$go = $redirects[$x];
header(“Location:$go”);
die();
}
?>

In the landing page http: //www.website.com/products.php (this was the page in my example if x did not exist or if x=non valid value) add this code:

<?php include(“redirect.php”); ?>

Remark: 1/ This line has to be at the very very start of that page, so it has to be the very first line of your code on that page. 2/ Your landing page has to be a PHP extension. If your page is “http: //www.website.com/products.html” is has to be changed in “http: //www.website.com/products.php

I wish to thank all the people that helped me and provided ideas to solve this problem.

Edited by belper: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.