Jump to content

Archived

This topic is now archived and is closed to further replies.

sakata

the ELSE in this function dont werk

Recommended Posts

i wrote this simple function to auth check certain files i wanted if u were logged in... the file is included if u werent it shows u the form to login... now everything works as far as the sql,php even keepin my sessions alive etc... i don't know why but it if your not logged in it wont show the login form... so basicly the else part in this code doesnt seem to work... i think it may have to do w/ structure...

[code]
function auth_sid_include($file = NULL)
{
        $sid2 = session_id();
        $sql = mysql_query(" SELECT * FROM admin WHERE session = '$sid2' ");
        
        while($auth = mysql_fetch_assoc($sql))
        {
              if ( $sid2 = $auth['session'] ) { include_once ''. $file .''; }
              else { ?>

            <h3>Login</h3>
            <form action="?s=form" method="post" >
            <input type="text" name="user" size="15" maxlength="40" value="" id="user"/>
            <input type="password" name="pass" size="15" maxlength="25" id="pass" />
            <input type="hidden" name="autologin" value="1" />
            <input type="hidden" name="sid" value="<? echo session_id(); ?>" />
            <input type="submit"  name="login" value="submit" />
            </form>
            
            <? }
        }
}
[/code]

thanks in advance for any help...

dan

Share this post


Link to post
Share on other sites
I think the problem is here

[code]              if ( $sid2 = $auth['session'] ) { include_once ''. $file .''; }[/code]
Where the $auth array is being defined/passed?

The structure itself is OK I guess (a bit ugly IMO).

Share this post


Link to post
Share on other sites
[!--quoteo(post=366297:date=Apr 18 2006, 10:14 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 18 2006, 10:14 PM) [snapback]366297[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I think the problem is here

[code]              if ( $sid2 = $auth['session'] ) { include_once ''. $file .''; }[/code]
Where the $auth array is being defined/passed?

The structure itself is OK I guess (a bit ugly IMO).
[/quote]


uhh... no. that isnt the problem.... and yes the code is sloppy i just wrote it... not really thinking about it.... anyway... like i said it works... i pull and check if the session id is a match if so... the page is included if not i want the form echo`d.... the else part dont work.... oh hmmm i think maybe i found where...

[code]              if ( $sid2 = $auth['session'] ) { include_once ''. $file .''; }[/code]

instead

[code]              if ( $sid2 == $auth['session'] ) { include_once ''. $file .''; }[/code]

ill go give it a try... =/

Share this post


Link to post
Share on other sites
and don't use include() or include_once() inside conditions, use require() or require_once().
Includes don't work with conditions, require() does

Share this post


Link to post
Share on other sites

×

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.