开发者

from eregi to preg_match

I've upgraded my php to 5.3 so i need to change regex expressions to preg_match. I've successfully made few changes to a script using delimiters and changing regex to preg_match but i'm struck with the following code which i tried to change in the following way though i didn't get any error cookies are not getting deleted.

if (preg_match('#COOKIE_PREFIX#i', $key))

Original code is

   // destroys the session cookies
function destroy($hash)
{
    foreach ($_COOKIE as $key => $value)
    {
        if (eregi(COOKIE_PREFIX, $key))
        {
            $key = str_replace(COOKIE_PREFIX, '', $key);
            xtsetcookie($key, '')开发者_运维技巧;
        }
    }
    $this->userinfo['user_id'] = 0;
}

P.S: The script developer is not replying to my support requests....


Since COOKIE_PREFIX is a constant defined to have some value you should not be enclosing it in quotes. Instead try:

if (preg_match('#'.COOKIE_PREFIX.'#i', $key))

this would fail if COOKIE_PREFIX contained a # in it, so better use:

if (preg_match('#'.preg_quote(COOKIE_PREFIX,'#').'#i', $key))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