Skip to content

Instantly share code, notes, and snippets.

@DawTaylor
Last active October 10, 2016 15:13
Show Gist options
  • Save DawTaylor/b2776b0f5f9b1553a014e0590e4c037d to your computer and use it in GitHub Desktop.
Save DawTaylor/b2776b0f5f9b1553a014e0590e4c037d to your computer and use it in GitHub Desktop.
Base 64 URL encoding/decoding sample
<?php
//Checks if plain URL was given
if ( $_GET['url'] ){
//Encodes $_GET['url'] parameter
$encodedURL = base64_encode( urlencode( $_GET['url'] ) );
//Prints out the encoded url
echo "Encoded URL => " . $encodedURL . "<br />";
}
//Checks if encoded URL was given
else if ( $_GET['enc'] ) {
//Decodes $_GET['enc'] parameter
$decodedURL = urldecode( base64_decode( $_GET['enc'] ) );
//Prints out the decoded url
echo "Decoded URL => " . $decodedURL . "<br />";
}
//If no encoded or decoded URL, prints a simple help
else {
?>
<h1> Error! </h1>
<p>You should inform either an URL to encode or and encoded URL to decode.</p>
<p>Use ?url=http://example.com to encode the given URL.</p>
<p>Use ?enc= to decode the given encoded URL.</p>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment