ManelMusti ManelMusti - 1 year ago 89
PHP Question

Form data base64 encoded with get method

I need to be able to provide custom URL's from html forms with the data encoded in base64.

For example:

<form name="test" action="test.php" method="get">
<input type="text" name="category" />
<input type="text" name="gender" />
<input type="text" name="quantity" />

And get an URL:



Answer Source

You should probably post the form first and then do the following:

// Sanitize data

$urlData = $array();

$urlData['category'] = $_POST['category'];
$urlData['gender']   = $_POST['gender'];
$urlData['quantity'] = $_POST['quantity'];

$urlData = base64_encode( json_encode( $urlData ) );

header("Location test.php?data=". $urlData ."");

I used json_encode because base64 alone can alter the meaning of your data. Checkout this article on that subject: Passing base64 encoded strings in URL

Then on test.php:

$data = json_decode( base64_decode( $_GET['data'] ) );
// Sanitize data again