Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/236195-undefined-index-memberof/
Share on other sites

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.

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

?>

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

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.