ready2drum Posted August 4, 2009 Share Posted August 4, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/168848-notice-undefined-offset-1-in-error/ Share on other sites More sharing options...
premiso Posted August 4, 2009 Share Posted August 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/168848-notice-undefined-offset-1-in-error/#findComment-890859 Share on other sites More sharing options...
ready2drum Posted August 4, 2009 Author Share Posted August 4, 2009 I appreciate your help on this Premiso...I'll put your suggestions to good use and let you know how it turns out. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/168848-notice-undefined-offset-1-in-error/#findComment-890862 Share on other sites More sharing options...
premiso Posted August 4, 2009 Share Posted August 4, 2009 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). Quote Link to comment https://forums.phpfreaks.com/topic/168848-notice-undefined-offset-1-in-error/#findComment-890863 Share on other sites More sharing options...
ready2drum Posted August 4, 2009 Author Share Posted August 4, 2009 The good news is that it works now...no errors to report. I checked everything to ensure that there were no missed items and no other discrepancies in the code. Thank you for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/168848-notice-undefined-offset-1-in-error/#findComment-890869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.