blogfisher Posted December 8, 2008 Share Posted December 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/136095-passing-variable-throught-hyperlink/ Share on other sites More sharing options...
rhodesa Posted December 8, 2008 Share Posted December 8, 2008 um, you could do a form, and have the link post the form...but that seems like a lot of useless code. what is wrong with doing ?val=$num ? Quote Link to comment https://forums.phpfreaks.com/topic/136095-passing-variable-throught-hyperlink/#findComment-709643 Share on other sites More sharing options...
blogfisher Posted December 8, 2008 Author Share Posted December 8, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/136095-passing-variable-throught-hyperlink/#findComment-709647 Share on other sites More sharing options...
rhodesa Posted December 8, 2008 Share Posted December 8, 2008 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> Quote Link to comment https://forums.phpfreaks.com/topic/136095-passing-variable-throught-hyperlink/#findComment-709667 Share on other sites More sharing options...
blogfisher Posted December 8, 2008 Author Share Posted December 8, 2008 Thx rhodesa i guess passing through ?val=$num will be fine. will do small encryption to the value being passed and later decrypt it. anyway, thx for the quick suggestion Cheer! Quote Link to comment https://forums.phpfreaks.com/topic/136095-passing-variable-throught-hyperlink/#findComment-709687 Share on other sites More sharing options...
rhodesa Posted December 8, 2008 Share Posted December 8, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/136095-passing-variable-throught-hyperlink/#findComment-709696 Share on other sites More sharing options...
blogfisher Posted December 8, 2008 Author Share Posted December 8, 2008 Data is not much sensitive.. so simple encryption will work for me. Also i don't store data to database, just passing the value which will be used by another algorithm and display result to user. thx. Quote Link to comment https://forums.phpfreaks.com/topic/136095-passing-variable-throught-hyperlink/#findComment-709701 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.