I have the following code that places a session code "3888" so that when the user brwosers to the URL without the session code, they are redirected. If they have the code in the URL, the page continues to load.
The problem is the code is changing my URL spaces to + signs when outputting the javascript variables: Example: This http://localhost/testing/testingvar.php?region=South AFrica&brand=samsung&model=S 5 changes to: http://localhost/testing/testingvar.php?region=South%20AFrica&brand=samsung&model=S%205&mine=3888
So now var
var region= getURLParameter('region');
is printed out as South+Africa, instead of South Africa.
Anyway to decode the URL to keep the spaces?
Here is the PHP code:
<?php
session_start();
$self = "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}";
if(!empty($_GET['mine']) && $_GET['mine'] == "3888" ) {
unset($_GET['mine']);
$qs = http_build_query($_GET);
$self = "{$_SERVER['PHP_SELF']}?{$qs}";
$_SESSION['mine'] = 1;
header("Location: $self");
exit;
} elseif (!isset($_SESSION['mine'])) {
header('Location: http://redirectedpage.com');
exit;
}
session_unset();
session_destroy();
session_write_close();
?>
I already have this as javascript code:
<script>
function getURLParameter(name){return decodeURI( (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || '' );}</script>
This doesn't seem to fix it... Could I use urldecode() in the PHP code somewhere? Without the PHP code, all my variables are intepreted perfectly.