jdeutsch Posted December 25, 2007 Share Posted December 25, 2007 I'm attempted to put together a simple chat script based solely on PHP/MySQL. I'm using iframes to juggle the chat window, and the list of users currently online, however, I keep running into problems. I've worked with iframes and php together before and never experienced these issues, so I'm stumped. I've got most of the site-wide functions grouped into a single file, for easy access, and have been requiring this file on each page where the functions will be used. This also includes my MySQL connection script. Using session_start and require on the parent page works fine, however, if I attempt to use either on the iframe source pages, I get a "session already started" error, and a "cannot redeclare XXXX function" error respectively. However, if I comment out the session_start or the require, the iframe source no longer recognizes the session variables, or the previously declared functions. I don't know what I'm doing wrong, and I'm sure it's something remarkably simple, but I've been going nuts trying to solve this for several hours now. Below are the affected snippets: INDEX.PHP (the parent page for the chat frames) <? session_start(); require("../scripts/includes.php"); if(!isset($_SESSION['chat_id'])) $_SESSION['chat_id']=generate_chat_id(); ?> ... <iframe src="chat_window.php" scrolling="auto" name="chat_window" id="chat_window"></iframe> <iframe src="online.php" scrolling="auto" name="online" id="online"></iframe> <div id="controls"> <form method="post" action="chat_window.php" target="chat_window"> <textarea name="msg" id="chat_msg"></textarea> <input type="hidden" name="chat_id" value="<? print $_SESSION['chat_id']; ?>" /> <input type="submit" value="Submit" name="send" id="submit_button" /> </form> </div> CHAT_WINDOW.PHP (displays the chat dialogue) <? session_start(); require("../scripts/includes.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body bgcolor="#FFFFFF"> <? $chat=get_chat($_SESSION['chat_id']); for($i=0;$i<count($chat);$i++) { if($chat[$i]['uid']==$_SESSION['uid']) $other_style=" blue"; else $other_style="red"; if(isset($_SESSION['admin'])) $a="admin"; else $a=""; print "<span class=\"dialogue\"><span class=\"username".$other_style."\">".get_username_from_id($chat[$i]['uid'],$a)." <span class=\"small\">(".date("m/d/Y h:i:sA",$chat[$i]['timestamp']).")</span> <span class=\"text\">".$chat[$i]['dialogue']."</span></span>"; } print time(); ?> </body> </html> ONLINE.PHP (displays the users online) <? session_start(); require("../scripts/includes.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Untitled Document</title> </head> <body bgcolor="#FFFFFF"> <? $online=get_users_online(); for($i=0;$i<count($online);$i++) { print "<span class=\"online\"><a href=\"?u=".$online[$i]."&invite&new_chat\">".$online[$i]."</a></span>"; } ?> </body> </html> INCLUDES.PHP (running list of all required scripts) <? require("mysql.php"); require("functions.php"); require("online.php"); ?> Any and all help with this would be appreciated. Happy holidays! Quote Link to comment https://forums.phpfreaks.com/topic/83118-php-sessions-and-require-within-iframes/ Share on other sites More sharing options...
redarrow Posted December 25, 2007 Share Posted December 25, 2007 use ob_start() and at the end of page use ob_flush(); Quote Link to comment https://forums.phpfreaks.com/topic/83118-php-sessions-and-require-within-iframes/#findComment-422787 Share on other sites More sharing options...
jdeutsch Posted December 25, 2007 Author Share Posted December 25, 2007 Thanks for the quick reply. I've never used ob_start or flush before, though I've read about them in the php manual. Which page(s) am I using them on, and do I need to include anything specific with them? Quote Link to comment https://forums.phpfreaks.com/topic/83118-php-sessions-and-require-within-iframes/#findComment-422950 Share on other sites More sharing options...
jdeutsch Posted December 26, 2007 Author Share Posted December 26, 2007 Still isn't working. Don't quite understand why this is causing such an issue. I've also tried every combination of using ob_start, but still get similar errors, or no data. Quote Link to comment https://forums.phpfreaks.com/topic/83118-php-sessions-and-require-within-iframes/#findComment-423235 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.