Jump to content

Special Characters In Search String


sintax63

Recommended Posts

Hash marks and fragments get ignored through the address bar.

 

Run this example on what you can do or not to see the fragment.

 

<?php
$url = filter_var("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING);
if (!empty($_SERVER["QUERY_STRING"])) {
    $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING);
    $url .= "?" . $query_string;
}

echo "<h4>what your script sees from address bar</h4>";
echo $url . "<br />";
//as can see here, nothing through $_server shows the fragment
print_r($_SERVER);
echo "<h4>client side using javascript</h4>";
echo "<script language='javascript'>
document.write(window.location.hash);
</script>";
echo "<h4>directly from server or in code</h4>";
$url = "http://site.com/page#fragment";
//example 1
echo parse_url($url, PHP_URL_FRAGMENT) . "<br />";
//example 2
echo end(explode("#", $url)) . "<br />";
//example 3
$arr = parse_url($url);
//print_r($arr);
echo $arr['fragment'];
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.