DeanWhitehouse Posted May 2, 2008 Share Posted May 2, 2008 $logout = str_replace("?logout","",""); this is my code, i want to delete the ?logout, how can i do this(am i using the wrong code). example http://mysite.com/members?logout should change to this http://mysite.com/members Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/ Share on other sites More sharing options...
BlueSkyIS Posted May 2, 2008 Share Posted May 2, 2008 $url = 'http://mysite.com/members?logout'; $url = str_replace('?logout',"",$url); Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532138 Share on other sites More sharing options...
DeanWhitehouse Posted May 2, 2008 Author Share Posted May 2, 2008 i tried this $url = $_SERVER['HTTP_HOST']; $log_out = $_SERVER['HTTP_HOST']."?logout"; $logout = str_replace($log_out,"",$url); header("Location:".$logout); but this does this http://mysite.co.uk/mysite.co.uk Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532142 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 ................ ................ People really can't follow directions these days. >_> $url = $_SERVER['HTTP_HOST']; $logout = str_replace("?logout","",$url); header("Location:".$logout); Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532144 Share on other sites More sharing options...
BlueSkyIS Posted May 2, 2008 Share Posted May 2, 2008 $_SERVER['HTTP_HOST'] is the host, not the entire URL. if the script is (presumably) members, why not just header("location: members"); ? Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532146 Share on other sites More sharing options...
DeanWhitehouse Posted May 2, 2008 Author Share Posted May 2, 2008 because it's ment to refer the user to the home page, and it is for a CMS so it has to be to there host. BTW i can follow directions, i just decide not to follow bad ones, as i thought your code done the same as mine http://mysite.co.uk/mysite.co.uk Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532148 Share on other sites More sharing options...
BlueSkyIS Posted May 2, 2008 Share Posted May 2, 2008 if you just need to redirect the script to itself without the query string, this should work: header("Location: ".$_SERVER['PHP_SELF']); exit; Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532152 Share on other sites More sharing options...
DeanWhitehouse Posted May 2, 2008 Author Share Posted May 2, 2008 thanks, that worked Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532154 Share on other sites More sharing options...
DarkWater Posted May 2, 2008 Share Posted May 2, 2008 Do this: $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']); if ((substr($url, -1) == '/') || (substr($url, -1) == '\\')) { $url = substr($url, 0, -1); } $url .= '/members.php'; header("Location: $url"); exit() >_> I didn't realize that's what you were doing. Absolute URLs are better. Quote Link to comment https://forums.phpfreaks.com/topic/103944-solved-str_replace-with-blank-characters/#findComment-532157 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.