Mcod Posted January 11, 2012 Share Posted January 11, 2012 I am looking for a way to remove session id strings from URL's. As far as I know, they always have the same size and pattern like: http://www.domain.com/forumdisplay.php?s=3d496add17bf8a05551109b5693e9489&f=33 http://www.domain.com/forumdisplay.php?s=3d496add17bf8a05jd7shdbe383e9489&f=21 So my mission is removing the part where it says s=sessionid which is always different. What I try to return would be: http://www.domain.com/forumdisplay.php?&f=33 and http://www.domain.com/forumdisplay.php?f=21 As you can see, I also need to remove the & at the end of the string, so it doesn't say http://www.domain.com/forumdisplay.php?&f=33 as the & would be too much. Now here is another issue... sometimes the session has a different name - for example sessid= or session= which I would also like to cover if possible. Your help is greatly appreciated as usual Quote Link to comment https://forums.phpfreaks.com/topic/254835-remove-session-ids-from-string/ Share on other sites More sharing options...
ragax Posted January 12, 2012 Share Posted January 12, 2012 Hey Mcod, Try this. Should work with s, sessid, sessionid. $pattern=',php\?\Ks(?:ession|essid)?=[^&]*&,'; $s = 'http://www.domain.com/forumdisplay.php?s=3d496add17bf8a05551109b5693e9489&f=33'; $s = preg_replace($pattern,"",$s); echo $s; Quote Link to comment https://forums.phpfreaks.com/topic/254835-remove-session-ids-from-string/#findComment-1306710 Share on other sites More sharing options...
Mcod Posted January 12, 2012 Author Share Posted January 12, 2012 Seems like you have an answer to all my questions I will give this a try as soon as possible and report back, but looking at how everything you post works, it will work just fine. Thank you (again) Quote Link to comment https://forums.phpfreaks.com/topic/254835-remove-session-ids-from-string/#findComment-1306711 Share on other sites More sharing options...
ragax Posted January 12, 2012 Share Posted January 12, 2012 Glad to help, bro. Thanks for your friendly message. Quote Link to comment https://forums.phpfreaks.com/topic/254835-remove-session-ids-from-string/#findComment-1306712 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.