-4

I want to grab the 7 digit number from the url of a browser as shown below:

www.example/?id=1122331 and add the 7 digit to another link.

This is the base of the link wwww.referece.com/ref and change to wwww.referece.com/ref1122331.

Angel Politis
  • 10,955
  • 14
  • 48
  • 66
  • For this, you should take a look at javascript, I guess. – meJustAndrew Jul 02 '16 at 23:57
  • It's unclear what you're asking. Do you just want to redirect the user? That is, send traffic from `www.example.com/?id=1122332` to `www.example2.com/ref1122332`? – elixenide Jul 03 '16 at 00:17
  • This is for a funnel used by many different affiliate. each affiliate has their own id. instate of duplication the funnel, I though we could do something www.example.com/?id=1122332 where the 7 digit is an id number of an affiliate. when they share this funnel with their lead the id will be concatenating to the sing up link. This is an example of sing up link www.example2.com/ref1122332 – Hanif Mohammadi Jul 10 '16 at 11:15

5 Answers5

0

Well for that I would recommend you to use PHP. To get the value of ID in PHP just do the following

<?php
    $id = $_GET['id']; //here we grab the 7 digits and place them into $id var
    // Now lets build the new link
    $link = "www.referece.com/ref".$id; //values are concatenated and we get www.referece.com/ref1122331
?>
Ahmad
  • 477
  • 2
  • 9
0

Option 1: You can do it client side using javascript, for example how-to-get-the-value-from-the-url-parameter

Option 2: You can do it server side (Java/Php/Python and so on - depend your server side language)

Community
  • 1
  • 1
Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
0

1) You can use PHP to do it from server-side as shown below:

<?php
    // Get the url of the browser
    $url = isset($_SERVER["REQUEST_URI"]) ?  $_SERVER["REQUEST_URI"] : "";

    // Get the 7-digit number
    $number = strpos($url, "=")>0 ? substr($url, strpos($url, "=")+1, strlen($url)) : "";

    // Add the 7-digit number to a new link and return it
    return $link = "wwww.referece.com/?ref=" . $number;
?>

2) Or, instead, to do it from client-side you can use JavaScript as follows:

// Get the url of the browser
var link = document.location.href;

// Get the 7-digit number
var number = (link.indexOf("=")) ? link.substr(link.indexOf("=")+1, link.length) : null;

// Add the 7-digit number to a new link and return it
var newLink = "wwww.referece.com/?ref=" + number;

[EDIT]: ↓

// Create button
var button = document.createElement("a");
button.setAttribute("href", newLink);
document.body.appendChild(button);
Angel Politis
  • 10,955
  • 14
  • 48
  • 66
  • Maybe I have not explain this well. This is what I want to achive I am using work Press. this is the website? http://onlinetradingfloors/id=0123456 "0123456" will change by each user. user can insert their unique number but the number is always 7 digit. i want to grap the 7 digit number and form the a new link for call to action button. – Hanif Mohammadi Jul 22 '16 at 16:11
  • That's exactly what my code does. Just put **`newLink`** in href. Check out me edit. – Angel Politis Jul 22 '16 at 17:05
0

Most typical solution involves server-side processing, either PHP, ASP, JSP

For JSP

<a href="wwww.referece.com/ref<%= request.getParameter("id") %>" 

would do it.

Client-side would be also possible with javascript.

Here is how to override the target of a link:

JavaScript function in href vs. onclick

And here is how to obtain the parameters:

How to retrieve GET parameters from javascript?

Community
  • 1
  • 1
0
document.location.href

This grab the page url. Lets say the original page ulr is this `https://stackoverflow.com/questions/

user entre this manually on the url. ?mid=123456 new URL `https://stackoverflow.com/questions/?mid=123456

now the goal is to extract this number 123456 and append to the new URL. this is a user pass parameter to action button through URL. each user parameter is unique and the length is always 7 digit.

Community
  • 1
  • 1