I got a very weird problem I haven't before thought about.
When I call my page with ...index.php or index.php? it displays the same site. I only want to show index.php and when index.php? shows up I want to make a header Location request to index.php. (There is nothing behind the ?)
My problem now is, that I cannot determine if there simply is just the ?
I tried isset and array_key_exists on $_SERVER['QUERY_STRING']) but it seems the array is there nomatter what and therefore both index.php and index.php? always have the same result.
Script_Name displays without ?
So is there anyway to eliminate that ? ?
URL extract ? [solved]
Moderator: General Moderators
URL extract ? [solved]
Last edited by AGISB on Tue May 12, 2009 5:16 am, edited 1 time in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: URL extract ?
You can use trim with the optional second argument.
Code: Select all
$querystring = isset($_SERVER['QUERY_STRING']) ? trim($_SERVER['QUERY_STRING'], '?') : '';
if (empty($querystring)) {
//do something
} else {
//do something else
}
Re: URL extract ?
The Problem is, that the ? is neither part of the $_SERVER['QUERY_STRING'] or the $_SERVER['SCRIPT_NAME'] so I can't trim any of those ;-(John Cartwright wrote:You can use trim with the optional second argument.
Code: Select all
$querystring = isset($_SERVER['QUERY_STRING']) ? trim($_SERVER['QUERY_STRING'], '?') : ''; if (empty($querystring)) { //do something } else { //do something else }
I found the way however, just for future reference
$_SERVER['REQUEST_URI'] shows the complete path and so I could just determine if the last char is ?