How can I Decrypt and Redirect to a Different Link?

3 replies
Hi,

I would like to do this:

Redirect http://mindreality.com/cb/?a=btXAypit2&p=2

To: http://mindreality.com/ez/go.php?offer=pelmansec&pid=2

What happens is that "btXAypit2&" is an encrypted ClickBank id, and I know the key code such as "a" = "2", "b" = "s", "1" = "8" etc...

I would like to be able to do TWO Things.

1. Decrypt a certain part of a URL

2. Redirect to another URL with the data

3. Transform and Pass other parameters as well such as "&p=2" becomes "&pid=2"

What I am really trying to do is to redirect all "ClickBank Hopguard" Affiliate links to "Easy Click Mate" Affiliate links.

So the above method is a way do it. I just need to know how to implement the exact code/script required. I think it would be uploaded to the folder where my hopguard is installed "http://mindreality.com/cb/"

Any suggestions?
#based #code #decrypt #link #redirect
  • Profile picture of the author Worrier9001
    You can do this with javascript. I don't know php, but I am sure you can do it with php as well. In the example, the encrypted clickbank id should be "btXAypit2" without the ampersand as the ampersand separates parameters.

    You can do this by adding this javascript to the page you are working in at:

    "http://mindreality.com/cb/"

    The default page there "index.html" or "default.php", whatever it may be called.

    Here is the javascript:

    Code:
    <script type="text/javascript">
    
    function getParameterByName(name) {
        name = name.replace(/[[]/, "[").replace(/[]]/, "]");
        var regex = new RegExp("[?&]" + name + "=([^&#]*)"),
            results = regex.exec(location.search);
        return results == null ? "" : decodeURIComponent(results[1].replace(/+/g, " "));
    }
    
    function redirect()
    {	
    	var a = getParameterByName('a');
    	var p = getParameterByName('p');
    	
    	window.location.href = 'http://mindreality.com/ez/go.php?offer=' + a + '&pid=' + p;
    }
    
    </script>
    And in the html, you would call the redirect method like this:

    HTML Code:
    <body onLoad="redirect()">
    </body>
    {{ DiscussionBoard.errors[8801662].message }}
    • Profile picture of the author MindReality
      Thanks!

      I'm trying to understand how the code works.

      Starting with: How does it know which part of the link I am trying to read?
      Signature
      Discover The Greatest Secrets Of The Mind And Reality That Will Get You Anything You Desire, Almost Like Magic! Visit: http://www.MindReality.com
      {{ DiscussionBoard.errors[8802507].message }}
      • Profile picture of the author Worrier9001
        Originally Posted by MindReality View Post

        Thanks!

        I'm trying to understand how the code works.

        Starting with: How does it know which part of the link I am trying to read?
        The function called "getParameterByName(name)" (which is originally created by the stackoverflow community at: jquery - How can I get query string values in JavaScript? - Stack Overflow) accepts a string value which represents the query parameter name and returns to us a string value which represents that query parameter's value. In our case, the 2 query parameter names are "a" and "p", and in our example, it will return "btXAypit2" when we call "getParameterByName('a')" and it will return "2" when we call "getParameterByName('b')".

        Looking at the function in more detail, it first defines a Regular Expression (the variables "name" and "regex" which will be used to parse the query string. It will separate out the different parts of the query string, which starts with a question "?" and is separated by ampersands "&" and the values defined with an equal sign "=".

        The entire querystring is then gotten using "location.search", which should return to us "?a=btXAypit2&p=2", so by calling regex.exec against that text, we are able to separate out the different text values of each parameter because our Regular Expression will separate it out based on those 3 characters (?, &, =) using the "name" variable to retrieve only the parameter we are interested in.

        Then there is an additional step for replacing plus signs with spaces, the decodeURIComponent will decode the encoded URL (for example a space in the url will be written as %20 so this will turn it back into a space to get the actual value).

        So in the end, this function will return the value for the provided querystring parameter name.

        The redirect() function simply calls that above function twice, once for each parameter ('a' and 'p')

        Then we call window.location.href which will redirect the user to a page, and we add our parameter values for offer and pid in the string as querystring values.

        Finally, in the HTML code, when the page loads, we want to perform the redirect operation right away, so we call redirect() when the body loads.

        Since you are going to be decrypting the clickbank id, you could do that in the redirect() method, right before the call to window.location.href, you could run your decrypt function for the 'a' parameter.
        {{ DiscussionBoard.errors[8802713].message }}

Trending Topics