jeffshead Posted June 8, 2008 Share Posted June 8, 2008 Googled for hours and can't find an answer ??? I get a "Notice: Undefined offset: 1" warning referring to line 2 in the the code below: /* add domain name to username if whatnot and soforth */ if (!list($login_host, $other) = split(':', $_SERVER['HTTP_HOST'])) { $login_host = $_SERVER['HTTP_HOST']; } if (!strstr($login_username, '@')) { /* strip any leading 'www.' so that only a username is required */ $login_host = preg_replace('/^www\./i', '', $login_host); $login_host = preg_replace('/^webmail\./i', '', $login_host); $login_host = preg_replace('/^mail\./i', '', $login_host); $login_username .= '@' . $login_host; } I did not write the code, just trying to stop the warning. This code snippet is from a webmail redirect page which prevents users from reposting their form data after a successful logout. I'm sure the fix is is to add "isset" somewhere, but I can't figure it out. Can someone help? Link to comment https://forums.phpfreaks.com/topic/109286-solved-notice-undefined-offset-1/ Share on other sites More sharing options...
Barand Posted June 8, 2008 Share Posted June 8, 2008 if the item you are splitting does not contain ":" then only one array element is returned. The list() expects 2 at least. error_reporting(E_ALL); list ($a, $b) = split(':', 'abcde'); // --> undefined index 1 Link to comment https://forums.phpfreaks.com/topic/109286-solved-notice-undefined-offset-1/#findComment-560587 Share on other sites More sharing options...
jeffshead Posted June 8, 2008 Author Share Posted June 8, 2008 if the item you are splitting does not contain ":" then only one array element is returned. The list() expects 2 at least. error_reporting(E_ALL); list ($a, $b) = split(':', 'abcde'); // --> undefined index 1 Thanks for the reply. :)How do I fix? Link to comment https://forums.phpfreaks.com/topic/109286-solved-notice-undefined-offset-1/#findComment-560593 Share on other sites More sharing options...
Barand Posted June 8, 2008 Share Posted June 8, 2008 PS. A simple workaround is <?php list ($a, $b) = split(':', 'abcde' . ':'); // --> OK $a - 'abcde' , $b = '' Link to comment https://forums.phpfreaks.com/topic/109286-solved-notice-undefined-offset-1/#findComment-560596 Share on other sites More sharing options...
jeffshead Posted June 8, 2008 Author Share Posted June 8, 2008 PS. A simple workaround is <?php list ($a, $b) = split(':', 'abcde' . ':'); // --> OK $a - 'abcde' , $b = '' Thanks for the explanation Barand, that seems to have fixed it! Link to comment https://forums.phpfreaks.com/topic/109286-solved-notice-undefined-offset-1/#findComment-560601 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.