[PHP] getting rid of NOTICE

2004-10-07 Thread Roger Thomas
I have this short script (below) that does checking whether a userid has an associated 
jpegPhoto in an LDAP database. The script is working fine but gave a 'Notice' msg bcos 
I made error_reporting to report all errors.

Notice: Undefined index: jpegphoto in test.php on line 34

Question: How do I make the Notice go away without changing error reporting to 
error_reporting (E_ALL  ~E_NOTICE) ?

Please advise.

--
roger

?
require_once config.inc;
error_reporting (E_ALL);

$ds = @connectBindServer(LDAP_RDN, LDAP_PASS);
if ($ds) {
$what2return   = array(givenName,sn,jpegPhoto);
$searchFilter  = ([EMAIL PROTECTED]);
$sr= ldap_search($ds, LDAP_BASEDN, $searchFilter,$what2return);
$resultEntries = ldap_get_entries($ds, $sr);
closeConn($ds);

if ($resultEntries[count] == 0) {
print user not found;
exit;
}
else {
$gn= $resultEntries[0][givenname];
$sn= $resultEntries[0][sn];
$photo = $resultEntries[0][jpegphoto];
if ($photo['count'] == 1)
print photo available;
else
print photo not available;
}
}

?



---
Sign Up for free Email at http://ureg.home.net.my/
---

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] getting rid of NOTICE

2004-10-07 Thread zareef ahmed

--- Roger Thomas [EMAIL PROTECTED] wrote:

 I have this short script (below) that does checking
 whether a userid has an associated jpegPhoto in an
 LDAP database. The script is working fine but gave a
 'Notice' msg bcos I made error_reporting to report
 all errors.
 
 Notice: Undefined index: jpegphoto in test.php on
 line 34
 
 Question: How do I make the Notice go away without
 changing error reporting to error_reporting (E_ALL 
 ~E_NOTICE) ?
 
 Please advise.
 
 --
 roger
 
 ?
 require_once config.inc;
 error_reporting (E_ALL);
 
 $ds = @connectBindServer(LDAP_RDN, LDAP_PASS);
 if ($ds) {
 $what2return   =
 array(givenName,sn,jpegPhoto);

You have define jpegPhoto Note Caps P.

 $searchFilter  = ([EMAIL PROTECTED]);
 $sr= ldap_search($ds, LDAP_BASEDN,
 $searchFilter,$what2return);
 $resultEntries = ldap_get_entries($ds, $sr);
 closeConn($ds);
 
 if ($resultEntries[count] == 0) {
 print user not found;
 exit;
 }
 else {
 $gn= $resultEntries[0][givenname];
 $sn= $resultEntries[0][sn];
 $photo = $resultEntries[0][jpegphoto];

here p is small in jpegphoto.

Got it ...

zareef ahmed
 if ($photo['count'] == 1)
 print photo available;
 else
 print photo not available;
 }
 }
 
 ?
 
 
 
 ---
 Sign Up for free Email at http://ureg.home.net.my/
 ---
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


=
Zareef Ahmed :: A PHP Developer in Delhi ( India ).
Homepage :: http://www.zasaifi.com/zareef_ahmed.php



___
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] getting rid of NOTICE

2004-10-07 Thread Roger Thomas
I dont know how to explain this but when you work with an ldap attribute, they are 
case sensitive. jpegPhoto was what the schema was written with.

However when you retrieve that into PHP, you accessed them with all lower case. So 
accessing userPassword attribute in ldap will become userpassword in PHP.

Just to satisfy your curiosity, I have changed that to your advise with running the 
script produces identical result.

--
roger

