salento9 Posted May 12, 2011 Share Posted May 12, 2011 Hi all, from my intranet site with ldap fonction for windows AD i got the error : Undefined index: memberof , this is my code on page: session_start(); $creatorparts = explode('\\',$_SERVER["REMOTE_USER"]); $creator = $creatorparts[1]; if($_SESSION['memberof']){ $memberof = $_SESSION['MEMBEROF']; }else{ $memberof = get_memberships($creator); $_SESSION['memberof'] = $memberof; } Can you help me find what's wrong? Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/ Share on other sites More sharing options...
trq Posted May 12, 2011 Share Posted May 12, 2011 You should be using... if(isset($_SESSION['memberof'])){ instead of.... if($_SESSION['memberof']){ Be aware that indexes are case sensitive too. Have you set $_SESSION['memberof'] anywhere? Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214378 Share on other sites More sharing options...
jonsjava Posted May 12, 2011 Share Posted May 12, 2011 try if (isset($_SESSION['memberof'])){ Your code is how many people used to code. Only problem is that if your error reporting is set to notice, you get errors, when the variable isn't set. Best to check if it is set, and go from there. How your code works: if it is set, it's counted as true. If not, it comes back as false with notice. Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214381 Share on other sites More sharing options...
salento9 Posted May 12, 2011 Author Share Posted May 12, 2011 Done, but now i got a blank page how can i verify if this variable is defined? i use xampp last version. Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214385 Share on other sites More sharing options...
JasonLewis Posted May 12, 2011 Share Posted May 12, 2011 print_r($_SESSION) to see what sessions you have set. Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214389 Share on other sites More sharing options...
salento9 Posted May 12, 2011 Author Share Posted May 12, 2011 No way, always blanc page, here the whole code of header.php file: <? /* set the cache limiter to 'private' */ session_cache_limiter('none'); //echo session_cache_limiter(); /* set the cache expire to 3 minutes */ session_cache_expire(3); //echo session_cache_expire(); session_start(); $creatorparts = explode('\\',$_SERVER["REMOTE_USER"]); $creator = $creatorparts[1]; if (isset($_SESSION['memberof'])){ $memberof = $_SESSION['memberof']; }else{ $memberof = get_memberships($creator); $_SESSION['memberof'] = $memberof; } $page = basename($_SERVER["PHP_SELF"]); $page = substr($page,0,strpos(basename($_SERVER["PHP_SELF"]),'.')); if(strpos(basename($_SERVER["PHP_SELF"]),'-')){ $page = substr($page,0,strpos(basename($_SERVER["PHP_SELF"]),'-')); } $bimAuth = false; $cpoAuth = false; $pageAllowed = false; if($memberof){ foreach($memberof as $group){ //echo $group.'*<br>'; if($group == $bimSecurityGroup){ $bimAuth = true; if(array_search($page,$bimSecurity,1)){ $pageAllowed = true; } } if($group == $cpoSecurityGroup){ $cpoAuth = true; if(array_search($page,$cpoSecurity,1)){ $pageAllowed = true; } } } } ?> <html> <head> <script type="text/javascript" src="calendarDateInput.js"> /*********************************************** * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm * Script featured on and available at http://www.dynamicdrive.com * Keep this notice intact for use. ***********************************************/ </script> <? if($checkfields){ echo '<SCRIPT language="JavaScript" type="text/javascript">'; echo 'function checkform(form) {'; foreach($checkfields as $xfields){ foreach($xfields as $fielddata){ if(!$fielddata[5]){ echo 'if (form.'.$fielddata[0].'.value == "") { alert("'.strip_tags($fielddata[1]).' cannot be empty!"); form.'.$fielddata[0].'.focus(); return false; }'."\n"; } } } echo '}'; echo '</SCRIPT>'; } ?> <link rel="stylesheet" type="text/css" href="config/stylesheet.css"> <title>Océ-Belgium Usermanagement portal</title> </head> <body> <center> <img src="images/logo.jpg"><br> <font class="light"> <? echo '[Logged on as: '.$_SERVER["REMOTE_USER"].']'; if($bimAuth){ echo '[bIM]'; } if($cpoAuth){ echo '[CP&O]'; } ?> </font> <br> <br> <br> <? if(!$pageAllowed){ echo '<img src="images/nok.gif"><font size="2"><b> Access is denied! </b><img src="images/nok.gif"><br> <br> Please check if ['.$_SERVER["REMOTE_USER"].'] is a member of the right security group(s).</font><br> <br> ('.$bimSecurityGroup.')<br>or<br>('.$cpoSecurityGroup.')'; ?> <br> <br> <br> <br><input class="button" type="button" onClick="window.location='index.php'" value="^ MENU"><br> <br> <br> <br> <? include('footer.php'); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214393 Share on other sites More sharing options...
fugix Posted May 12, 2011 Share Posted May 12, 2011 And you don't receive any errors from this script? Also, what is your error_reporting level set to? Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214433 Share on other sites More sharing options...
salento9 Posted May 12, 2011 Author Share Posted May 12, 2011 ok, sorry for trouble, i found the problem for the blank page error after enable on php.ini the ldap extention. Now the problem is that i receive a page for administrators and not for normal user, it's mean that the check for user rigth in the domain not working. can you help me? new code: <? /* set the cache limiter to 'private' */ session_cache_limiter('none'); //echo session_cache_limiter(); /* set the cache expire to 3 minutes */ session_cache_expire(3); //echo session_cache_expire(); session_start(); $creatorparts = explode('\\',$_SERVER["REMOTE_USER"]); $creator = $creatorparts[1]; if (!empty($_SESSION['memberof'])){ $memberof = $_SESSION['memberof']; }else{ $memberof = get_memberships($creator); $_SESSION['memberof'] = $memberof; } $page = basename($_SERVER["PHP_SELF"]); $page = substr($page,0,strpos(basename($_SERVER["PHP_SELF"]),'.')); if(strpos(basename($_SERVER["PHP_SELF"]),'-')){ $page = substr($page,0,strpos(basename($_SERVER["PHP_SELF"]),'-')); } $bimAuth = false; $cpoAuth = false; $pageAllowed = false; if($memberof){ foreach($memberof as $group){ //echo $group.'*<br>'; if($group == $bimSecurityGroup){ $bimAuth = true; if(array_search($page,$bimSecurity,1)){ $pageAllowed = true; } } if($group == $cpoSecurityGroup){ $cpoAuth = true; if(array_search($page,$cpoSecurity,1)){ $pageAllowed = true; } } } } ?> <html> <head> <script type="text/javascript" src="calendarDateInput.js"> /*********************************************** * Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm * Script featured on and available at http://www.dynamicdrive.com * Keep this notice intact for use. ***********************************************/ </script> <? if(!empty($checkfields)){ echo '<SCRIPT language="JavaScript" type="text/javascript">'; echo 'function checkform(form) {'; foreach($checkfields as $xfields){ foreach($xfields as $fielddata){ if(!$fielddata[5]){ echo 'if (form.'.$fielddata[0].'.value == "") { alert("'.strip_tags($fielddata[1]).' cannot be empty!"); form.'.$fielddata[0].'.focus(); return false; }'."\n"; } } } echo '}'; echo '</SCRIPT>'; } ?> <link rel="stylesheet" type="text/css" href="config/stylesheet.css"> <title>Océ-Belgium Usermanagement portal</title> </head> <body> <center> <img src="images/logo.jpg"><br> <font class="light"> <? echo '[Logged on as: '.$_SERVER["REMOTE_USER"].']'; if($bimAuth){ echo '[bIM]'; } if($cpoAuth){ echo '[CP&O]'; } ?> </font> <br> <br> <br> <? if(!$pageAllowed){ echo '<img src="images/nok.gif"><font size="2"><b> Access is denied! </b><img src="images/nok.gif"><br> <br> Please check if ['.$_SERVER["REMOTE_USER"].'] is a member of the right security group(s).</font><br> <br> ('.$bimSecurityGroup.')<br>or<br>('.$cpoSecurityGroup.')'; ?> <br> <br> <br> <br><input class="button" type="button" onClick="window.location='index.php'" value="^ MENU"><br> <br> <br> <br> <? include('footer.php'); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214452 Share on other sites More sharing options...
trq Posted May 12, 2011 Share Posted May 12, 2011 I don't see anywhere within that code where you actually query any ldap server? Quote Link to comment https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/#findComment-1214463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.