Jump to content

'Notice: Undefined offset: 1 in ...' Error


ready2drum

Recommended Posts

I corrected a link for a web page using Dreamweaver 8 (.php file), and after saving the change and refreshing the web page, an error appeared:

 

------

Notice: Undefined offset: 1 in E:\Inetpub\wwwroot\Intranet_Old\intranet\includes\header_1.php on line 30

------

 

line 30 reads as...

---

<?php

$username = $_SERVER["LOGON_USER"];

$username2 = explode('\\', $username);

Line 30 ->        $_SESSION['username'] = $username2[1];

echo($_SESSION['username']);

 

$_SESSION['valid_user'] = false;

 

for ($i=0; $i<$num_users; $i++) {

if ($users[$i] == $_SESSION['username']) {

$_SESSION['valid_user'] = true;

}

}

?>

---

I've not ever seen this error before and need assistance on how to resolve it.

 

Your help is greatly appreciated. Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/168848-notice-undefined-offset-1-in-error/
Share on other sites

The explode of $username did not contain as many fields as you thought it was. $username2 array does not contain an index at 1.

 

I would echo out your username and make sure it is what you were expecting. Also do a print_r on the $username2 array and see what it contains. Just to make sure they are what you expect them to be.

Not a problem. Alternatively what could be happening is you were getting this notice all the time until a server upgrade or switch happened and notice errors were turned on. They are not a huge problem, but better to remediate them.

 

You can also do a check like so:

 

$_SESSION['username'] = isset($username2[1])?$username2[1]:""; // default it to "" if there is no index in the array

 

Which would not show the notice error, but $_SESSION['username'] would be set to "" (an empty string).

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.