sakata Posted April 19, 2006 Share Posted April 19, 2006 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 Link to comment https://forums.phpfreaks.com/topic/7797-the-else-in-this-function-dont-werk/ Share on other sites More sharing options...
poirot Posted April 19, 2006 Share Posted April 19, 2006 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). Link to comment https://forums.phpfreaks.com/topic/7797-the-else-in-this-function-dont-werk/#findComment-28454 Share on other sites More sharing options...
sakata Posted April 22, 2006 Author Share Posted April 22, 2006 [!--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... =/ Link to comment https://forums.phpfreaks.com/topic/7797-the-else-in-this-function-dont-werk/#findComment-29533 Share on other sites More sharing options...
eves Posted April 22, 2006 Share Posted April 22, 2006 and don't use include() or include_once() inside conditions, use require() or require_once().Includes don't work with conditions, require() does Link to comment https://forums.phpfreaks.com/topic/7797-the-else-in-this-function-dont-werk/#findComment-29593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.