Jump to content


Photo

the ELSE in this function dont werk


  • Please log in to reply
3 replies to this topic

#1 sakata

sakata
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 19 April 2006 - 12:02 AM

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...

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>
            
            <? }
         }
}

thanks in advance for any help...

dan



#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 03:14 AM

I think the problem is here

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

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

#3 sakata

sakata
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 April 2006 - 02:00 AM

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

              if ( $sid2 = $auth['session'] ) { include_once ''. $file .''; }
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...

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

instead

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

ill go give it a try... =/

#4 eves

eves
  • Members
  • PipPip
  • Member
  • 26 posts

Posted 22 April 2006 - 03:09 PM

and don't use include() or include_once() inside conditions, use require() or require_once().
Includes don't work with conditions, require() does




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users