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

Link to comment
Share on other sites

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).

 

Link to comment
Share on other sites

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.