Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-8749

Faster/lighter way to generate SID-free links in feed.php

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 3.0.6
    • 3.0.x
    • Other
    • None
    • PHP Environment:
      Database:

      I was digging through the source for feed.php, and I noticed a function in there called feed_append_sid(). Fine and dandy. Then I noticed all the fighting to remove the SID from the append_sid() call within the function call and thought that there had to be a better way.

      /**
      * Run links through append_sid(), prepend generate_board_url() and remove session id
      **/
      function feed_append_sid($url, $params)
      {
      	global $board_url;
       
      	$link = append_sid($board_url . $url, $params);
       
      	// Remove added sid - not as easy as it sounds. ;)
      	$link = (strpos($link, 'sid=') !== false) ? trim(preg_replace('/(&|&|\?)sid=[a-z0-9]+(&|&)?/', '\1', $link), '?& ') : $link;
       
      	// Now the only thing remaining could be an empty &
      	$link = (substr($link, -5) === '&') ? substr($link, 0, -5) : $link;
      	// And &#xxx
      	$link = str_replace('&#', '#', $link);
       
      	return $link;
      }

      Now, when I looked at append_sid() in includes/functions.php, I noticed there was a fourth param. It seems this allows us to specify a custom SID – what if an empty string was specified, like so?

      $some_url = append_sid("{$phpbb_root_path}page.{$phpEx}", false, true, '');

      append_sid() only seems to strict check for false ( if ($session_id === false) ), which allows us to specify just '' as the value for the $session_id param and get the URL without the SID affixed.

      By changing this around, it surely would improve the generation times for the feed pages, especially if the feed_append_sid() function was called heavily throughout.

      I have yet to test this as it is getting late for me and I need sleep, but this alternative should be looked into and I wanted to get it out there ASAP so that it could be considered before phpBB 3.0.6 is released.

            Acyd Burn Meik Sievertsen [X] (Inactive)
            Desdenova Desdenova [X] (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: