简体   繁体   中英

How to capture a “script tag” value and append it to a link

I have installed an "affiliate management software" in my hosting account.

I have created a landing page and I want my affiliates to promote this landing page. Each affiliate will have a unique affiliate link.

Each affiliate link has this format:

http://www.mywebsite.com/AM/index.php/uswername

The flow of the process is: Customer clicks an affiliate link(for product 1) ---> Landing Page

In my landing page, I have included a script tag provided by the "affiliate management software". This script tag dynamically shows the affiliate's username on the page. The script tag format is:

<script src="http://www.mywebsite.com/AM/js/show/username"> </script>

This is the description of the script tag by the "affiliate management software":

The Javascript API allows you to show specific affiliate data on external pages using simple Javascript calls. For example: <script src="http://www.mywebsite.com/affiliates/js/show/username"></script> . Once a user has clicked on an affiliate link, adding that javascript above to the landing page will show the referring affiilate's username on the page.

My Issue

In the landing page I have included another affiliate link (for product 2) and I want to append the affiliate's username to this link so that he get the commission from the sale of product 2.

I am trying to capture the value of a "script tag" and assign it to a variable. and then, print the value stored in the variable at the end of the 2nd affiliate link.

So my goal is basically capturing the username and then reprinted it at the end of the 2nd affiliate link. I want to capture the username printed by the script tag and append it to the 2nd affiliate link in the landing page, so that the 2nd affiliate_link will belong to the affiliate who initially referred the customer.


Here is a simple solution I came out with (but didn't work):

I created a form in my landing page:

<form action="go.php" method="get"> 
<script src="yourdomain.com/affiliates/js/show/username/field">; </script> 
</form> 

The reason for creating the form because, according to the "affiliate management software":

You can also show affiliate data in a hidden field, so that you can add hidden form fields to any web form that you want. Just append the field value to each javascript call, and it will do a javascript: document.write('<input type="hidden" name="username" value="joe">');

In go.php, I have the following code:

<?php $username = $_GET['username']; 
 header("Location: http://www.mywebsite.com/AM/index.php/$uswername); ?> 

First thing is that you need to concatenate the variable to the url, do this:

<?php 
    $username = $_GET['username']; 
    header("Location: http://www.mywebsite.com/AM/index.php" . &uswername); 
?> 
<?php 
$username = $_GET['username']; 
$url  = "http://www.mywebsite.com/AM/index.php".$uswername;
 header("Location: ".$url; ?> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM