Stefan83 Posted December 4, 2013 Share Posted December 4, 2013 Hi I'm redirecting wireless devices to a page that delivers different content based on the device OS. I'm using WURFL to do this. The following code gets the landing page URI and redirects mobile devices to domain.com/mobile/?from=previousPageURI elseif ($client->getDeviceCapability('is_wireless_device')) { $source = ''; if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/'); $source = urldecode($_SERVER['REQUEST_URI']); header("Location:/mobile/?from=$source"); } The issue I'm having is if the referral URL already has a query string attached, I get two '?' in the URL. So domain.com/?example=1 redirects to domain.com/mobile?from=?example=1 How do I resolve this? Thanks Link to comment https://forums.phpfreaks.com/topic/284528-two-in-query-string/ Share on other sites More sharing options...
kicken Posted December 4, 2013 Share Posted December 4, 2013 you should be using urlencode on your source variable, not urldecode. That will turn the second ? (and other bad characters) into it's percent-encoded form, thus preventing problems. Link to comment https://forums.phpfreaks.com/topic/284528-two-in-query-string/#findComment-1461266 Share on other sites More sharing options...
Ch0cu3r Posted December 4, 2013 Share Posted December 4, 2013 Edit, double post Use urlencode on $source The use urldecode when you use $_GET['from'] Link to comment https://forums.phpfreaks.com/topic/284528-two-in-query-string/#findComment-1461267 Share on other sites More sharing options...
Stefan83 Posted December 4, 2013 Author Share Posted December 4, 2013 Thanks guys, that's great. Now, on the mobile landing page, I'd like include different content based on referral URL. So if the URL is domain.com/mobile/?from=%2F%3Fnov13%3Dtest1 I'd like to load nov13.php But I'd also like to load nov13.php file when the value is test2, test3 etc. How do I rewrite the array below for this wildcard variable? <?php $mapping = array( '%2F%3Fnov13%3Dtest1' => 'inc/mobile/nov13.php' '%2F%3Fnov13%3Dtest2' => 'inc/mobile/nov13.php' '%2F%3Fnov13%3Dtest3' => 'inc/mobile/nov13.php' '%2F%3Fnov13%3Dtest4' => 'inc/mobile/nov13.php' ); if(array_key_exists($_GET['from'], $mapping)) include $mapping[$_GET['from']]; else include 'inc/mobile/default.php'; ?> Thanks Link to comment https://forums.phpfreaks.com/topic/284528-two-in-query-string/#findComment-1461277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.