CodeIgniter Forums
Warning in core/URI.php with rewrite - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Warning in core/URI.php with rewrite (/showthread.php?tid=38107)



Warning in core/URI.php with rewrite - El Forum - 01-30-2011

[eluser]Unknown[/eluser]
I've followed the instructions for rewriting urls in my .conf (not .htaccess) file, and I'm generating a warning now:

Code:
A PHP Error was encountered
Severity: Warning
Message: strpos() [function.strpos]: Empty delimiter
Filename: core/URI.php
Line Number: 149
A PHP Error was encountered
Severity: Warning
Message: strpos() [function.strpos]: Empty delimiter
Filename: core/URI.php
Line Number: 153

I've fixed it by checking that $_SERVER['SCRIPT_NAME'] is not blank before calling that

Code:
if (!empty($_SERVER['SCRIPT_NAME']))
        if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)

I think this is a bug, or possibly a configuration error, though I've followed the instructions at

http://codeigniter.com/wiki/mod_rewrite/

Tac


Warning in core/URI.php with rewrite - El Forum - 02-12-2011

[eluser]Unknown[/eluser]
I believe it is a bug:

From system/core/URI.php:149-156
Code:
if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
{
    $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
}
elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
{
    $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
}

This should really be checking whether $_SERVER['SCRIPT_NAME'] has any contents like this (and thus is safe to pass as the second parameter to strpos):

Code:
if($_SERVER['SCRIPT_NAME'] != '')
{
    if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
    {
        $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
    }
    elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
    {
        $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
    }
}

Nik.

Edit: I've posted this up on the bug tracker now Smile

Edit Edit: Gah, those smilies are ugly - Deploying alternative smiley: ^_^