Last active
October 10, 2016 15:13
-
-
Save DawTaylor/b2776b0f5f9b1553a014e0590e4c037d to your computer and use it in GitHub Desktop.
Base 64 URL encoding/decoding sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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