DJ24966 Posted November 9, 2008 Share Posted November 9, 2008 I'm trying to embed this page into Jupiter Content Manager. When the page is alone, I get no errors, I do get these after embedding the page though. Notice: Undefined offset: 1 in C:\wamp\www\site\pages\roomlist.php on line 38 Notice: Undefined offset: 1 in C:\wamp\www\site\pages\roomlist.php on line 44 Notice: Undefined offset: 1 in C:\wamp\www\site\pages\roomlist.php on line 48 Notice: Undefined offset: 1 in C:\wamp\www\site\pages\roomlist.php on line 52 Notice: Undefined variable: color in C:\wamp\www\site\pages\roomlist.php on line 59 Here is the page in question. <?php $botnick = "Chatterup"; $server = "SERVER"; $port = "6667"; $channel = ""; ?> <html> <head> <meta http-equiv="Content-Language" content="en"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Room List</title> </head> <body> <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" id="AutoNumber1" style="border-collapse: collapse"> <tr> <td width="8%" height="20" align="center" valign="middle" bgcolor="#FFFFCC" style="border-left:1px solid #333333;border-bottom:1px solid;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"> Users</td> <td width="15%" height="20" align="left" valign="middle" bgcolor="#FFFFCC" style="border-bottom:1px solid;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"> Roomname:</td> <td width="77%" height="20" align="left" valign="middle" bgcolor="#FFFFCC" style="border-right:1px solid #333333;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"> Topic:</td> </tr> <?php $fp = fsockopen($server, $port, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { fputs($fp,"USER $botnick $botnick 127.0.0.1 :php\n"); $nick = $botnick . rand(10000,99999); fputs($fp,"NICK $nick\n"); while (!feof($fp)) { usleep(50); $fget = @fgets($fp, 128); //echo "$fget <br>\n"; $match = explode(" ", $fget); $fget = ereg_replace ("\n", "", $fget); $fget = ereg_replace ("\r", "", $fget); if ($match[1] == "001") { fputs($fp,"LIST\n"); } else if ($match[0] == "PING") { fputs($fp, "PONG :" . $match[1]); } else if ($match[1] == "433") { $nick = $botnick . rand(10000,99999); fputs($fp,"NICK $nick\n"); } else if ($match[1] == "323") { fputs($fp, "QUIT :bye!\n"); break; } else if ($match[1] == "322") { $match[3] = ereg_replace ("#", "", $match[3]); if (eregi ("$channel(.*)", $match[3], $chan)) { $topic = explode(":", $fget); unset($topic[0]); unset($topic[1]); $topic = implode(":", $topic); if ($color == "FBFBF7") { $color = "FFFFFF"; } else { $color = "FBFBF7"; } ?> <tr> <td width="8%" align="center" valign="middle" bgcolor="#<?php echo $color; ?>" style="border-top:1px solid #333333;border-left:1px solid #333333;border-bottom:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"><?php echo $match[4]; ?></td> <td width="15%" style="border-bottom:1px solid #333333;bordertop:1px solid #333333;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;" bgcolor="#<?php echo $color; ?>"> <a href="./chat.php?action=Chat&rmname=[EN]<?php echo $chan[1]; ?>"> <?php echo $chan[1]; ?> </a></td> <td width="77%" style="border-right:1px solid #333333;border-bottom:1px solid #333333;FONT-FAMILY:;border-top:1px solid #333333; verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"bgcolor="#<?php echo $color; ?>"> <?php echo $topic; ?></td> </tr> <?php } } } fclose($fp); } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/ Share on other sites More sharing options...
genericnumber1 Posted November 9, 2008 Share Posted November 9, 2008 In this case "$match[1]" isn't set, hence the error for offset, and the $color isn't set (because the if statement that contains the $color initializing code isn't run)... Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686135 Share on other sites More sharing options...
DJ24966 Posted November 9, 2008 Author Share Posted November 9, 2008 Can you explain to me how to fix it? I'm a bit confused right now. Kinda new to php. Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686145 Share on other sites More sharing options...
Mchl Posted November 9, 2008 Share Posted November 9, 2008 You can just disable notices. These are not actual errors. Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686147 Share on other sites More sharing options...
wildteen88 Posted November 9, 2008 Share Posted November 9, 2008 You can just disable notices. These are not actual errors. Its should still be fixed. EDIT: <?php $botnick = "Chatterup"; $server = "SERVER"; $port = "6667"; $channel = ""; ?> <html> <head> <meta http-equiv="Content-Language" content="en"> <meta name="GENERATOR" content="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Room List</title> </head> <body> <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" id="AutoNumber1" style="border-collapse: collapse"> <tr> <td width="8%" height="20" align="center" valign="middle" bgcolor="#FFFFCC" style="border-left:1px solid #333333;border-bottom:1px solid;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"> Users</td> <td width="15%" height="20" align="left" valign="middle" bgcolor="#FFFFCC" style="border-bottom:1px solid;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"> Roomname:</td> <td width="77%" height="20" align="left" valign="middle" bgcolor="#FFFFCC" style="border-right:1px solid #333333;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"> Topic:</td> </tr> <?php $fp = fsockopen($server, $port, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { fputs($fp,"USER $botnick $botnick 127.0.0.1 :php\n"); $nick = $botnick . rand(10000,99999); fputs($fp,"NICK $nick\n"); while (!feof($fp)) { usleep(50); $fget = @fgets($fp, 128); //echo "$fget <br>\n"; $match = explode(" ", $fget); $fget = ereg_replace ("\n", "", $fget); $fget = ereg_replace ("\r", "", $fget); if (isset($match[0]) && $match[0] == "PING") { fputs($fp, "PONG :" . $match[1]); } elseif(isset($match[1])) { if ($match[1] == "001") { fputs($fp,"LIST\n"); } else if ($match[1] == "433") { $nick = $botnick . rand(10000,99999); fputs($fp,"NICK $nick\n"); } else if ($match[1] == "323") { fputs($fp, "QUIT :bye!\n"); break; } else if ($match[1] == "322") { $match[3] = ereg_replace ("#", "", $match[3]); if (eregi ("$channel(.*)", $match[3], $chan)) { $topic = explode(":", $fget); unset($topic[0]); unset($topic[1]); $topic = implode(":", $topic); if ($color == "FBFBF7") { $color = "FFFFFF"; } else { $color = "FBFBF7"; } ?> <tr> <td width="8%" align="center" valign="middle" bgcolor="#<?php echo $color; ?>" style="border-top:1px solid #333333;border-left:1px solid #333333;border-bottom:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"><?php echo $match[4]; ?></td> <td width="15%" style="border-bottom:1px solid #333333;bordertop:1px solid #333333;border-top:1px solid #333333;FONT-FAMILY: verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;" bgcolor="#<?php echo $color; ?>"> <a href="./chat.php?action=Chat&rmname=[EN]<?php echo $chan[1]; ?>"> <?php echo $chan[1]; ?> </a></td> <td width="77%" style="border-right:1px solid #333333;border-bottom:1px solid #333333;FONT-FAMILY:;border-top:1px solid #333333; verdana;FONT-SIZE: 8pt;TEXT-DECORATION: none;"bgcolor="#<?php echo $color; ?>"> <?php echo $topic; ?></td> </tr> <?php } } } } fclose($fp); } ?> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686150 Share on other sites More sharing options...
genericnumber1 Posted November 9, 2008 Share Posted November 9, 2008 wildteen88's will work if you actually mean for it to work if $match[1] is not set, but if $match[1] should always be set, do a little debugging... trace back why $match[1] isn't set. $match = explode(" ", $fget); Here it's splitting a string into an array on the spaces. So if there's no $match[1] set, that means that there's no space in $fget. Let's trace back why that is so. Uncomment the line that echos $fget, that may help. My theory without seeing the output of fget: Either the input is malformed, and there really is no space, or the line before the space is longer than 128-1 bytes. What do you mean "embed" the page? include()? file_get_contents() over a url? an iframe? Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686158 Share on other sites More sharing options...
DJ24966 Posted November 9, 2008 Author Share Posted November 9, 2008 Here is the site: http://chatterup.webhop.net/site By embedding I mean by just clicking Roomlist in the navigation menu, and it shows up within the layout of the site. You guys can view the output of the page by clicking roomlist. All it does is pull the currently open rooms from an IRC server, and displays them. Uncommenting that line just displays server information. I have done it to allow you guys to see what it is doing. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686180 Share on other sites More sharing options...
genericnumber1 Posted November 10, 2008 Share Posted November 10, 2008 Try wildteen's code and see if it does what you want, if not, try the debugging steps I've suggested to you. Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686468 Share on other sites More sharing options...
DJ24966 Posted November 10, 2008 Author Share Posted November 10, 2008 With his code, I'm still getting the following error Notice: Undefined variable: color in C:\wamp\www\site\pages\roomlist.php on line 70 Otherwise, it works. Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686474 Share on other sites More sharing options...
wildteen88 Posted November 10, 2008 Share Posted November 10, 2008 Change if ($color == "FBFBF7") { $color = "FFFFFF"; } else { $color = "FBFBF7"; } to $color = (isset($color) && $color == "FBFBF7") ? "FFFFFF" : "FBFBF7"; Quote Link to comment https://forums.phpfreaks.com/topic/132036-notice-undefined-offset-1/#findComment-686889 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.