Undefined index: memberof error

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Undefined index: memberof error

Postby salento9 » 12. May 2011 09:07

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.
salento9
 
Posts: 9
Joined: 27. July 2007 09:18

Re: Undefined index: memberof error

Postby anton_k » 12. May 2011 11:25

Ok I'll try to make this situation as clear as possible.
Here are my researches :

1. You said that you used: "ldap fonction" >>> ok, re-check again whether the error is coming from the "ldap function" usage, which ldap function did you use before? If the error were really coming from that "ldap function", then you must re-check that function as an error-triggered,ok.

2. You got the error:
Undefined index: memberof , this is my code on page:

And one of your code was:
$memberof = get_memberships($creator);

So, i suggest you to re-check your get_memberships(yourArgument) function as the error arised. You can check whether your function's argument is really a certain data-type that will be executed within the function(=Did your function accept "various string data-types", "various number data-types", so on ?)

3. I also see your code :
$memberof = $_SESSION['MEMBEROF'];

Ok, you got two sessions here. Their names are MEMBEROF (=with uppercase) & memberof (=with lowercase). See the differences ?

The $_SESSION['memberof'] got its own value from the right variable $memberof (it's ok), but what about the other one? The $_SESSION['MEMBEROF']; was only a definition from a plain variable $memberof. You must know how to create the very right $_SESSION variable. Here are what i mean:

> Below is the right session. Because it is indeed coming from a variable which has defined from your get_memberships() function.
$memberof = get_memberships($creator);
$_SESSION['memberof'] = $memberof;


> So what i want to know is about this session $_SESSION['MEMBEROF']; (=the uppercase). Are you sure this session has been created before, the first time you created within session_start(); function.? If this session derives another page, it's already right. But i want to suggest you for a better clean programming, you must specify different name in order to avoid some errors that would arise in the future.

4. Ok, that's all from me. Always Re-check the functions that u have been playing with. Try to be involved in a better clean programming.
I'll try to catch up again for the reviews.
anton_k
 
Posts: 4
Joined: 03. May 2011 03:39

Re: Undefined index: memberof error

Postby salento9 » 12. May 2011 12:01

Thank you very much for your explanation, but it become to difficult for me, i will try to put in practice your suggestion. :cry:
salento9
 
Posts: 9
Joined: 27. July 2007 09:18

Re: Undefined index: memberof error

Postby Altrea » 12. May 2011 12:19

simply change
Code: Select all
if($_SESSION['memberof']){


to
Code: Select all
if(!empty($_SESSION['memberof'])){
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Undefined index: memberof error

Postby salento9 » 12. May 2011 12:26

Thanks, i've done this:

if (!empty($_SESSION['memberof']))

but now i got a blank page :(
salento9
 
Posts: 9
Joined: 27. July 2007 09:18

Re: Undefined index: memberof error

Postby Altrea » 12. May 2011 12:43

The code snippet you showed us doesn't have any outputs.
Either show us your full sourcecode here, or try to debug it on your own.
But i don't have enough information to debug your script from here, sorry.

P.S.: please wrap your code in the code-BBCodes here for better reading.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Undefined index: memberof error

Postby salento9 » 12. May 2011 13:40

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.

full code page: header.php

Code: Select all
<?

/* 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>&nbsp;<br>&nbsp;<br>

<?
if(!$pageAllowed){

  echo '<img src="images/nok.gif"><font size="2"><b> Access is denied! </b><img src="images/nok.gif"><br>&nbsp;<br>
        Please check if ['.$_SERVER["REMOTE_USER"].'] is a member of the right security group(s).</font><br>&nbsp;<br>
        ('.$bimSecurityGroup.')<br>or<br>('.$cpoSecurityGroup.')';
  ?>
  <br>&nbsp;<br>&nbsp;<br>&nbsp;<br><input class="button" type="button" onClick="window.location='index.php'" value="^ MENU"><br>&nbsp;<br>&nbsp;<br>&nbsp;<br>
  <?
  include('footer.php');
  exit;
}

?>
salento9
 
Posts: 9
Joined: 27. July 2007 09:18


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 97 guests