Solved: How do I pass a variable in the URL of a page into a href link on that page?

This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.


Thread Starter
May 27, 2005
so after users fill out a form on my website, they are taken to a confirmation page.

as this is happening, i am passing thru their email to the confirmation page using a variable generated by the form on the previous page and placed into the URL of the confirmation page.

so on the confirm page the url in the status bar looks like:[email protected]"

what i want to do is then place that email variable into a link on the confirmation page, something like:
<a href=" ADDRESS" >
<a href="[email protected]" >
<a href="[em]" >

just to give you an idea of what im trying to accomplish.

So when users click that link on the confirmation page, their email address is again passed thru to the next page.

essentially, i want to pass the same variable through two pages

the form is awebers, so with the following code within the <head></head> tags:
<script type="text/javascript">

var formData = function() {

    var query_string = ( ? (('#') != -1) ?,'#')) : : '';
    var elements = [];

    if(query_string) {
       var pairs = query_string.split("&");
       for(i in pairs) {
          if (typeof pairs[i] == 'string') {
              var tmp = pairs[i].split("=");
              elements[unescape(tmp[0])] = unescape(tmp[1]);

    return {
        display: function(key) {
            if(elements[key]) {
            } else {
              document.write("<!--If desired, replace everything between these quotes with a default in case there is no data in the query string.-->");


i can then print out the email that is being pass thru in the URL onto the confirmation page with the code below :

<script type="text/javascript">formData.display("email")</script>
Of course, what I really want to do is somehow place what that code above prints out (the email) into a new href link on the confirmation page, not just display it. im just showing this to give more context...

not too bright with javascript or php so simple answers are nice :)

any help would be greatly appreciated, thanks!
Jul 2, 2006
You can get the variable from the url with a very simple piece of PHP:

<a href="index.php?em=<?php echo $_GET['em']; ?>">Click here</a>
Aug 12, 2007
The answer from andy is exactly correct, but the original poster should understand the security risks involved in this sort of code. For example, I could easily just type the url with my own (or any arbitrary) email address, like

Code:[email protected]
If you aren't handling the $_GET variables appropriately, then bad or unintended things can happen. One rule of thing is the use $_GET only to pass info between pages, but never to alter or access anything on the server (like in a database). To more securely pass information, you could use POST or session variables instead. These are much harder to fake.

I'm not saying it's wrong to use $_GET variables, I use them all the time. I'm just saying be aware of the risks and don't carry this example to another application that might be more security-centric.
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online