shebbycs Posted December 9, 2011 Share Posted December 9, 2011 chatlog.php <html> <head> <script type="text/javascript"> var refreshPeriod = 120; // 120 Seconds function refresh() { document.cookie = 'scrollTop=' + filterScrollTop(); document.cookie = 'scrollLeft=' + filterScrollLeft(); document.location.reload(true); } function getCookie(name) { var start = document.cookie.indexOf(name + "="); var len = start + name.length + 1; if(((!start) && (name != document.cookie.substring(0, name.length))) || start == -1) return null; var end = document.cookie.indexOf(";", len); if(end == -1) end = document.cookie.length; return unescape(document.cookie.substring(len, end)); } function deleteCookie(name) { document.cookie = name + "=" + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; } function setupRefresh() { var scrollTop = getCookie("scrollTop"); var scrollLeft = getCookie("scrollLeft"); if (!isNaN(scrollTop)) { document.body.scrollTop = scrollTop; document.documentElement.scrollTop = scrollTop; } if (!isNaN(scrollLeft)) { document.body.scrollLeft = scrollLeft; document.documentElement.scrollLeft = scrollLeft; } deleteCookie("scrollTop"); deleteCookie("scrollLeft"); setTimeout("refresh()", 2000); } function filterResults(win, docEl, body) { var result = win ? win : 0; if (docEl && (!result || (result > docEl))) result = docEl; return body && (!result || (result > body)) ? body : result; } // Setting the cookie for vertical position function filterScrollTop() { var win = window.pageYOffset ? window.pageYOffset : 0; var docEl = document.documentElement ? document.documentElement.scrollTop : 0; var body = document.body ? document.body.scrollTop : 0; return filterResults(win, docEl, body); } // Setting the cookie for horizontal position function filterScrollLeft() { var win = window.pageXOffset ? window.pageXOffset : 0; var docEl = document.documentElement ? document.documentElement.scrollLeft : 0; var body = document.body ? document.body.scrollLeft : 0; return filterResults(win, docEl, body); } </script> </head> <body onload="setupRefresh()"> <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } ?> </body> </html> When its auto refresh it wil going to the bottom can u show me which one need to be modify Quote Link to comment https://forums.phpfreaks.com/topic/252849-how-its-update-the-chat-to-the-bottom/ Share on other sites More sharing options...
shebbycs Posted January 24, 2012 Author Share Posted January 24, 2012 [b]Chatlog.php[/b] <?php $db = mysql_connect("localhost", "root") or die("Could not connect."); //username and password mysql_select_db("cute") or die(mysql_error()); $getnummessages="SELECT COUNT(*) as messagecount from chatmessages"; $getnummessages2=mysql_query($getnummessages) or die("blah"); $getnummessages3= mysql_result($getnummessages2, 0); if($getnummessages3>40) { $startrow=$getnummessages3-20; } else { $startrow=0; } $getmsg="SELECT name, message from chatmessages order by postime ASC limit $startrow,$getnummessages3"; $getmsg2=mysql_query($getmsg) or die(mysql_error()); function replacesmiley($msg) { $msg = str_replace('', '<img src="smile.gif" alt="" />', $msg); $msg = str_replace('', '<img src="sad.gif" alt="" />', $msg); $msg = str_replace('', '<img src="tongue.gif" alt="" />', $msg); return $msg; } echo replacesmiley($text); function filterBadWords($str) { $result = mysql_query("SELECT badwords FROM clean") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['badwords'], str_repeat('*', strlen($row['badwords'])), $str); } return $str; } while($getmsg3=mysql_fetch_array($getmsg2)) { $getmsg3['message'] = replacesmiley($getmsg3['message']); $getmsg3['message'] = filterBadWords($getmsg3['message']); //Smiley faces print "<font color='blue'><b>$getmsg3[name]:</b></font> $getmsg3[message]<br>"; } ?> <script> setTimeout("window.location.replace('chatlog.html')",2000); var objDiv = document.body; objDiv.scrollTop = objDiv.scrollHeight; </script> Form2.php <?php session_start(); if (empty($_SESSION['is_logged_in'])) { header("Location:chatframe2.php"); die(); // just to make sure no scripts execute } ?> <?php mysql_connect("localhost","root") or die(mysql_error()); mysql_select_db("cute") or die(mysql_error()); $message=$_POST['message']; $a=$_SESSION['username']; if(isset($_POST['submit'])) //if submit button push has been detected { if(strlen($message)>=1) { $message=strip_tags($message); $IP=$_SERVER["REMOTE_ADDR"]; //grabs poster's IP $checkforbanned="SELECT IP from ipbans where IP='$IP'"; $checkforbanned2=mysql_query($checkforbanned) or die("Could not check for banned IPS"); if(mysql_num_rows($checkforbanned2)>0) //IP is in the banned list { echo("<SCRIPT LANGUAGE='JavaScript'>window.alert('You IP is banned from posting.')</SCRIPT>"); } else { $thedate = date("U"); //grab date and time of the post $insertmessage="INSERT into chatmessages (name,IP,postime,message) values('$a','$IP','$thedate','$message')"; mysql_query($insertmessage) or die("Could not insert message"); } } } ?> <html> <head> <script type="text/javascript"> function addsmiley(code) { var pretext = document.smile.message.value; this.code = code; document.smile.message.value = pretext + code; } function a() { var x = document.smile.message.value; if(x=="") { alert("Please insert an message!"); return false; } } </script> <style type="text/css"> body{ background-color: #d8da3d } </style> </head> <body> <center> <form name="smile" method="post" action="form2.php" onSubmit="return a()" > <b>Message:</b>                                 <a style="text-decoration:none" <a href="javascript: void(0)" onclick="window.open('banip.php', 'windowname2', 'width=400, \ height=150, \ directories=no, \ location=no, \ menubar=no, \ resizable=no, \ scrollbars=1, \ status=no, \ toolbar=no'); return false;">Action</a>            <a style="text-decoration:none" href="logout.php">Sign Out</a><br><textarea name='message' cols='40' rows='3'></textarea><br> <img src="smile.gif" alt="" onClick="addsmiley('')" style="cursor:pointer;border:0" /> <img src="p.gif" alt="" onClick="addsmiley('')" style="cursor:pointer;border:0" /> <img src="lol.gif" alt="*lol*" onClick="addsmiley('*lol*')" style="cursor:pointer;border:0" /> <img src="blush.gif" alt="*blush*" onClick="addsmiley('*blush*')" style="cursor:pointer;border:0" /> <img src="angry.gif" alt=":@" onClick="addsmiley(':@')" style="cursor:pointer;border:0" />                                             <input type='submit' name='submit' value='Send' class='biasa' ></form> <br> <br> </center> </body> </html> My question is how can the chat refresh to the bottom if the send button is clicked because as for now this two php files im means the chatlog.php refresh itself to the bottom but im want that form2.php that has send button so when it clicked then it updated to the bottom any suggestion ? Quote Link to comment https://forums.phpfreaks.com/topic/252849-how-its-update-the-chat-to-the-bottom/#findComment-1310748 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.