Jump to content

Passing variable throught hyperlink


blogfisher

Recommended Posts

Hi,

I want to pass my variable value when someone click on hyperlink. However i don't want to pass along with '?' i.e.

 

<a href="http://site1.com?val=$num">link1</a>

 

Is there any other way ? As i have more than 50 links as below :

 

<a href="http://site1.com>Site1</a> - pass value 1 to site1.com

<a href="http://site2.com>Site2</a> - pass value 2 to site2.com

<a href="http://site3.com>Site3</a> - pass value 3 to site3.com

<a href="http://site4.com>Site4</a> - pass value 4 to site4.com

<a href="http://site5.com>Site5</a> - pass value 5 to site5.com

and so on...

 

Is it possible to pass through post method something like using form... ??

Edit/Delete Message

Link to comment
Share on other sites

How to do with form ? can you please give an example ?

 

well, i don't want to let user know about the value i am passing thought hyperlink. So i dont want to use ?val=something method...

 

form method below...but, a couple things. even with the form method, if the user wanted to, they could see what value is being passed. also, with the ?val=$num method, you can have the receiving page remove it after it gets the data:

<a href="http://site1.com?val=123">link1</a>

then on site.com/index.php, put the following code at the top of the page:

<?php
  if($_GET['val']){
    //do what you want with $val. add it to a database, or session or something
    //note though, that after the header statement below, $_GET won't exist anymore
    //so if you want the value for later in the page, put it in the SESSION
    
    //Redirect them back to this page without the $_GET
    header('Location: '.$_SERVER['PHP_SELF']);
    exit;
  }
  //continue with your page

?>

 

the form method would be:

<form id="form_<?php echo $num;?>" action="http://site1.com" method="POST">
  <input type="hidden" name="val" value="<?php echo $num;?>" />
  <a href="#" onclick="document.getElementById('form_<?php echo $num;?>').submit();">Site 1</a>
</form>

Link to comment
Share on other sites

if it's REALLY sensitive info, you can have the originating site post the data via CURL (so directly server to server). have site1 store that data in a database, and respond back with a random md5 hash (also but this hash in the database with the data sent). then, in the url, make it:

http://site1.com/?hash=<the_hash_sent_back_from_curl>

then, site1 can use the hash to retrieve the data from the database

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.