Reputation: 901
I am passing parameters through href
tag as below:
<a href='message.php?toid=$userid&name1=$fname&name2=$lname'>
When I get redirected to message.php
, the three parameters are visible on address bar. How can I hide these parameters? I came across .htaccess
as one of the solution but without .htaccess
I would like to hide the parameters
Upvotes: 2
Views: 7347
Reputation: 1044
You can use jQuery to submit POST data as well, something like the following example:
$('#post').click(function(e) { // we assigned our link the id "post"
e.preventDefault();
var url = $(this).attr('href');
$.ajax({
type: "POST",
url: url,
data: { name: 'John Doe', address: 'Some address' },
})
.done(function(data) {
// $(".success").html( data ); // Optionally display result from post page instead of redirecting
$(".success").html('We made a post! Yeah, redirecting you somewhere!');
var end = setTimeout(function() {
window.location.replace(url);
clearTimeout(end);
}, 200);
})
.fail(function() {
$('.success').html('Something went wrong!');
});
});
Upvotes: 1
Reputation: 68466
No, you cannot hide the parameters that are sent through the <a>
anchors tags.
However, you can obfuscate the parameters by encrypting them and then decrypting them on your server-side script.
test1.php
<?php
$key_value = "somekey"; //<--- This is a key for the encryption decryption process
$plain_text = "the secret !"; //<-- The actual text you are going to send.
$encryptedmsg = mcrypt_ecb(MCRYPT_DES, $key_value, $plain_text, MCRYPT_ENCRYPT); //<-- Encrypting...
echo "<a href=test2.php?enc=$encryptedmsg>Click Here</a>"; //<-- Your anchor tag
test2.php
<?php
$key_value = "somekey"; //<--- Note..the same key !
$decryptedmsg = mcrypt_ecb(MCRYPT_DES, $key_value, $_GET['enc'], MCRYPT_DECRYPT); //<-- Decrypting
echo $decryptedmsg; //<-- Prints "the secret"
When clicked the link.. the test2.php will get the enc
parameter and then decrypt it using the code , however, users will not be able to read the plain text.. the secret !
This is how it looks on the addressbar when you click the link from test1.php
...
http://localhost/ext1/test2.php?enc=%D4%1D%96F|C%8B%8C%D7%8AP%19=%13%F6%A1
Warning : The mcrypt_ecb
is deprecated. I just used it for the illustration purposes to give you an idea of what is happening.
Upvotes: 3
Reputation: 1005
The only way that I can think of you doing this is if you have a form with hidden input fields and the tag is your submit. Just set the action as post.
Upvotes: 0
Reputation: 10111
Add this link on the top of your code in message.php file
<?php if($_GET['toid']) echo header("location:message.php"); ?>
Upvotes: 0