login issues on IIS

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
ceilingfish

login issues on IIS

Post by ceilingfish »

Hi,
I have been using CMSMS on IIS for a while now and I have always noticed a really odd bug when logging into the admin. First attempt just fails. After clicking login, my browser just goes and sits in login.php looking despondent.

If you log in a second time then it scoots off to the right spot.

I took a look around, and found the redirect() function in misc.functions.php. This seems to redirect the browser using the Location HTTP header. But it does it with a relative URL. That's naughty >> http://www.w3.org/Protocols/rfc2616/rfc ... l#sec14.30

So I took the liberty of twiddling with my version, and in the jovial spirit of GPL. Here it is:

Code: Select all

function redirect($to, $noappend=false)
{
    global $gCms;
    $config = $gCms->config;

    $schema = $_SERVER['SERVER_PORT'] == '443' ? 'https' : 'http';
    $host = strlen($_SERVER['HTTP_HOST'])?$_SERVER['HTTP_HOST']:$_SERVER['SERVER_NAME'];

    $components = parse_url($to);
    if(count($components) > 0)
    {
        $to =  (isset($components['scheme']) ? $components['scheme'] : $schema) . '://';
        $to .= isset($components['host']) ? $components['host'] : $host;
        $to .= isset($components['port']) ? ':' . $components['port'] : '';
        if(isset($components['path']))
        {
            if(in_array(substr($components['path'],0,1),array('\\','/')))//Path is absolute, just append.
            {
                $to .= $components['path'];
            }
            else//Path is relative, append current directory first.
            {
                $to .= (strlen(dirname($_SERVER['PHP_SELF'])) > 1 ?  dirname($_SERVER['PHP_SELF']).'/' : '/') . $components['path'];
            }
        }
        $to .= isset($components['query']) ? '?' . $components['query'] : '';
        $to .= isset($components['fragment']) ? '#' . $components['fragment'] : '';
    }
    else
    {
        $to = $schema."://".$host."/".$to;
    }

    //If session trans-id is being used, and they is on yo website, add it.
    if (ini_get("session.use_trans_sid") != "0" && $noappend == false && strpos($to,$host) !== false)
    {
        if(strpos($to,'?') !== false)//If there are no arguments start a querystring
        {
            $to = $to."?".session_name()."=".session_id();
        }
        else//There are arguments, print an arg seperator
        {
            $to = $to.ini_get('arg_separator.input').session_name()."=".session_id();
        }
    }

    if (headers_sent())
    {
        // use javascript instead
        echo '<__script__ type="text/javascript">
            <!--
                location.replace("'.$url.'");
            // -->
            </__script>
            <noscript>
                <meta http-equiv="Refresh" content="0;URL='.$url.'">
            </noscript>';
        exit;

    }
    else
    {
        if (isset($config) and $config['debug'] == true)
        {
            echo "Debug is on.  Redirecting disabled...  Please click this link to continue.<br />";
            echo "<a href=\"".$to."\">".$to."</a><br />";
            global $sql_queries;
            if (isset($sql_queries))
            {
                echo $sql_queries;
            }
            exit();
        }
        else
        {
            header("Location: $to");
            exit();
        }
    }
}
PS Obviously this does sort the issue.
Last edited by ceilingfish on Tue Jul 19, 2005 10:24 am, edited 1 time in total.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

Re: login issues on IIS

Post by Ted »

Awesome.  Thanks.  I knew some people were having IIS issues, but didn't really know where to start looking, since I don't have IIS readily available these days.

I'll commit that into the codebase and it'll be in 0.10.1.
Post Reply

Return to “Developers Discussion”