Quoting zareef ahmed [EMAIL PROTECTED]:

 
 --- Roger Thomas [EMAIL PROTECTED] wrote:
 
  I have this short script (below) that does checking
  whether a userid has an associated jpegPhoto in an
  LDAP database. The script is working fine but gave a
  'Notice' msg bcos I made error_reporting to report
  all errors.
  
  Notice: Undefined index: jpegphoto in test.php on
  line 34
  
  Question: How do I make the Notice go away without
  changing error reporting to error_reporting (E_ALL 
  ~E_NOTICE) ?
  
  Please advise.
  
  --
  roger
  
  ?
  require_once config.inc;
  error_reporting (E_ALL);
  
  $ds = @connectBindServer(LDAP_RDN, LDAP_PASS);
  if ($ds) {
  $what2return   =
  array(givenName,sn,jpegPhoto);
 
 You have define jpegPhoto Note Caps P.
 
  $searchFilter  = ([EMAIL PROTECTED]);
  $sr= ldap_search($ds, LDAP_BASEDN,
  $searchFilter,$what2return);
  $resultEntries = ldap_get_entries($ds, $sr);
  closeConn($ds);
  
  if ($resultEntries[count] == 0) {
  print user not found;
  exit;
  }
  else {
  $gn= $resultEntries[0][givenname];
  $sn= $resultEntries[0][sn];
  $photo = $resultEntries[0][jpegphoto];
 
 here p is small in jpegphoto.
 
 Got it ...
 
 zareef ahmed
  if ($photo['count'] == 1)
  print photo available;
  else
  print photo not available;
  }
  }
  
  ?
  
  
  
  ---
  Sign Up for free Email at http://ureg.home.net.my/
  ---
  
  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
  
  
 
 
 =
 Zareef Ahmed :: A PHP Developer in Delhi ( India ).
 Homepage :: http://www.zasaifi.com/zareef_ahmed.php
 
 
   
 ___
 Do you Yahoo!?
 Declare Yourself - Register online to vote today!
 http://vote.yahoo.com
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 





---
Sign Up for free Email at http://ureg.home.net.my/
---

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] getting rid of NOTICE

2004-10-07 Thread Marek Kilimajer
Roger Thomas wrote:
I dont know how to explain this but when you work with an ldap attribute, they are 
case sensitive. jpegPhoto was what the schema was written with.
However when you retrieve that into PHP, you accessed them with all lower case. So 
accessing userPassword attribute in ldap will become userpassword in PHP.
Just to satisfy your curiosity, I have changed that to your advise with running the 
script produces identical result.
You can either:
1. prepend @ in front of the variable, which supresses notices and warnings
2. use isset() or array_key_exists() to check for the existance of the key.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] getting rid of NOTICE

2004-10-07 Thread M. Sokolewicz
Marek Kilimajer wrote:
Roger Thomas wrote:
I dont know how to explain this but when you work with an ldap 
attribute, they are case sensitive. jpegPhoto was what the schema was 
written with.

However when you retrieve that into PHP, you accessed them with all 
lower case. So accessing userPassword attribute in ldap will become 
userpassword in PHP.

Just to satisfy your curiosity, I have changed that to your advise 
with running the script produces identical result.

You can either:
1. prepend @ in front of the variable, which supresses notices and warnings
that's a very ugly use... If you're sure it'll throw a notice, then 
initialize the variable.

If you're unsure about aby of your variables, and don't want to appear 
as if you were a clean coder, you can set 
error_reporting(E_ALL~E_NOTICE), which'll show E_ALL AND NOT E_NOTICE :)
2. use isset() or array_key_exists() to check for the existance of the key.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] getting rid of NOTICE

2004-10-07 Thread Robin Vickery
On Thu,  7 Oct 2004 14:04:00 +0800, Roger Thomas [EMAIL PROTECTED] wrote:
 I have this short script (below) that does checking whether a userid has an 
 associated jpegPhoto in an LDAP database. The script is working fine but gave a 
 'Notice' msg bcos I made error_reporting to report all errors.
 
 Notice: Undefined index: jpegphoto in test.php on line 34
 
 Question: How do I make the Notice go away without changing error reporting to 
 error_reporting (E_ALL  ~E_NOTICE) ?
 [...]
 $photo = $resultEntries[0][jpegphoto];

It's complaining because you're trying to read from an array index
that hasn't been set, Assuming this isn't a typo or something, if you
want to avoid the notice you normally have two options:

  1. initialise all the indexes that you plan to use.
  2. check whether the index has been set before you try to read from it.

In this case, you're pretty much stuck with the second option as
you're getting the array from an external source.

So do something like this:

  $photo = isset($resultEntries[0][jpegphoto]) ?
$resultEntries[0][jpegphoto] : array('count' = 0);

  -robin

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php