Jump to content

Remove session ID's from string


Mcod

Recommended Posts

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 :)

 

 

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/254835-remove-session-ids-from-string/
Share on other sites

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;

 

:)

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.