PHP - Messaging With Server For Data (chat-like Page Loading)
I've been trying to figure out how chat apps work all afternoon to do dynamic data in HTML loading. Can someone please tell me where I'm going wrong for the code flow in this script:
<script> function submitchat{ if (form1.uname.value=='' || form1.msg.value==''){ alert("fill out whole form"); return; } var uname=form1.uname.value; var msg=form1.msg.value; var xmlhttp= new XMLHttpRequest(); xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState==4 && xmlhttp.status=200){ document.getElementById('chatlogs').innerHTML=xmlhttp.responseText; alert("message sent"); } xmlhttp.open('GET', '?page=3.2&uname='+uname+'&msg='+msg, true); xmlhttp.send(); } </script> <form name="form1"> enter your chat name<input type="text" name="uname"> message: <textarea name="msg"></textarea> <br> <div id="chatlogs">Loading Chat Logs...</div> <a href="#" onclick="">send</a> </form> <?php $uname = $_REQUEST['uname']; $msg = $_REQUEST['msg']; if ($msg!='' && $uname!=''){ $chat=" INSERT INTO chat ( `uname` , `msg` ) VALUES ( '$uname', '$msg' )"; $result = mysql_query($chat, $con) or die (sql_death($chat)); } Similar TutorialsI am not sure how I should go about doing this. I have a server that has a chat server on it, people register an account and then have access to this chat server from their application. To initially connect to it, they need a game id and game stamp (kind of like a username/password for the game). I don't want chats from one application to display in another users application. When I created this chat server it was for another purpose, and could only support about 64,510 different chats since each chat ran on its own port. For my current purpose it is a little different some applications can have 1 - 10 chats going at once per user using the application. Say their is 100 people using the application and each is using 5 - 10 different chat windows. With 100 users on at the same time all chatting, that can get up to 1,000 different ports being used. I don't want that, because say there are 100 applications also using chat, that is about 100,000 different ports, and I am pretty sure you cant have 100,000 ports. So! I need a way to make a chat server, any ideas on how I could do this with my php? need more information? please ask! I have a php tutorial that I followed for creating, inserting, selecting and updating a MySQL database with php. Everything works fine so I wanted to put it into Wordpress. I took the code and placed it into the wordpress page and everything worked just fine except the update function. Here is the tutorial I used. http://www.phpsimple.net/mysql_insert_record.html It is also the part I am having trouble with. I am able to create a record and I am also able to select a record but when I choose "update" the form doesn't load the data. It will outside the website but not inside wordpress. I am hoping this is not vague but because of my inexperience I am not sure what else to say. I will be more than happy to provide any other information you need. Hi i would like a simple chat page on my site for my members. i already have a site login database and want to know how i can let people chat and have their names entered with thier message without them having to login in to something else or typing their name with each message, for example - tom says: hello Here's the code that deals with the client side:
<?php session_start(); if(!isset($_SESSION['Logged_in'])){ header("Location: /page.php?page=login"); } ?> <!DOCTYPE Html> <html> <head> <!--Connections made and head included--> <?php require_once("../INC/head.php"); ?> <?php require_once("../Scripts/DB/connect.php"); ?> <!--Asynchronously Return User Names--> <script> $(document).ready(function(){ function search(){ var textboxvalue = $('input[name=search]').val(); $.ajax( { type: "GET", url: 'search.php', data: {Search: textboxvalue}, success: function(result) { $("#results").html(result); } }); }; </script> </head> <body> <div id="header-wrapper"> <?php include_once("../INC/nav2.php"); ?> </div> <div id="content"> <h1 style="color: red; text-align: center;">Member Directory</h1> <form onsubmit="search()"> <label for="search">Search for User:</label> <input type="text" size="70px" id="search" name="search"> </form> <a href="index.php?do=">Show All Users</a>|<a href="index.php?do=ONLINE">Show All Online Users</a> <div id="results"> <!--Results will be returned HERE!--> </div>search.php <?php //testing if data is sent ok echo "<h1>Hello</h1><br>" . $_GET['search']; ?>This is the link I get after sending foo. http://www.family-li...php?&search=foo Is that mean it was sent, but I'm not processing it correctly? I'm new to the whole AJAX thing. I wish to create validation rules once which are used both on the client and on the server.
For instance, I will start off with the following PHP object:
stdClass Object ( [rules] => stdClass Object ( [email] => stdClass Object ( [required] => 1 [email] => 1 [remote] => stdClass Object ( [url] => check-email.php [type] => post [data] => stdClass Object ( [username] => function() {return $( '#username' ).val();} ) ) ) ) [messages] => stdClass Object ( [email] => stdClass Object ( [required] => an email is required ) ) )When the edit page is downloaded to the client, I will include this object in some format suitable to the client. The client will then use the jQuery Validation plugin (http://jqueryvalidation.org/) along with the validation object, and client side validate the page. When the form passes client side validation and is uploaded, PHP will use the same validation object to serverside validate the form (I have this part working as desired). My question is how should I pass this data to the client? Originally, I would just use PHP to write some JavaScript. exit('var myObj='.json_encode($myObj));Note that when I json_encode the object, the value of $myObj->rules->email->remote->data->username is a string with quotes around it, however, I can easily use PHP to strip these tags before sending it to the client. As Jacques1 pointed out in http://forums.phpfre...ascript-client/, I should never ever use PHP to generate JavaScript, and should use AJAX to download the JSON directly. I tried doing the later, but found that a callback function could not be included in the JSON. Please advise on the best way to accomplish this. Thank you i am new with web socket
and in same time
I try to make server and client communication for soccer manager application, and for this purpose, i need to create closed "chat rooms" or "games" where two users can watch (read game event) and menage (create) game event (make substitution, formation ... or if you want, to send message to server, that they make changes in formation)
this game (room) mast bi secret, and only this two player can use this game for "read" and "write" events in game
for example: Game no: 200001 between user A and user B in 14.05.
when User A, and User B click on game no. 200001 they can read and write game event.
PS: for now, i create basic chat aplication with PHP, jQuery and webSocket and in this app, all user see wath all other user do (public chat) and i want to make secret chat for specific user (already automate subscribed from server) All work with no problem (i work on this example http://www.sanwebe.c...ket-php-socket)
How i can create chat room(s) and subscribe user to specific chat room?
Thanks
Edited by laponac84, 30 November 2014 - 09:09 AM. Looking for the best way to set-up the db of a messaging system. Here's what I have so far (basically pulled from another forum), don't know if Table1 is even really necessary: Table1: id user_message_id recepient_id recepient_read Table2: user_message_id sender_id sender_read subject message created_at updated_at Basically it needs to function where, someone submits a message to the admin or moderator, the admin/moderators can review and reply, and then the user can submit another reply, and keeps going indefinitely. I want each reply to show up almost like a forum thread. How would I chain the reply messages to the original messages? Hello, I'm pretty sure this is possible, but I have no idea where to start... I'm creating an anonymous messaging system for my school and I've had a lot of students request that they be able to send messages via sms text. I want to find a way for the students to send a text message to some number or maybe an email address using their cell phone. I want to have a php page that processes the message and then forwards it to a specific person depending on what the first word of the message is. For example: Someone sends a message that reads: "John: This is a text message." I want to be able to forward the message, "This is a text message." to the user named John. Any ideas on where to start? Is this even something that can be feasibly done? im setting up a php and jQuery pm system and have run into a problem. When a user clicks on a message in the left column the right column is supposed to be populated with the message contents, however the content stays the same whichever message is clicked. Code: (php) [Select] <?php $query = $link->query("SELECT * FROM ".TBL_PREFIX."messages WHERE m_sent_to = '$user_name'") or die(print_link_error()); $row = $query->fetchAll(); foreach($row as $key => $value) { $_message_list .= '<dl class="message_row" id="row-'.$row[$key]['m_mid'].'">'; $_message_list .= '<dd class="message_author">'.profile_link($row[$key]['m_author']).'</dd>'; $_message_list .= '<dd class="message_date">'.asf_date($row[$key]['m_date_sent'], 'short').'</dd>'; $_message_list .= '<dd class="message_checkbox"><input type="checkbox" id="checkbox-'.$row[$key]['m_mid'].'" /></dd>'; $_message_list .= '<dd class="message_subject">'.$row[$key]['m_subject'].'</dd>'; $_message_list .= '</dl>'; $template->message_content = $row[$key]['m_content']; } ?> and the jQuery Code: (js) [Select] <script type="text/javascript"> $j = jQuery.noConflict(); $j(document).ready(function(){ $j('dl.message_row').click(function(){ $j('li.message').html('<?php echo $this->message_content; ?>'); }); }); </script> The content display is always the content of the last message. This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=352279.0 Hello,
I want to grab some data from this site, using a script.
But I am stuck right at the beginning. If you go to the site, you can make a selection with the drop-down-boxes and get some output. For example if you select (left side: text on page in dutch / right side: translation in english):
Selecteer competitienaam: Najaarscompetitie 2014 Select league name: Autumn League 2014 Selecteer competitiegroep: Eredivisie dames Select league group: Eredivisie ladies Selecteer weergave: Programma (incl. uitslagen en stand) Select view: Program (including results and position) Optioneel poule filter: De Treffers R Optional group filter: De Treffers R Selecteer poule(s): Eredivisie - Poule A Select group(s): Premier League - Group A I want to grab the output you get after making all the selections. When I look at the webbrowser's page source the selections (drop-down-boxes) are inside an iframe from another domain: <iframe src="http://www.nttb-competitie.nl/" width="100%" height="1200" scrolling="yes" frameborder="0" name="NTTB_Competitie"></iframe>I figured out: First, the script gets url: http://www.nttb-competitie.nl/selectie.php?anr=0And after last selection it gets url: http://www.nttb-competitie.nl/web_programma.php?reset=0&pidString=1009267&sc=0&vastgesteldeAfdelingsnr=0&cnid=10085&cid=10704&view=programma&pf=1269&pid=1009267My problem is when I copy those URL's in a webbroser 's address bar, I get a page with only the words: Ongeldige aanroep!Which means "Invalid Call!" So my question is: How can I grab the data instead of this stupid message? Is it even possible or is it somehow protected? Please help! Having some issues, hopefully you guys can identify a solution for me. There are 7 Servers involved in this situation - Each with its own website. Server 1 houses a page with content that is shared by the other 6 servers. I need to change an image (logo) at the top of Server 1 page based upon which server they originally came from. For example they are traveling from server 4, when they arrive at server 1 they see server 1 content however the image at the top will corrospond with correct brand in this example server 4's logo. Cookies have not been a reliable solution considering they are usually disabled. Please Help Guys, Any feedback is Fantastic! Hello,
I want to grab some data using a script from this site.
But I am stuck right at the beginning. If you make a selection with the drop down boxes you get some output. For example you select:
Selecteer competitienaam: Najaarscompetitie 2014 Selecteer competitiegroep: Eredivisie dames Selecteer weergave: Programma (incl. uitslagen en stand) Optioneel poule filter: De Treffers R Selecteer poule(s): Eredivisie - Poule A I want to grab this output. When I look at the page source it is inside an iframe: <iframe src="http://www.nttb-competitie.nl/" width="100%" height="1200" scrolling="yes" frameborder="0" name="NTTB_Competitie"></iframe>I figured out: The script on the site first it gets url: http://www.nttb-competitie.nl/selectie.php?anr=0And after last selection it gets url: http://www.nttb-competitie.nl/web_programma.php?reset=0&pidString=1009267&sc=0&vastgesteldeAfdelingsnr=0&cnid=10085&cid=10704&view=programma&pf=1269&pid=1009267My problem is when I copy those URL's in a webbroser I get a page with only the words: Ongeldige aanroep!Which means "Invalid Call!" So my question is: How can I grab the data instead of this stupid message. Is it even possible or is it somehow protected? Please help! I seem to have a problem with a PHP page I made. When executed on the server, it loads with a filesize 0 and for some browsers, says it does not exist. I believe that the cause is because it is not parsing due to a syntax error. I've busted my @$$ over this code, trying to find the issue, but cannot find it. Here is the whole page's code on pastie: http://pastie.org/1064160 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=349747.0 hello sir, i have to connect database to my live server using <?php
define('DB_HOST', 'localhost'); ?> or
Hey guys i am writing a code which will get data frm the user and then write a file in my server and well sadly i am really confused with the annoying errors and warnings i am getting please help here is my code <?php //This File Gets the data from the chat setup form and then writes the chat file or edits it //Get Data from the form $cname=$_POST['cname']; $nicklen=$_POST['nicklen']; $msglen=$_POST['msglen']; $pm=$_POST['pm']; $msgh=$_POST['msgh']; $aname=$_POST['aname']; $pass=$_POST['pass']; $cheight=$_POST['cheight']; $cwidth=$_POST['cwidth']; $prcadmin=$_POST['prcadmin']; $cas=$_POST['cas']; $frznick=$_POST['frznick']; $sm=$_POST['sm']; $id=$_COOKIE["id"]; //Check if the cookie id is empty if (!isset($id)) { header( 'Location: www.techbreeze.in/mychat/chat-add.html') ; } //Check if any field is empty and redirect to setup page if empty if ((isset($cname))&&(isset($nicklen))&&(isset($msglen))&&(isset($pm))&&(isset($msgh))&&(isset($aname))&&(isset($pass))&&(isset($cheight))&&(isset($cwidth))) { if ((is_numeric ($nicklen)) && (is_numeric ($msglen))&&(is_numeric($pm))&&(is_numeric($msgh))&&(is_numeric ($cheight))&&(is_numeric ($cwidth))) { //Start writting data into the file $str1=";"; $str2 = ".php"; $str4 = "\n"; $File = $id . $str2; $fh = fopen($File, 'w') or die("can't open file"); $stringData = "<?php\n"; fwrite($fh, $stringData); $strt1= "require_once /mychat/src/phpfreechat.class.php;\n"; $stringData = $strt1; fwrite($fh, $stringData); $strt1='$params["serverid"] ='; $stringData = $strt1 . $id . $str1 . $str4; fwrite($fh, $stringData); fclose($fh); $strt3 = "$params"; $stringData = $strt3; fwrite($fh, $stringData); fclose($fh); } else { echo "Only numeric Inputs allowed for the fields"; echo "<br><br><br>"; echo "Enter the maximum length of nick"; echo "<br>"; echo "Maximum Lenth of message"; echo "<br>"; echo "Max number of Simultaneous PM"; echo "<br>"; echo "No. of msg to be stored in history"; echo "<br>"; echo "Height of the Chat Room"; echo "<br>"; echo "Width of Chat Room"; echo "<br><br><br>"; echo "Please Fill them up Carefully!"; echo "<meta HTTP-EQUIV='REFRESH' content='6; url= http://www.techbreeze.in/chat-setup.html'>"; } } else { echo "You Have one or more incomplete Field"; echo "<br>"; echo "Please Fill them up Carefully!"; echo "<meta HTTP-EQUIV='REFRESH' content='2; url= http://www.techbreeze.in/chat-setup.html'>"; } ?> ok now the error i am getting is Quote Warning: fclose(): 3 is not a valid stream resource in /home/techbr/domains/techbreeze.in/public_html/mychat/chatcreate.php on line 52 Any ideas as to what i should do and why i am getting this error. All good with sending single dimensional form data to the server using application/x-www-form-urlencoded, and having PHP convert it into an array. Also, good with sending simple arrays using []. But then I find myself needing to send a deeper object to the server . For example, I have a form with three text inputs simpleFormName 1, 2, and 3 plus some deeper object. Array ( [simpleFormName1] => bla [simpleFormName2] => bla [simpleFormName3] => bla [deeperObject] => Array ( [0] => Array ( [prop1] => bla [prop2] => true [data] => Array ( [0] => Array ( [p1] => 321 [p2] => 123 ) [1] => Array ( [p1] => 121 [p2] => 423 ) [2] => Array ( [p1] => 221 [p2] => 133 ) ) ) [1] => Array ( [prop1] => blabla [prop2] => false [data] => Array ( [0] => Array ( [p1] => 222 [p2] => 443 ) [1] => Array ( [p1] => 321 [p2] => 213 ) [2] => Array ( [p1] => 111 [p2] => 421 ) ) ) ) )
I see at least four options: Come up with naming structure which "flattens" the data. I have used this approach in the past, but it quickly becomes difficult to manage and I don't want to do so. Not use PHP's POST and and instead use Content-Type: application/json and file_get_contents(php://input) and json_decode the entire request server side. Use PHP's POST and urlencoding but make deeperObject a string using JSON.stringify and json_decode this one field server side. Urlencode the entire object.simpleFormName1=bla&simpleFormName2=bla&simpleFormName3=bla&deeperObject%5B0%5D%5Bprop1%5D=bla&deeperObject%5B0%5D%5Bprop2%5D=true&deeperObject%5B0%5D%5Bdata%5D%5B0%5D%5Bp1%5D=321&deeperObject%5B0%5D%5Bdata%5D%5B0%5D%5Bp2%5D=123&deeperObject%5B0%5D%5Bdata%5D%5B1%5D%5Bp1%5D=121&deeperObject%5B0%5D%5Bdata%5D%5B1%5D%5Bp2%5D=423&deeperObject%5B0%5D%5Bdata%5D%5B2%5D%5Bp1%5D=221&deeperObject%5B0%5D%5Bdata%5D%5B2%5D%5Bp2%5D=133&deeperObject%5B1%5D%5Bprop1%5D=blabla&deeperObject%5B1%5D%5Bprop2%5D=false&deeperObject%5B1%5D%5Bdata%5D%5B0%5D%5Bp1%5D=222&deeperObject%5B1%5D%5Bdata%5D%5B0%5D%5Bp2%5D=443&deeperObject%5B1%5D%5Bdata%5D%5B1%5D%5Bp1%5D=321&deeperObject%5B1%5D%5Bdata%5D%5B1%5D%5Bp2%5D=213&deeperObject%5B1%5D%5Bdata%5D%5B2%5D%5Bp1%5D=111&deeperObject%5B1%5D%5Bdata%5D%5B2%5D%5Bp2%5D=421 Any recommendations how to best implement? If you recommend using urlencoding for simple forms, but some other approach for more complex data, what criteria do you use to transition from one approach to another? Thanks I have a PHP Page. It is doing a lot of site crawling, throughout a lot of loops. Basically it's getting a massive array together and it's huge. However, it's so big that PHP times out beyond belief. I mean there is no error or nothing. Google throws a major error about page not found, IE shows an internet connection error. It really times out big time. Even though it's not really "A LOT". Any advice on what to do in that situation. I can't show the site/code because of NDA, but was curious if someone had ever done that much work on a PHP page before to have it do that? I have a script which registers people to a database, however it doing something very strange. Whenever I place it into even a single CSS div it adds the registration to the dabase but stops loading the next page (index.php) I find this totally bizarre as I haven't seen anything like this behave before. With CSS affecting how PHP works. Especially when the CSS is not inside the <php> of <form> tags. Code: [Select] <?php include("connect.php"); if($_POST['submit']) { $username = mysql_real_escape_string(trim($_POST['username'])); $password = trim($_POST['password']); $password2 = trim($_POST['password2']); $email = mysql_real_escape_string(trim($_POST['email'])); $error = false; if(!isset($username) || empty($username)) { $error = "You need to enter a username."; } $query = mysql_query("SELECT id FROM users WHERE username = '".$username."' LIMIT 1"); if(mysql_num_rows($query) > 0 && !$error) { $error = "Sorry, that username is already taken!"; } if((!isset($password) || empty($password)) && !$error) { $error = "You need to enter a password."; } if((!isset($password2) || empty($password2)) && !$error) { $error = "You need to enter your password twice."; } if($password != $password2 && !$error) { $error = "The passwords you entered did not match."; } if((!isset($email) || empty($email)) && !$error) { $error = "You need to enter an email."; } if(preg_match("/[a-zA-Z0-9-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) == 0 && !$error) { $error = "The email you entered is not valid."; } $query = mysql_query("SELECT id FROM users WHERE email = '".$email."' LIMIT 1"); if(mysql_num_rows($query) > 0 && !$error) { $error = "Sorry, that email is already in use!"; } if(!$error) { $query = mysql_query("INSERT INTO users (username, password, email) VALUES ('".$username."', '".mysql_real_escape_string(md5($password))."', '".$email."')"); if($query) { $message = "Hello ".$_POST['username'].",\r\n\r\nThanks for registering! We hope you enjoy your stay.\r\n\r\nThanks,\r\nJohn Doe"; $headers = "From: ".$website['name']." <".$website['email'].">\r\n"; mail($_POST['email'], "Welcome", $message, $headers); setcookie("user", mysql_insert_id(), $time); setcookie("pass", mysql_real_escape_string(md5($password)), $time); header("Location: index.php"); } else { $error = "There was a problem with the registration. Please try again."; } } } ?><html> <head> <title>Register</title> </head> <body> <form action="" method="post"> <?php if($error) echo "<span style=\"color:#ff0000;\">".$error."</span><br /><br />"; ?> <label for="username">Username: </label> <input type="text" name="username" value="<?php if($_POST['username']) echo $_POST['username']; ?>" /><br /> <label for="password">Password: </label> <input type="password" name="password" value="<?php if($_POST['password']) echo $_POST['password']; ?>" /><br /> <label for="password2">Retype Password: </label> <input type="password" name="password2" value="<?php if($_POST['password2']) echo $_POST['password2']; ?>" /><br /> <label for="email">Email: </label> <input type="text" name="email" value="<?php if($_POST['email']) echo $_POST['email']; ?>" /><br /><br /> <input type="submit" name="submit" value="Register" /> </form> </body> |