-1

I am working on a project in which user can search anything. I want to show search data in encrypt form in URL. I create a form and when user submit it I send user to result page, which I define in form action and form method is get.

<form is="search" action="example/search.php" method="get">
<input type="text" placeholder="Search..." name="key" id="header-search" />
<button class="submit"></button>
</form>

I need to show encrypt data in URL. If I encrypt data using java script then I can't get the data using PHP. How can I send data in encrypt form in URL and get in php in other page.

3
  • 2
    Isn't HTTPS (en.wikipedia.org/wiki/HTTPS) is what you are looking for? Commented Mar 28, 2016 at 19:11
  • user enter any data to search but that data should show in encrypted form in URL and I can get all data using $_GET related to search. This search is used in header. so I can't send data to other page using php. Commented Mar 28, 2016 at 19:14
  • I recommend reading: The Comprehensive Guide to URL Parameter Encryption in PHP. Commented Mar 28, 2016 at 22:00

2 Answers 2

0

Are you referring to url obfuscation? If so, you can base64 encode the string client side, and decode it server side.

https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding for more details.

An example:

//client side
var encodedData = window.btoa("Hello, world"); // encode a string


//Server side (php)
$decodedData= base64_decode($encodedData)
Sign up to request clarification or add additional context in comments.

2 Comments

I can encrypt data using atob(). but how I can I De-crypt it in php. because I get all data from database according to the search
Just to remind anyone reading this, base64 isn't encryption.
0

As you are sending parameters in it so You can implement the process using ajax. Before submitting form create an ajax request and send text field data in it. Use below variables for encryption

$cipher = "AES-128-CTR";
$key = "12345";
$opt = 0;
$iv_key = '123456789';
$iv_length = openssl_cipher_iv_length($cipher);

encrypt string using openssl_encrypt function and return as ajax response

$encryption = openssl_encrypt($string, $cipher, $key, $opt, $iv_key);
return $encryption;

Now store this string in a hidden field and send in form. On next page use the below code to decrypt the string and get data from database.

$decryption = openssl_decrypt($string, $cipher, $key, $opt, $iv_key);

make sure $cipher, $key, $opt, $iv_key should have same value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.