<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Coding Mix</title><link>http://www.codingmix.com/search/label/PHP%20tutorials</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/codingmix/PHP/tutorials" /><description></description><language>en</language><managingEditor>noreply@blogger.com (Csabi)</managingEditor><lastBuildDate>Thu, 23 Feb 2012 19:15:09 PST</lastBuildDate><generator>Blogger http://www.blogger.com</generator><openSearch:totalResults xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">11</openSearch:totalResults><openSearch:startIndex xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">1</openSearch:startIndex><openSearch:itemsPerPage xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/">25</openSearch:itemsPerPage><feedburner:info uri="codingmix/php/tutorials" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>codingmix/PHP/tutorials</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Upload an image and downsize it (in KB`s) using php and GD</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/NCdwKFvUDPA/php-gd-upload-image-downsize-compress.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sat, 15 Jan 2011 03:41:15 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-8181027301628160392</guid><description>If you have a website where you let your users to upload images, you know that even the small images (around 100x100) can reach 50 - 100KB. This is way too much, when you could simply downsize the image to around 1 - 5KB, this is only the 1 - 5% of the size of the original image. Just imagine the benefits of downsizing 100.000 images...&lt;br /&gt;Bellow is an image before and after resizing: &lt;div id="full-post"&gt;&lt;div class="code" style="width:250px;text-align:center;float:left;"&gt;&lt;b&gt;Before&lt;/b&gt;&lt;br /&gt;&lt;img src="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TTGCPr-nXDI/AAAAAAAAARE/4JiKiIIHmzs/s1600/example.jpg" border="0" alt="before resizing"/&gt;&lt;br /&gt;24.80KB&lt;/div&gt;&lt;div class="code" style="width:250px;text-align:center;float:left;"&gt;&lt;b&gt;After&lt;/b&gt;&lt;br /&gt;&lt;img src="http://2.bp.blogspot.com/_Ok7mVUxPcsk/TTGDXe5VtjI/AAAAAAAAARM/8131J6AA2xw/s1600/example.jpg" border="0" alt="after resizing" /&gt;&lt;br /&gt;3.52KB&lt;/div&gt;So let`s begin downsizing those images...&lt;br /&gt;&lt;b&gt;The upload form&lt;/b&gt;&lt;br /&gt;&lt;i&gt;upload-form.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;form action=&amp;quot;upload.php&amp;quot; method=&amp;quot;POST&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;hidden&amp;quot; name=&amp;quot;MAX_FILE_SIZE&amp;quot; value=&amp;quot;100000&amp;quot; /&amp;gt;&lt;br /&gt;Select image: &amp;lt;input name=&amp;quot;theimage&amp;quot; type=&amp;quot;file&amp;quot; /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Upload image&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/div&gt;&lt;b&gt;enctype=&amp;quot;multipart/form-data&amp;quot;&lt;/b&gt; - this line tells the server that you want to send a file&lt;br /&gt;&lt;b&gt;MAX_FILE_SIZE&lt;/b&gt; - limits the maximum file size in bytes&lt;br /&gt;&lt;b&gt;type=&amp;quot;file&amp;quot;&lt;/b&gt; - this is the file selecting input&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Checking the image&lt;/b&gt;&lt;br /&gt;First we need to check the file for 3 different problems: &lt;br /&gt;- it was submitted or not ?&lt;br /&gt;- it was uploaded ?&lt;br /&gt;- it is too big ?&lt;br /&gt;&lt;i&gt;upload.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;b&gt;Check image type&lt;/b&gt;&lt;br /&gt;Now we will check the type of the file, because we will accept only .jpg .gif and .png. At this step we will use some GD, too, because we will put our image in a variable:&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;      switch($_FILES['theimage']['type']){&lt;br /&gt;         case 'image/gif':&lt;br /&gt;         $image = imagecreatefromgif($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/jpeg':&lt;br /&gt;         case 'image/pjpeg':&lt;br /&gt;         $image = imagecreatefromjpeg($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/png':&lt;br /&gt;         $image = imagecreatefrompng($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      if(!isset($image)){&lt;br /&gt;         echo 'Only .gif, .jpg or .png images are allowed!';&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;b&gt;Working with transparent images&lt;/b&gt;&lt;br /&gt;We will downsize the images by converting it to .jpg. The jpg images can not be transparent and when the user uploads a transparent image, the transparent part will be painted in black. To make the transparent part white we need to create a white image with the same size as our uploaded image and then copy the uploaded image over the white image:&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;      switch($_FILES['theimage']['type']){&lt;br /&gt;         case 'image/gif':&lt;br /&gt;         $image = imagecreatefromgif($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/jpeg':&lt;br /&gt;         case 'image/pjpeg':&lt;br /&gt;         $image = imagecreatefromjpeg($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/png':&lt;br /&gt;         $image = imagecreatefrompng($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      if(!isset($image)){&lt;br /&gt;         echo 'Only .gif, .jpg or .png images are allowed!';&lt;br /&gt;      }&lt;br /&gt;      else {&lt;br /&gt;         $size = getimagesize($_FILES['theimage']['tmp_name']);&lt;br /&gt;         $background = imagecreatetruecolor($size[0],$size[1]);&lt;br /&gt;         $white = imagecolorallocate($background,255,255,255);&lt;br /&gt;         imagefill($background,0,0,$white);&lt;br /&gt;         imagecopy($background,$image,0,0,0,0,$size[0],$size[1]);&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;b&gt;Downsize the image&lt;/b&gt;&lt;br /&gt;This is the final step, when we save the image in .jpg format: &lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;if(isset($_FILES['theimage'])){&lt;br /&gt;   if($_FILES['theimage']['size'] &amp;lt; 1){&lt;br /&gt;      echo 'Upload error!';&lt;br /&gt;   }&lt;br /&gt;   else if($_FILES['theimage']['size'] &amp;gt; 100000){&lt;br /&gt;      echo 'The image is too big!';&lt;br /&gt;   }&lt;br /&gt;   else {&lt;br /&gt;      switch($_FILES['theimage']['type']){&lt;br /&gt;         case 'image/gif':&lt;br /&gt;         $image = imagecreatefromgif($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/jpeg':&lt;br /&gt;         case 'image/pjpeg':&lt;br /&gt;         $image = imagecreatefromjpeg($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;         case 'image/png':&lt;br /&gt;         $image = imagecreatefrompng($_FILES['theimage']['tmp_name']);&lt;br /&gt;         break;&lt;br /&gt;      }&lt;br /&gt;      if(!isset($image)){&lt;br /&gt;         echo 'Only .gif, .jpg or .png images are allowed!';&lt;br /&gt;      }&lt;br /&gt;      else {&lt;br /&gt;         $size = getimagesize($_FILES['theimage']['tmp_name']);&lt;br /&gt;         $background = imagecreatetruecolor($size[0],$size[1]);&lt;br /&gt;         $white = imagecolorallocate($background,255,255,255);&lt;br /&gt;         imagefill($background,0,0,$white);&lt;br /&gt;         imagecopy($background,$image,0,0,0,0,$size[0],$size[1]);&lt;br /&gt;         $image = $background;&lt;br /&gt;         $filename = explode(&amp;quot;.&amp;quot;,$_FILES['theimage']['name']);&lt;br /&gt;         $filename = $filename[0];&lt;br /&gt;         imagejpeg($image,$_SERVER['DOCUMENT_ROOT'] . '/thumbnails/' . $filename . '.jpg',90);&lt;br /&gt;         imagedestroy($image);&lt;br /&gt;         echo 'Your image: &amp;lt;img src=&amp;quot;/thumbnails/' . $filename . '.jpg&amp;quot; /&amp;gt;';&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'There is no image!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;If you have any questions please don`t hesitate to ASK!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-8181027301628160392?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/TIDxTpoJeUFz4Q0p14LfaKtOGyM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TIDxTpoJeUFz4Q0p14LfaKtOGyM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/TIDxTpoJeUFz4Q0p14LfaKtOGyM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/TIDxTpoJeUFz4Q0p14LfaKtOGyM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/NCdwKFvUDPA" height="1" width="1"/&gt;</description><media:thumbnail url="http://1.bp.blogspot.com/_Ok7mVUxPcsk/TTGCPr-nXDI/AAAAAAAAARE/4JiKiIIHmzs/s72-c/example.jpg" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">9</thr:total><feedburner:origLink>http://www.codingmix.com/2011/01/php-gd-upload-image-downsize-compress.html</feedburner:origLink></item><item><title>Private chat room script</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/4lWkAdU22qg/private-chat-room-script.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 04 Jan 2012 00:47:49 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5652676838774154670</guid><description>Finally my private chat room is ready! I`we used jQuery, PHP and 2 MySQL tables to write this script. This is the first version, this is some kind of beta version, because I hadn`t test it yet, because it needs at least 2 users to work... Here is a live demo, have fun with it and please tell me about the errors: &lt;div id="full-post"&gt;&lt;iframe src="" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;NOTES: &lt;br /&gt;Everything is refreshed each 15 seconds. &lt;br /&gt;An user is logged out after 10 minutes of inactivity.&lt;br /&gt;Each message is kept for 30 minutes.&lt;br /&gt;An users name is highlighted with orange if the user sent you a message.&lt;br /&gt;The selected username is highlighted with red.&lt;br /&gt;&lt;br /&gt;As I said, we will need two mysql tables: one to hold the users (username, ip, last activity date) and one for the messages (from, to, message, date). Here is my code to create the tables: &lt;br /&gt;&lt;i&gt;table1.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect(&amp;quot;host&amp;quot;, &amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_select_db(&amp;quot;database&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_query(&amp;quot;CREATE TABLE chatusers(&lt;br /&gt;   username VARCHAR(30),&lt;br /&gt;   ip CHAR(15),&lt;br /&gt;   lastactive INT UNSIGNED,&lt;br /&gt;   PRIMARY KEY(username)&lt;br /&gt;)&amp;quot;)&lt;br /&gt;or die(mysql_error()); &lt;br /&gt;echo &amp;quot;Table Created!&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;table2.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect(&amp;quot;host&amp;quot;, &amp;quot;username&amp;quot;, &amp;quot;password&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_select_db(&amp;quot;database&amp;quot;) or die(mysql_error());&lt;br /&gt;mysql_query(&amp;quot;CREATE TABLE messages(&lt;br /&gt;   messagefrom VARCHAR(30),&lt;br /&gt;   sendto VARCHAR(30),&lt;br /&gt;   message VARCHAR(255),&lt;br /&gt;   date INT UNSIGNED&lt;br /&gt;)&amp;quot;)&lt;br /&gt;or die(mysql_error()); &lt;br /&gt;echo &amp;quot;Table Created!&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;It`s hard to explain how it works... but I will try to. At the start if your ip is not in the database you will be asked for an username and you will be added to the database and a list with the online users is generated by the &lt;i&gt;onlineusers.php&lt;/i&gt; file. When you click on somebody the messages sent by that person to you and the messages sent by you to that person are shown by the &lt;i&gt;show-messages.php&lt;/i&gt; file. When you write a message and press the send button then your message will be sent to the selected user by saving it on the messages table.&lt;br /&gt;&lt;br /&gt;Here is the rest of the code:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;#chat {&lt;br /&gt;   width:500px;&lt;br /&gt;   margin:0 auto;&lt;br /&gt;}&lt;br /&gt;#login {&lt;br /&gt;   width:230px;&lt;br /&gt;   height:50px;&lt;br /&gt;   margin:100px;&lt;br /&gt;   border:1px solid black;&lt;br /&gt;   text-indent:10px;&lt;br /&gt;}&lt;br /&gt;.onlineuser {&lt;br /&gt;   padding:0 10px;&lt;br /&gt;   background:#CCC;&lt;br /&gt;   margin-left:2px;&lt;br /&gt;}&lt;br /&gt;.yes {&lt;br /&gt;   background:#F90;&lt;br /&gt;}&lt;br /&gt;.message {&lt;br /&gt;   float:left;&lt;br /&gt;   border:1px solid black;&lt;br /&gt;   width:498px;&lt;br /&gt;}&lt;br /&gt;.messdate {&lt;br /&gt;   float:right;&lt;br /&gt;}&lt;br /&gt;.selected {&lt;br /&gt;   background:red;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;script src=&amp;quot;http://code.jquery.com/jquery-latest.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot;&amp;gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;?php mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;)) == 0){ ?&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;login&amp;quot;&amp;gt;&lt;br /&gt;Select username: &amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;usernameinput&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Login&amp;quot; id=&amp;quot;loginbutton&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;?php } &lt;br /&gt;else {&lt;br /&gt;mysql_query(&amp;quot;UPDATE chatusers SET lastactive = &amp;quot; . time() . &amp;quot; WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;);&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;onlineusers&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;send&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; id=&amp;quot;sendbutton&amp;quot; disabled=&amp;quot;disabled&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;?php } ?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script&amp;gt;&lt;br /&gt;$('#loginbutton').click(function (){&lt;br /&gt;   if($(this).attr(&amp;quot;disabled&amp;quot;) != &amp;quot;disabled&amp;quot;){&lt;br /&gt;      var error = $.ajax({ &lt;br /&gt;         url: &amp;quot;login.php&amp;quot;,&lt;br /&gt;         data: &amp;quot;username=&amp;quot; + $('#usernameinput').val(),&lt;br /&gt;         async:false&lt;br /&gt;      }).responseText;&lt;br /&gt;      if(error != ''){&lt;br /&gt;         alert(error);&lt;br /&gt;      }&lt;br /&gt;      else {&lt;br /&gt;         location.reload();&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;var from = '';&lt;br /&gt;showusers();&lt;br /&gt;function showusers(){&lt;br /&gt;   $('#onlineusers').html($.ajax({&lt;br /&gt;      url: 'onlineusers.php?x=' + Math.random() + '&amp;amp;selected=' + from, &lt;br /&gt;      async:false&lt;br /&gt;   }).responseText);&lt;br /&gt;   $('#messages').html($.ajax({&lt;br /&gt;      url: 'show-messages.php',&lt;br /&gt;      data: '?x=' + Math.random() + '&amp;amp;from=' + from,&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText);&lt;br /&gt;   setTimeout('showusers()',15000); &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$('.onlineuser').click(function (){&lt;br /&gt;   from = $(this).html();&lt;br /&gt;   $('#messages').html($.ajax({&lt;br /&gt;      url: 'show-messages.php',&lt;br /&gt;      data: '?x=' + Math.random() + '&amp;amp;from=' + $(this).html(),&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText); &lt;br /&gt;   $('#sendbutton').removeAttr(&amp;quot;disabled&amp;quot;);&lt;br /&gt;   showusers();&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;$('#sendbutton').click(function (){&lt;br /&gt;   if($(this).attr(&amp;quot;disabled&amp;quot;) != &amp;quot;disabled&amp;quot;){&lt;br /&gt;      var message = $('#message').val();&lt;br /&gt;      $.ajax({&lt;br /&gt;         url: 'send.php?to=' + from + '&amp;amp;mes=' + message&lt;br /&gt;      });&lt;br /&gt;      $('#message').val('');&lt;br /&gt;      showusers();&lt;br /&gt;   }&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;i&gt;onlineusers.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;mysql_query(&amp;quot;UPDATE chatusers SET lastactive = &amp;quot; . time() . &amp;quot; WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;);&lt;br /&gt;$users = mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip != '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;); &lt;br /&gt;mysql_query(&amp;quot;DELETE FROM chatusers WHERE lastactive &amp;lt; &amp;quot; . (time() - 600)) or die(mysql_error());&lt;br /&gt;echo 'Online users: ';&lt;br /&gt;$username = mysql_fetch_array(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;));&lt;br /&gt;$username = $username['username'];&lt;br /&gt;while($row = mysql_fetch_array($users)){&lt;br /&gt;   $class = '';&lt;br /&gt;   $class2 = '';&lt;br /&gt;   if(mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM messages WHERE sendto = '&amp;quot; . $username . &amp;quot;' and messagefrom = '&amp;quot; . $row['username'] . &amp;quot;'&amp;quot;)) &amp;gt; 0) {&lt;br /&gt;      $class = 'yes';&lt;br /&gt;   }&lt;br /&gt;   if($_GET['selected'] == $row['username']){&lt;br /&gt;      $class2 = 'selected';&lt;br /&gt;   }&lt;br /&gt;   echo '&amp;lt;span class=&amp;quot;onlineuser ' . $class . ' ' . $class2 . '&amp;quot;&amp;gt;' . $row['username'] . '&amp;lt;/span&amp;gt;';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;$username = mysql_fetch_array(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;));&lt;br /&gt;$username = $username['username'];&lt;br /&gt;mysql_query(&amp;quot;DELETE FROM messages WHERE date &amp;lt; &amp;quot; . (time() - 1800));&lt;br /&gt;$result = mysql_query(&amp;quot;(SELECT * FROM messages WHERE messagefrom = '&amp;quot; . $_GET['from'] . &amp;quot;' and sendto = '&amp;quot; . $username . &amp;quot;' ORDER BY date ASC LIMIT 0, 10) UNION (SELECT * FROM messages WHERE messagefrom = '&amp;quot; . $username . &amp;quot;' and sendto = '&amp;quot; . $_GET['from'] . &amp;quot;' ORDER BY date ASC LIMIT 0, 10)&amp;quot;) or die(mysql_error()); &lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   if($row['messagefrom'] == $username){&lt;br /&gt;      $by = 'You';&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      $by = $_GET['from'];&lt;br /&gt;   }&lt;br /&gt;   echo '&amp;lt;div class=&amp;quot;message&amp;quot;&amp;gt;&amp;lt;b&amp;gt;' . $by . ':&amp;lt;/b&amp;gt; ' . $row['message'] . '&amp;lt;span class=&amp;quot;messdate&amp;quot;&amp;gt;' . date('g:i A M, d Y',$row['date']) . '&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;login.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM chatusers WHERE username = '&amp;quot; . $_GET['username'] . &amp;quot;'&amp;quot;)) == 0){&lt;br /&gt;   mysql_query(&amp;quot;INSERT INTO chatusers VALUES('&amp;quot; . $_GET['username'] . &amp;quot;', '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;', &amp;quot; . time() . &amp;quot;)&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   echo 'Username is taken';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'username', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;$username = mysql_fetch_array(mysql_query(&amp;quot;SELECT username FROM chatusers WHERE ip = '&amp;quot; . $_SERVER['REMOTE_ADDR'] . &amp;quot;'&amp;quot;));&lt;br /&gt;$username = $username['username'];&lt;br /&gt;mysql_query(&amp;quot;INSERT INTO messages VALUES('&amp;quot; . $username . &amp;quot;','&amp;quot; . $_GET['to'] . &amp;quot;', '&amp;quot; . $_GET['mes'] . &amp;quot;', &amp;quot; . time() . &amp;quot;)&amp;quot;) or die(mysql_error());&lt;br /&gt;?&amp;gt;&lt;/div&gt;If something is not working please let me know!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5652676838774154670?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Rglqm6WSt1Xu-pgKh8HLGXvpgmc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Rglqm6WSt1Xu-pgKh8HLGXvpgmc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Rglqm6WSt1Xu-pgKh8HLGXvpgmc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Rglqm6WSt1Xu-pgKh8HLGXvpgmc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/4lWkAdU22qg" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">23</thr:total><feedburner:origLink>http://www.codingmix.com/2010/12/private-chat-room-script.html</feedburner:origLink></item><item><title>Create SEO friendly URL`s using mod rewrite in PHP (.htaccess)</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/THJxx8t1S9k/mod-rewrite-seo-url-php-htaccess.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 19 Dec 2010 07:12:33 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-4458784298246858128</guid><description>In this tutorial I will show you how to transform this: &lt;div class="code"&gt;http://www.mywebsite.com/tutorials.php?id=123&amp;title=mod_rewrite&amp;category=php&lt;/div&gt; into this &lt;div class="code"&gt;http://www.mywebsite.com/tutorials/php/mod_rewrite-123&lt;/div&gt;&lt;div id="full-post"&gt;&lt;br /&gt;&lt;b&gt;Why to rewrite your URL`s ?&lt;/b&gt;&lt;br /&gt;The main reason is because static URL`s (the second URL is static) are indexed more faster than dynamic URL`s (like the first one), because from a static URL is easier to understand what the page is about both for search engines and your visitors. When using dynamic URL`s there is an another problem: search engines are reading only the beginning of the long URL`s, so if your addresses are different only at the end, than search engines will see the same URL for all of your pages and from this reason none will be indexed.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;How this works ?&lt;/b&gt;&lt;br /&gt;We will use Apache mod_rewrite. The mod_rewrite transforms back the second URL into the first URL, so the server will access the "ugly" address, but the visitors and the search engines will see the "clear" one. mod_rewrite simply rewrites the URL`s what meets specific conditions into addresses what are understood by the server.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Let`s rewrite it!&lt;/b&gt;&lt;br /&gt;The code what rewrites the website address needs to be placed in your &lt;b&gt;.htaccess&lt;/b&gt; file (if you don`t have it in your root folder, create it), the code is very short:&lt;div class="code"&gt;RewriteEngine on&lt;br /&gt;RewriteRule ^tutorials/(.*)/(.*)-([0-9]+)/?$ /tutorials.php?id=$3&amp;title=$2&amp;category=$1&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Take it apart!&lt;/b&gt;&lt;br /&gt;The first line: &lt;b&gt;RewriteEngine on&lt;/b&gt; simply does what it says, it starts the rewrite engine. &lt;br /&gt;Now let`s take apart the second line:&lt;br /&gt;&lt;div class="code"&gt;&lt;b&gt;RewriteRule&lt;/b&gt; - this tells the server about the rule to follow when rewriting the URL&lt;br /&gt;&lt;b&gt;^&lt;/b&gt; - this exponential sign means the start of the URL: http://www.mywebsite.com/&lt;br /&gt;&lt;b&gt;tutorials&lt;/b&gt; - this word is simply added to the website adress&lt;br /&gt;&lt;b&gt;/&lt;/b&gt; - this character separates the directories &lt;br /&gt;&lt;b&gt;(.*)&lt;/b&gt; - this tells the server that here will be placed some data (any kind of characters) (e.g.: php)&lt;br /&gt;&lt;b&gt;-&lt;/b&gt; - this character will be simply added to the website adress&lt;br /&gt;&lt;b&gt;([0-9])&lt;/b&gt; - this tells the server that here will be placed a digit (e.g: 1)&lt;br /&gt;&lt;b&gt;+&lt;/b&gt; - the plus sign tells the server that here can be more digits (e.g.: 123)&lt;br /&gt;&lt;b&gt;?&lt;/b&gt; - this sign tell the server that the character in it`s front it`s not required (so the URL will work with and without the last "/")&lt;br /&gt;&lt;b&gt;$&lt;/b&gt; - the dollar sign tells the server that here is the end of the rule&lt;/div&gt;The last part of the line is the old address, the value of each variable (id, title and category) are changed to $3, $2 and $1. mod_rewrite takes these variables and places them in their new position in the new URL. In the first place for data (the first (.*)) it places the $1`s value (the category value), in the second place the value of $2 and so on. If you want to change the order just change the $1, $2 and $3 order, but be careful to set the right data type in the new URL. &lt;br /&gt;&lt;br /&gt;I know that it`s not easy, if you have any question please don`t hesitate, ASK ME! And I will try to answer as fast as I can. You can for example write me in a comment your URL and how you want to transform it and I will try to make it ;)&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-4458784298246858128?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/iHK50-KamVOHISSgnia_feEnjYE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iHK50-KamVOHISSgnia_feEnjYE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/iHK50-KamVOHISSgnia_feEnjYE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iHK50-KamVOHISSgnia_feEnjYE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/THJxx8t1S9k" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">7</thr:total><feedburner:origLink>http://www.codingmix.com/2010/12/mod-rewrite-seo-url-php-htaccess.html</feedburner:origLink></item><item><title>Simple Chat script in PHP and jQuery</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/PNyWtrvhoiQ/chat-php-jquery.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Mon, 22 Nov 2010 05:48:54 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6993358900270163961</guid><description>This is a very basic Chat script written in PHP and jQuery for more browser compatibility. The script saves the messages in a MySQL table and automatically removes the old messages, so it needs minimum disk space. If you prefer Javascript instead, check out this version of the &lt;a href="http://www.codingmix.com/2010/11/cross-browser-chat-script-using-php.html" title="chat"&gt;chat script&lt;/a&gt;. Here is a live demo:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/jchat/chat.php" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;&lt;br /&gt;The script first needs a MySQL table:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;mysql_connect('host', 'database', 'password') &lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_query(&amp;quot;create table chat(&lt;br /&gt;   time int(11) NOT NULL, &lt;br /&gt;   name varchar(30) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   message varchar(255) NOT NULL, &lt;br /&gt;   PRIMARY KEY (time)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Than we need the main page of the script:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.message {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:498px;&lt;br /&gt;   margin-bottom:5px;&lt;br /&gt;   border:1px solid #999;&lt;br /&gt;}&lt;br /&gt;.messagehead {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#FFC;&lt;br /&gt;   width:500px;&lt;br /&gt;}&lt;br /&gt;.messagecontent {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:496px;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//Include jQuery&lt;/span&gt;&lt;br /&gt;&amp;lt;script src=&amp;quot;http://code.jquery.com/jquery-latest.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot; style=&amp;quot;width:500px;margin:0 auto;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;error&amp;quot; style=&amp;quot;width:500px;text-align:center;color:red;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;write&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&amp;gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;Name:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; id=&amp;quot;sendbutton&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function showmessages(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Change the content of the &lt;i&gt;messages&lt;/i&gt; div with the response from the &lt;i&gt;show-messages.php&lt;/i&gt; file.&lt;/span&gt;&lt;br /&gt;   $('#messages').html($.ajax({&lt;br /&gt;      url: 'show-messages.php?x=' + Math.random(), &lt;span style="color:green;"&gt;//The URL is always unique because of the random number&lt;/span&gt;&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText);&lt;br /&gt;   &lt;span style="color:green;"&gt;//Repeat the function each 30 seconds&lt;/span&gt;&lt;br /&gt;   setTimeout('showmessages()',30000); &lt;br /&gt;}&lt;br /&gt;showmessages();&lt;br /&gt;$('#sendbutton').click(function(){&lt;br /&gt;   var error = ''; &lt;br /&gt;   &lt;span style="color:green;"&gt;//Show an error message based on the response from &lt;i&gt;send.php&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;   switch(parseInt($.ajax({&lt;br /&gt;      url: 'send.php?message=' + $('#message').val() + '&amp;amp;name=' + $('#name').val(),&lt;br /&gt;      async:false&lt;br /&gt;   }).responseText)){&lt;br /&gt;   case 1:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 2:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 3:&lt;br /&gt;      error = 'Don`t forget the message!';&lt;br /&gt;      break;&lt;br /&gt;   case 4:&lt;br /&gt;      error = 'The message is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 5:&lt;br /&gt;      error = 'Don`t forget the name!';&lt;br /&gt;      break;&lt;br /&gt;   case 6:&lt;br /&gt;      error = 'The name is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 7:&lt;br /&gt;      error = 'This name is already used by somebody else!';&lt;br /&gt;      break;&lt;br /&gt;   case 8:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;   }&lt;br /&gt;   if(error == ''){&lt;br /&gt;      $('#error').html('');&lt;br /&gt;      showmessages();&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      $('#error').html(error);&lt;br /&gt;   }&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;Now we need to create the file that saves the message:&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (1);&lt;br /&gt;mysql_select_db('database') or die (2);&lt;br /&gt;if(strlen($message) &amp;lt; 1){&lt;br /&gt;   echo 3;&lt;br /&gt;}&lt;br /&gt;else if(strlen($message) &amp;gt; 255){&lt;br /&gt;   echo 4;&lt;br /&gt;}&lt;br /&gt;else if(strlen($name) &amp;lt; 1){&lt;br /&gt;   echo 5;&lt;br /&gt;}&lt;br /&gt;else if(strlen($name) &amp;gt; 29){&lt;br /&gt;   echo 6;&lt;br /&gt;}&lt;br /&gt;else if(mysql_num_rows(mysql_query(&amp;quot;select * from chat where name = '&amp;quot; . $name . &amp;quot;' and ip != '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 7;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//Insert the new message in the table and remove the unwanted characters&lt;/span&gt;&lt;br /&gt;   $search = array(&amp;quot;&amp;lt;&amp;quot;,&amp;quot;&amp;gt;&amp;quot;,&amp;quot;&amp;amp;gt;&amp;quot;,&amp;quot;&amp;amp;lt;&amp;quot;);&lt;br /&gt;mysql_query(&amp;quot;insert into chat values ('&amp;quot; . time() . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$name) . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$message) . &amp;quot;')&amp;quot;) or die(8);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;And the file that sends back the messages to us:&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;mysql_select_db('database') or die(2);&lt;br /&gt;$result = mysql_query(&amp;quot;select * from chat order by time desc limit 0,10&amp;quot;);&lt;br /&gt;$messages = array();&lt;br /&gt;$i = 0;&lt;br /&gt;while($row = mysql_fetch_array($result)){ &lt;br /&gt;   $messages[$i] = &amp;quot;&amp;lt;div class='message'&amp;gt;&amp;lt;div class='messagehead'&amp;gt;&amp;quot; . $row[name] . &amp;quot; - &amp;quot;;&lt;br /&gt;   $timeago = time() - $row['time'];&lt;br /&gt;   &lt;span style="color:green;"&gt;//Calculate the message date&lt;/span&gt;&lt;br /&gt;   if($timeago &amp;gt; 86400){&lt;br /&gt;      $messages[$i] .= date('g:i A M, d Y',$row[time]);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      $hours = floor($timeago / 3600); &lt;br /&gt;      $minutes = floor(($timeago - ($hours * 3600)) / 60);&lt;br /&gt;      $seconds = floor($timeago - ($hours * 3600) - ($minutes * 60));&lt;br /&gt;      if($hours &amp;gt; 0){&lt;br /&gt;         if($minutes &amp;gt; 9){&lt;br /&gt;            if($seconds &amp;gt; 9){&lt;br /&gt;               $messages[$i] .= $hours . ' h, ' . $minutes . ' min, ' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               $messages[$i] .= $hours . ' h, ' . $minutes . ' min, 0' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            if($seconds &amp;gt; 9){&lt;br /&gt;               $messages[$i] .= $hours . ' h, 0' . $minutes . ' min, ' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;            else{&lt;br /&gt;               $messages[$i] .= $hours . ' h, 0' . $minutes . ' min, 0' . $seconds . ' sec';&lt;br /&gt;            }&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      else if($minutes &amp;gt; 0){&lt;br /&gt;         if($seconds &amp;gt; 9){&lt;br /&gt;            $messages[$i] .= $minutes . ' min, ' . $seconds . ' sec';&lt;br /&gt;         }&lt;br /&gt;         else{&lt;br /&gt;            $messages[$i] .= $minutes . ' min, 0' . $seconds . ' sec';&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;      else{&lt;br /&gt;         $messages[$i] .= $seconds . ' sec';&lt;br /&gt;      }&lt;br /&gt;      $messages[$i] .= ' ago';&lt;br /&gt;   }&lt;br /&gt;   $messages[$i] .= &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='messagecontent'&amp;gt;&amp;quot; . $row[message] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;   $old = $row[time];&lt;br /&gt;   $i++;&lt;br /&gt;}&lt;br /&gt;for($i=9;$i&amp;gt;=0;$i--){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Output the messages from the oldest to the newest&lt;/span&gt;&lt;br /&gt;   echo $messages[$i];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Delete old messages&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;delete from chat where time &amp;lt; &amp;quot; . $old);&lt;br /&gt;?&amp;gt;&lt;/div&gt;If you have any related questions or problems please ask me!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6993358900270163961?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mpID26lbFVinybJr15R-KB58emc/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mpID26lbFVinybJr15R-KB58emc/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mpID26lbFVinybJr15R-KB58emc/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mpID26lbFVinybJr15R-KB58emc/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/PNyWtrvhoiQ" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">14</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/chat-php-jquery.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 4</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/freimmD6J-o/creating-full-php-login-system-very_21.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Mon, 22 Nov 2010 05:15:20 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6678078753780952414</guid><description>Before reading this tutorial please read the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html" title="login register"&gt;previous parts&lt;/a&gt;. In this part of the tutorial we will discuss about how the users will log in and log out. I will use the same database as in the &lt;a href="http://www.codingmix.com/2010/11/creating-full-php-login-system-very.html"  title="login register"&gt;third part&lt;/a&gt; of the tutorial, if you have registered there now you can log in:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/login/" style="width:350px;height:295px;overflow:hidden;margin-left:100px;"&gt;&lt;/iframe&gt;&lt;br /&gt;&lt;br /&gt;To log in we will use sessions (here you can read more about &lt;a href="http://www.codingmix.com/2010/11/php-sessions.html" title="php sessions"&gt;sessions&lt;/a&gt;). As you already know, a session can transfer data from a page to another pages. When the user logs in we will create a session with the username and later we will check this session: while the session exists the user is logged in.&lt;br /&gt;&lt;br /&gt;But first we need the log in form:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;span style="color:red;"&gt;&amp;lt;form action=&amp;quot;login.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Log in&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Log in&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;Don`t have an account?&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;And now we need to create the &lt;i&gt;login.php&lt;/i&gt; file. This file will create the session if the given username and password are matching. It will check the username and password by searching in the MySQL table for a row where the username field matches the given username and password field with the given password.&lt;br /&gt;&lt;i&gt;login.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start(); &lt;span style="color:green;"&gt;//Start sessions&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (&amp;quot;Could not connect to mysql because &amp;quot;.mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (&amp;quot;Could not select database because &amp;quot;.mysql_error());&lt;br /&gt;if(&lt;span style="color:red;"&gt;mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM users WHERE username='&amp;quot;.$_POST[&amp;quot;username&amp;quot;].&amp;quot;' and password='&amp;quot;.$_POST[&amp;quot;password&amp;quot;].&amp;quot;'&amp;quot;))==1&lt;/span&gt;){&lt;br /&gt;   session_register(&amp;quot;username&amp;quot;); &lt;span style="color:green;"&gt;//Create the session&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'Wrong username or password!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Now the session is created but we are not seeing the results. To see some results we will need to modify the &lt;i&gt;index.php&lt;/i&gt; to show a welcome message if the user is logged in, else to show the login and registration forms:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;:&lt;div class="code"&gt;&lt;span style="color:red;"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if(!session_is_registered(&amp;quot;username&amp;quot;)){?&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;login.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Log in&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Log in&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;Don`t have an account?&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;?php }&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:red;"&gt;echo 'Welcome ' . $_SESSION[&amp;quot;username&amp;quot;];&lt;/span&gt;&lt;br /&gt;}?&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;In this moment if you log in ,you need to go back to the &lt;i&gt;index.php&lt;/i&gt; file to see the welcome message. To solve this problem we will need to edit the &lt;i&gt;login.php&lt;/i&gt; file in a way to redirect the user back to &lt;i&gt;index.php&lt;/i&gt;. We will make this by using the &lt;i&gt;header("location:index.php")&lt;/i&gt; function:&lt;br /&gt;&lt;i&gt;login.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start(); &lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (&amp;quot;Could not connect to mysql because &amp;quot;.mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (&amp;quot;Could not select database because &amp;quot;.mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * FROM users WHERE username='&amp;quot;.$_POST[&amp;quot;username&amp;quot;].&amp;quot;' and password='&amp;quot;.$_POST[&amp;quot;password&amp;quot;].&amp;quot;'&amp;quot;))==1){&lt;br /&gt;   session_register(&amp;quot;username&amp;quot;);&lt;br /&gt;   &lt;span style="color:red;"&gt;header(&amp;quot;location:index.php&amp;quot;);&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;else {&lt;br /&gt;   echo 'Wrong username or password!';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Now there is only one thing that needs to be done: the log out option. We will make logging out possible by creating a file: &lt;i&gt;logout.php&lt;/i&gt;. This file will simply delete the &lt;i&gt;username&lt;/i&gt; session and redirect the users back to &lt;i&gt;index.php&lt;/i&gt;, but first we need to include the log out button in the &lt;i&gt;index.php&lt;/i&gt; file:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;if(!session_is_registered(&amp;quot;username&amp;quot;)){?&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;login.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Log in&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Log in&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;Don`t have an account?&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;?php }&lt;br /&gt;else{&lt;br /&gt;   echo 'Welcome ' . $_SESSION[&amp;quot;username&amp;quot;] . &lt;span style="color:red;"&gt;'&amp;lt;br/&amp;gt;&amp;lt;a href=&amp;quot;logout.php&amp;quot;&amp;gt;Log out&amp;lt;/a&amp;gt;'&lt;/span&gt;;&lt;br /&gt;}?&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;And here is the log out part:&lt;br /&gt;&lt;i&gt;logout.php&lt;/i&gt;:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;session_start();&lt;br /&gt;session_destroy(); &lt;span style="color:green;"&gt;//Delete session&lt;/span&gt;&lt;br /&gt;header(&amp;quot;location:index.php&amp;quot;);&lt;br /&gt;?&amp;gt;&lt;/div&gt;And now the script should work fine, if it doesn`t or you have a question please comment. This script can be easily adapted to any website, by checking the existence of the session on each page.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6678078753780952414?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/MIwfSMdcJUnYwpChYEXFTUFLrbs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MIwfSMdcJUnYwpChYEXFTUFLrbs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/MIwfSMdcJUnYwpChYEXFTUFLrbs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/MIwfSMdcJUnYwpChYEXFTUFLrbs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/freimmD6J-o" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">36</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/creating-full-php-login-system-very_21.html</feedburner:origLink></item><item><title>Cross-browser Chat script using PHP, MySQL and Javascript</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/CRUsjt1ild0/cross-browser-chat-script-using-php.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Mon, 31 Jan 2011 23:41:49 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-7073350657830778254</guid><description>I write this tutorial because the &lt;a href="http://www.codingmix.com/2010/09/simple-chat-script-in-php-mysql-and.html" title="chat script"&gt;first version&lt;/a&gt; of my Chat script had some problems in IE (Internet Explorer): After the message was submitted the page was not refreshed. Now I`we found the problem and a solution and here is the new, cross-browser chat script:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/chat3/chat.php" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;&lt;br /&gt;The chat is refreshed automatically each 30 seconds.&lt;br /&gt;&lt;br /&gt;This script works the same way as the &lt;a href="http://www.codingmix.com/2010/09/simple-chat-script-in-php-mysql-and.html" title="chat"&gt;old one&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Let`s start: First we need to create a MySQL table with 4 fields: &lt;div class="code"&gt;time - the time when the message was posted (UNIX)&lt;br /&gt;name - the name of the author of the message&lt;br /&gt;ip - the ip of the author of the message&lt;br /&gt;message - the message text&lt;/div&gt;To create the table (I will call it &lt;i&gt;chat&lt;/i&gt;) I`we used the following file:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Create the table&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;create table chat(&lt;br /&gt;   time int(11) NOT NULL, &lt;br /&gt;   name varchar(30) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   message varchar(255) NOT NULL, &lt;br /&gt;   PRIMARY KEY (time)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;For the rest of the Chat script we will need 3 more files:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Let`s start with the chat.php what will contain the forms and all the Ajax scripts what will trigger the other 2 files: &lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.message {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:498px;&lt;br /&gt;   margin-bottom:5px;&lt;br /&gt;   border:1px solid #999;&lt;br /&gt;}&lt;br /&gt;.messagehead {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#FFC;&lt;br /&gt;   width:500px;&lt;br /&gt;}&lt;br /&gt;.messagecontent {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:496px;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot; style=&amp;quot;width:500px;margin:0 auto;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain the messages&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain an eventual error message&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;error&amp;quot; style=&amp;quot;width:500px;text-align:center;color:red;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div contains the forms and the send button&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;write&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&amp;gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;Name:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; onClick=&amp;quot;send();&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will display the messages&lt;/span&gt;&lt;br /&gt;function showmessages(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'show-message.php' file&lt;/span&gt;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      &lt;span style="color:red;"&gt;//And here is the line what makes it cross-browser:&lt;/span&gt;&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;show-messages.php&lt;span style="color:red;"&gt;?&amp;quot; + Math.random()&lt;/span&gt;,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;showmessages.php&lt;span style="color:red;"&gt;?&amp;quot; + Math.random()&lt;/span&gt;,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Replace the content of the &lt;i&gt;messages&lt;/i&gt; with the response from the 'show-messages.php' file&lt;/span&gt;&lt;br /&gt;   document.getElementById('messages').innerHTML = xmlhttp.responseText;&lt;br /&gt;   &lt;span style="color:green;"&gt;//Repeat the function each 30 seconds&lt;/span&gt;&lt;br /&gt;   setTimeout('showmessages()',30000);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Start the &lt;i&gt;showmessages()&lt;/i&gt; function&lt;/span&gt;&lt;br /&gt;showmessages();&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will submit the message&lt;/span&gt;&lt;br /&gt;function send(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'send.php' file with all the required informations&lt;/span&gt;&lt;br /&gt;   var sendto = 'send.php?message=' + document.getElementById('message').value + '&amp;amp;name=' + document.getElementById('name').value;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   var error = '';&lt;br /&gt;   &lt;span style="color:green;"&gt;//If an error occurs the 'send.php' file send`s the number of the error and based on that number a message is displayed&lt;/span&gt;&lt;br /&gt;   switch(parseInt(xmlhttp.responseText)){&lt;br /&gt;   case 1:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 2:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 3:&lt;br /&gt;      error = 'Don`t forget the message!';&lt;br /&gt;      break;&lt;br /&gt;   case 4:&lt;br /&gt;      error = 'The message is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 5:&lt;br /&gt;      error = 'Don`t forget the name!';&lt;br /&gt;      break;&lt;br /&gt;   case 6:&lt;br /&gt;      error = 'The name is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 7:&lt;br /&gt;      error = 'This name is already used by somebody else!';&lt;br /&gt;      break;&lt;br /&gt;   case 8:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;   }&lt;br /&gt;   if(error == ''){&lt;br /&gt;      document.getElementById('error').innerHTML = '';&lt;br /&gt;      showmessages();&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      document.getElementById('error').innerHTML = error;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (1);&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die (2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is empty and send the error code&lt;/span&gt;&lt;br /&gt;if(strlen($message) &amp;lt; 1){&lt;br /&gt;   echo 3;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($message) &amp;gt; 255){&lt;br /&gt;   echo 4;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is empty&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;lt; 1){&lt;br /&gt;   echo 5;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;gt; 29){&lt;br /&gt;   echo 6;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if the name is used by somebody else&lt;/span&gt;&lt;br /&gt;else if(mysql_num_rows(mysql_query(&amp;quot;select * from chat where name = '&amp;quot; . $name . &amp;quot;' and ip != '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 7;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//If everything is fine&lt;/span&gt;&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//This array contains the characters what will be removed from the message and name, because else somebody could send redirection script or links&lt;/span&gt;&lt;br /&gt;   $search = array(&amp;quot;&amp;lt;&amp;quot;,&amp;quot;&amp;gt;&amp;quot;,&amp;quot;&amp;amp;gt;&amp;quot;,&amp;quot;&amp;amp;lt;&amp;quot;);&lt;br /&gt;   &lt;span style="color:green;"&gt;//Insert a new row in the chat table&lt;/span&gt;&lt;br /&gt;   mysql_query(&amp;quot;insert into chat values ('&amp;quot; . time() . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$name) . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$message) . &amp;quot;')&amp;quot;) or die(8);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die(2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Get the first 10 messages ordered by time&lt;/span&gt;&lt;br /&gt;$result = mysql_query(&amp;quot;select * from chat order by time desc limit 0,10&amp;quot;);&lt;br /&gt;$messages = array();&lt;br /&gt;&lt;span style="color:green;"&gt;//Loop and get in an array all the rows until there are not more to get&lt;/span&gt;&lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Put the messages in divs and then in an array&lt;/span&gt;&lt;br /&gt;   $messages[] = &amp;quot;&amp;lt;div class='message'&amp;gt;&amp;lt;div class='messagehead'&amp;gt;&amp;quot; . $row[name] . &amp;quot; - &amp;quot; . date('g:i A M, d Y',$row[time]) . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='messagecontent'&amp;gt;&amp;quot; . $row[message] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;   &lt;span style="color:green;"&gt;//The last posts date&lt;/span&gt;&lt;br /&gt;   $old = $row[time];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Display the messages in an ascending order, so the newest message will be at the bottom&lt;/span&gt;&lt;br /&gt;for($i=9;$i&amp;gt;=0;$i--){&lt;br /&gt;   echo $messages[$i];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//This is the more important line, this deletes each message older then the 10th message ordered by time is deleted, so the table will never have to store more than 10 messages.&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;delete from chat where time &amp;lt; &amp;quot; . $old);&lt;br /&gt;?&amp;gt;&lt;/div&gt;If we try to send multiple times the httpRequest to the same file IE will cache the first response and it will return the first result each time. To make IE to believe that we are sending the request to an another file we will use the url in the following way: &lt;div class="code"&gt;'file.php?' + Math.random&lt;br /&gt;this will result something like this: &lt;i&gt;file.php?0.12321321&lt;/i&gt; - this is a new file for IE&lt;/div&gt;Try it out and don`t hesitate to ask if something is not clear or if you find an error!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-7073350657830778254?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/pCHO1BZGDQZ6MFjeeHM-5i_xVQM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pCHO1BZGDQZ6MFjeeHM-5i_xVQM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/pCHO1BZGDQZ6MFjeeHM-5i_xVQM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/pCHO1BZGDQZ6MFjeeHM-5i_xVQM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/CRUsjt1ild0" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">107</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/cross-browser-chat-script-using-php.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 3</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/Yaz29NCvDOg/creating-full-php-login-system-very.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Sun, 21 Nov 2010 10:50:25 PST</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-3093255739594364336</guid><description>This is the third part of this tutorial (here is the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html" title="PHP Login system"&gt;first&lt;/a&gt;). In this part we will complete the registration process by recording the registration details in our MySQL table: &lt;i&gt;users&lt;/i&gt; and by outputting different error messages for different errors that may occur (e.g.: username already exist, password too short... ). &lt;div id="full-post"&gt;&lt;br /&gt;In the previous part of this tutorial we have discussed about how we can get the value of a text input. Now we will need to store these values in our MySQL table. To insert the data into the table we will use the &lt;i&gt;insert&lt;/i&gt; query: &lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;?&amp;gt;&lt;/div&gt;When using this query make sure you put the data in the right order (name,password)!&lt;br /&gt;&lt;br /&gt;The above code will not write out any success message, it will just simply insert the data into the &lt;i&gt;users&lt;/i&gt; table. To see the result you should &lt;a href="http://www.codingmix.com/2010/10/display-data-from-mysql-table-using-php.html" target="_blank"&gt;display the data from the mysql table&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now try to register twice with the same username. Because the username need`s to be unique you will get an error like this: &lt;div class="code"&gt;Duplicate entry 'username' for key 'PRIMARY'&lt;/div&gt;To avoid such errors we should begin with checking the username. We will check it using the &lt;i&gt;select&lt;/i&gt; query and the &lt;i&gt;mysql_num_rows&lt;/i&gt; function. &lt;br /&gt;&lt;br /&gt;This is very simple. We will count the rows where the username is the one what we are searching for. If this number is 0 means that the username is not in the table so we can register it, if it`s 1 than there is already somebody with this username in our table. &lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * from users WHERE username='&amp;quot; . $_POST['username'] . &amp;quot;'&amp;quot;)) == 1){&lt;br /&gt;   echo &amp;quot;Sorry, this username is already taken!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;In the same way (using if/else and else if statements) we will need to check for a list of possible errors: &lt;div class="code"&gt;Username too long&lt;br /&gt;Username too short&lt;br /&gt;Password too long&lt;br /&gt;Password too short&lt;br /&gt;Invalid characters in password&lt;br /&gt;Invalid characters in username&lt;br /&gt;&lt;/div&gt;This is a very simple, here is my code:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * from users WHERE username='&amp;quot; . $_POST['username'] . &amp;quot;'&amp;quot;)) == 1){&lt;br /&gt;   echo &amp;quot;Sorry, this username is already taken!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['username']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Username is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['username']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Username is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Password is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Password is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['username'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in username!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['password'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in password!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;These days most of the registration forms have a &lt;i&gt;retype password&lt;/i&gt; field, to avoid mistyped passwords. To add this feature to our registration form we will need to edit both the &lt;i&gt;index.php&lt;/i&gt; and the &lt;i&gt;register.php&lt;/i&gt; files. First we need to include the retype password text input and secondly to compare the two passwords.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;Retype password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;retype-password&amp;quot;/&amp;gt;&amp;lt;br /&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;i&gt;register.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;SELECT * from users WHERE username='&amp;quot; . $_POST['username'] . &amp;quot;'&amp;quot;)) == 1){&lt;br /&gt;   echo &amp;quot;Sorry, this username is already taken!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;else if($_POST['password'] != $_POST['retype-password']){&lt;br /&gt;   echo &amp;quot;The two passwords don`t match!&amp;quot;;&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;else if(strlen($_POST['username']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Username is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['username']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Username is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;gt; 15){&lt;br /&gt;   echo &amp;quot;Password is too long!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(strlen($_POST['password']) &amp;lt; 6){&lt;br /&gt;   echo &amp;quot;Password is too short!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['username'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in username!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else if(preg_match('/[^0-9A-Za-z]/',$_POST['password'])){&lt;br /&gt;   echo &amp;quot;Invalid characters in password!&amp;quot;;&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   mysql_query(&amp;quot;INSERT into users VALUES ('&amp;quot;.$_POST['username'].&amp;quot;', '&amp;quot;.$_POST['password'].&amp;quot;')&amp;quot;) or die(mysql_error());&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;Here is a live demo of what we have until now:&lt;iframe src="http://coolboycsaba.freehostia.com/login-example2/" style="width:350px;height:180px;overflow:hidden;margin-left:100px;"&gt;&lt;/iframe&gt;&lt;br /&gt;And here is a list with the registered users (it`s &lt;b&gt;not&lt;/b&gt; refreshing when you register!)&lt;iframe src="http://coolboycsaba.freehostia.com/login/registered-users.php" style="border:1px solid #999;width:520px;height:100px;margin-left:5px;float:left;"&gt;&lt;/iframe&gt;&lt;br /&gt;And this is enough for now. If something doesn`t work or you have a question just ask in a comment and I will try to answer to each comment.&lt;br /&gt;&lt;br /&gt;Here you can find the &lt;a href="http://www.codingmix.com/2010/11/creating-full-php-login-system-very_21.html" title="login register"&gt;4th part of the tutorial&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-3093255739594364336?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/iWypkkxtKoyQP5tYXb2lGFt4L_s/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iWypkkxtKoyQP5tYXb2lGFt4L_s/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/iWypkkxtKoyQP5tYXb2lGFt4L_s/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/iWypkkxtKoyQP5tYXb2lGFt4L_s/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/Yaz29NCvDOg" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://www.codingmix.com/2010/11/creating-full-php-login-system-very.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 2</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/V39BVgrx0ss/creating-full-php-login-system-very_29.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Wed, 03 Nov 2010 07:27:29 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5168213691621313436</guid><description>This is the second part of this tutorial. In the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html"&gt;first part&lt;/a&gt; we created a MySQL table to store the required user informations. In this part we will continue our Login/Register system by making registration possible.&lt;div id="full-post"&gt;&lt;br /&gt;First we will need to create an empty &lt;i&gt;.php&lt;/i&gt; page, later this page will contain the log in and the register form. I will name it &lt;i&gt;index.php&lt;/i&gt; because when you enter the URL of a website or a folder in the address bar the browser will open the first file with the name &lt;i&gt;index&lt;/i&gt;. For sure you can name it anyway you want if you want to make registration and logging in possible only from a secondary page.&lt;br /&gt;Here is my &lt;i&gt;index.php&lt;/i&gt; file:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;Now we need to create the registration form, this will contain a text inputs for the username, a password input for the password and a submit button. This form will be placed in the &lt;i&gt;index.php&lt;/i&gt; page.&lt;br /&gt;Here is an example of how it should look: &lt;div class="code"&gt;&lt;form&gt;&lt;br /&gt;&lt;b style="font-size:150%;"&gt;Register&lt;/b&gt;&lt;br /&gt;Username: &lt;input type="text" name="username"/&gt;&lt;br /&gt;Password: &lt;input type="password" name="password"/&gt;&lt;br /&gt;&lt;input type="button" value="Register" /&gt;&lt;br /&gt;&lt;/form&gt; &lt;/div&gt;&lt;small&gt;(The form is just an example, it will do nothing if you press the Register button.)&lt;/small&gt; &lt;br /&gt;&lt;br /&gt;Later we will create a file called &lt;i&gt;register.php&lt;/i&gt;. The above form will be submitted to this new file and this file (&lt;i&gt;register.php&lt;/i&gt;) will read the value of the username and the password input, but to make reading it possible we will need to set the name attribute of the two field: the username input will be called &lt;i&gt;username&lt;/i&gt; and the password input &lt;i&gt;password&lt;/i&gt;. After this we just need to specify the page to submit the form to and the submission method. As I said before the form will be submitted to &lt;i&gt;register.php&lt;/i&gt; using &lt;i&gt;post&lt;/i&gt; as method.&lt;br /&gt;After making the above modifications my &lt;i&gt;index.php&lt;/i&gt; file look`s in the following way:&lt;br /&gt;&lt;i&gt;index.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;form action=&amp;quot;register.php&amp;quot; method=&amp;quot;post&amp;quot;&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;b style=&amp;quot;font-size:150%;&amp;quot;&amp;gt;Register&amp;lt;/b&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Username: &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;username&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;Password: &amp;lt;input type=&amp;quot;password&amp;quot; name=&amp;quot;password&amp;quot;/&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Register&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;Now let`s start to write the &lt;i&gt;register.php&lt;/i&gt; file. First we will make it to write out the username and the password to familiarize with PHP and how to read from a form. At this step my &lt;i&gt;register.php&lt;/i&gt; look`s in the following way:&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;echo $_POST[&amp;quot;username&amp;quot;] . &amp;quot;&amp;lt;br /&amp;gt;&amp;quot; . $_POST[&amp;quot;password&amp;quot;];&lt;br /&gt;?&amp;gt;&lt;/div&gt;The &lt;b&gt;$_POST[&lt;span style="color:red;"&gt;"username"&lt;/span&gt;]&lt;/b&gt; function reads the value of the input with the name specified in the parameter (in red), in our case &lt;i&gt;"username"&lt;/i&gt;. (This function works only with method="post" forms.) &lt;br /&gt;&lt;br /&gt;Here is a live demo of what we have until now: &lt;iframe src="http://coolboycsaba.freehostia.com/login-example1/" style="width:300px;height:150px;overflow:hidden;margin-left:125px;"&gt;&lt;/iframe&gt;&lt;br /&gt;This is enough for now. If you have a question or something it`s not working just ASK ME!&lt;br /&gt;&lt;br /&gt;Here is the &lt;a href="http://www.codingmix.com/2010/11/creating-full-php-login-system-very.html"&gt;third part&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5168213691621313436?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Ffq5y5rrh5d7QDEmuxs-AhXRvRs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ffq5y5rrh5d7QDEmuxs-AhXRvRs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Ffq5y5rrh5d7QDEmuxs-AhXRvRs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Ffq5y5rrh5d7QDEmuxs-AhXRvRs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/V39BVgrx0ss" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/creating-full-php-login-system-very_29.html</feedburner:origLink></item><item><title>Creating a full PHP Login system (Very Detailed) part 1</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/AhUb_sH-2og/creating-full-php-login-system-very.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 29 Oct 2010 05:45:15 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-5112372583892540438</guid><description>In this tutorial we will make a full PHP Login script, what will allow users to register, login and to log out. This system can be easily used on any PHP website. In this tutorial we will deal more with the technical (PHP) part and less with styling it, as you can see it in the bellow example of how the login system will look and work:&lt;div id="full-post"&gt;&lt;iframe src='http://coolboycsaba.freehostia.com/login/' style="width:530px;height:300px;"&gt;&lt;/iframe&gt;&lt;br /&gt;When somebody registers the username and the password is stored in a MySQL table. When somebody tries to log in the script will verify if exists an user with the given username and password in the MySQL table. If the login was successful a session is created and a welcome message is displayed. From here the user can log out by destroying the session.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Creating the &lt;i&gt;users&lt;/i&gt; MySQL table&lt;/b&gt;&lt;br /&gt;As I said, the username and the password of each user will be stored in a MySQL table. I will call this table &lt;i&gt;users&lt;/i&gt;. We need two columns: &lt;i&gt;username&lt;/i&gt; and &lt;i&gt;password&lt;/i&gt;. &lt;br /&gt;I`we used the following file to create the table:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style='color:green;'&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (mysql_error());&lt;br /&gt;&lt;span style='color:green;'&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die (mysql_error());&lt;br /&gt;&lt;span style='color:green;'&gt;//Create the table&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;create table users(&lt;br /&gt;   username varchar(30) NOT NULL, &lt;br /&gt;   password varchar(30) NOT NULL, &lt;br /&gt;   PRIMARY KEY (username)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;&lt;span style='color:green;'&gt;//Show "Complete" if everything works&lt;/span&gt;&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;Now let`s take apart this code and talk about the following code:&lt;div class="code"&gt;mysql_query(&amp;quot;create table users(&lt;br /&gt;   username varchar(30) NOT NULL, &lt;br /&gt;   password varchar(30) NOT NULL, &lt;br /&gt;   PRIMARY KEY (username)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;/div&gt;By using &lt;i&gt;mysql_query&lt;/i&gt; we "ask" the MySQL database to do something. In this case we ask it to create a table with the name &lt;i&gt;users&lt;/i&gt;: &lt;b&gt;create table users&lt;/b&gt;.&lt;br /&gt;After this we need to specify some details about the table. These details needs to be placed between brackets ("()"). &lt;br /&gt;First we will specify the two fields (columns): &lt;div class="code"&gt;username varchar(30) NOT NULL,&lt;br /&gt;password varchar(30) NOT NULL&lt;/div&gt;"username" and "password" is the name of the field.&lt;br /&gt;"varchar" is the data type of the field - it will contain characters&lt;br /&gt;"(30)" is the maximum length of the field&lt;br /&gt;"NOT NULL" means the field can`t be leaved blank&lt;br /&gt;And we specify the PRIMARY KEY:&lt;br /&gt;&lt;div class="code"&gt;PRIMARY KEY (username)&lt;/div&gt;The primary key is an unique identifier, this means that there can`t be two users with the same username.&lt;br /&gt;&lt;br /&gt;Now just run your &lt;i&gt;create-table.php&lt;/i&gt; but don`t forget to change the host, database and the password to yours. If everything works you will see the message: "Complete.", otherwise an error message. In this case double check your code or ASK ME!&lt;br /&gt;&lt;br /&gt;Here is the &lt;a href="http://www.codingmix.com/2010/10/creating-full-php-login-system-very_29.html" title="php login system"&gt;second part!&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-5112372583892540438?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DXPxIindOkSSO9oadWKVKXcof0g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DXPxIindOkSSO9oadWKVKXcof0g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DXPxIindOkSSO9oadWKVKXcof0g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DXPxIindOkSSO9oadWKVKXcof0g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/AhUb_sH-2og" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">6</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/creating-full-php-login-system-very.html</feedburner:origLink></item><item><title>How to create a POLL system using PHP, MySQL and Ajax</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/HFCXpo3ocOA/how-to-create-poll-system-using-php.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Thu, 07 Oct 2010 06:19:34 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6019809021433487074</guid><description>In this tutorial I will show you how to create a basic POLL system using PHP, MySQL and Ajax. This poll will have some great features like: nobody can vote multiple times and the result of the poll is shown automatically after voting without refreshing the page.&lt;div id="full-post"&gt; Here is a live demo:&lt;div class="code"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/poll/poll.php" style="width:330px;height:150px;border:none;margin:0 0 0 150px;"&gt;&lt;/iframe&gt;&lt;/div&gt;The poll system uses a MySQL table to store the votes. This table requires only two columns: &lt;div class="code"&gt;vote - the number of the selected option (the "Yes..." option has the number 2)&lt;br /&gt;ip - the ip is used to prevent multiple votes&lt;/div&gt;To create the table you can use the following file:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&lt;?php &lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;mysql_query("create table poll(&lt;br /&gt;   vote tinyint(2) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   PRIMARY KEY (ip)&lt;br /&gt;)") or die (mysql_error());&lt;br /&gt;echo "Complete.";&lt;br /&gt;?&gt;&lt;/div&gt;The poll itself is made from two files. One contains the forms and the javascript and ajax parts, and an another file what`s called by the first one. &lt;br /&gt;The first file (poll.php) just sends the selected option number to the second file (vote.php) and displays the response. Here is my poll.php:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;poll.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.votes {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#CCC;&lt;br /&gt;   height:20px;&lt;br /&gt;   width:100px;&lt;br /&gt;   margin:5px 0 0 23px;&lt;br /&gt;   float:left;&lt;br /&gt;}&lt;br /&gt;.percentage {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#F00;&lt;br /&gt;   height:20px;&lt;br /&gt;}&lt;br /&gt;.option {&lt;br /&gt;   position:absolute;&lt;br /&gt;   width:100px;&lt;br /&gt;   height:20px;&lt;br /&gt;}&lt;br /&gt;.percentagetext {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:75px;&lt;br /&gt;   height:20px;&lt;br /&gt;   margin:5px 0 0 0;&lt;br /&gt;   float:left;&lt;br /&gt;   text-align:left;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;poll&amp;quot; style=&amp;quot;width:200px;overflow:hidden;text-align:center;&amp;quot;&amp;gt;&lt;br /&gt;Do you like this poll?&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;div style=&amp;quot;text-align:left;width:180px;margin:0 auto;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll1&amp;quot; checked&amp;gt;Yes, it`s great&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll2&amp;quot;&amp;gt;Yes...&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll3&amp;quot;&amp;gt;Not bad...&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;radio&amp;quot; name=&amp;quot;poll&amp;quot; id=&amp;quot;poll4&amp;quot;&amp;gt;No!&amp;lt;br/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Vote!&amp;quot; onClick=&amp;quot;vote();&amp;quot;/&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;function vote(){&lt;br /&gt;   for(var i=1;i&amp;lt;=4;i++){&lt;br /&gt;      if(document.getElementById('poll' + i).checked){&lt;br /&gt;         &lt;span style="color:green;"&gt;//Check which one has been checked&lt;/span&gt;&lt;br /&gt;         var sendto = 'vote.php?vote=' + i;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;// Call the vote.php file&lt;/span&gt;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest;&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Output the response&lt;/span&gt;&lt;br /&gt;   document.getElementById('poll').innerHTML = xmlhttp.responseText;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;The CSS code is used to bring style to the response.&lt;br /&gt;&lt;br /&gt;Now let`s create the &lt;i&gt;vote.php&lt;/i&gt; file. This file will need to check if the user has already voted or not (by checking the ip) and it will need to calculate the percentage of votes and output the result in HTML format:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;vote.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('borcsa9_database');&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if the current user has already voted or not&lt;/span&gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//&lt;i&gt;@$REMOTE_ADDR&lt;/i&gt; is used to get the ip of the user&lt;/span&gt;&lt;br /&gt;if(mysql_num_rows(mysql_query(&amp;quot;select * from poll where ip = '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 'You can vote only once!';&lt;br /&gt;}&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//If the user had not voted then insert the new vote in the &lt;i&gt;poll&lt;/i&gt; table&lt;/span&gt;&lt;br /&gt;   mysql_query(&amp;quot;insert into poll values ('&amp;quot; . $vote . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;')&amp;quot;) or die (mysql_error());&lt;br /&gt;}&lt;br /&gt;$mostvotes = 0;&lt;br /&gt;for($i=1;$i&amp;lt;=4;$i++){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Create an array of votes for each option&lt;/span&gt;&lt;br /&gt;   $votes[$i] = mysql_num_rows(mysql_query(&amp;quot;select * from poll where vote = &amp;quot; . $i));&lt;br /&gt;   if($votes[$i] &amp;gt; $mostvotes){&lt;br /&gt;      &lt;span style="color:green;"&gt;//Select the option with the higher number of votes&lt;/span&gt;&lt;br /&gt;      $mostvotes = $votes[$i];&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Each vote&lt;/span&gt;&lt;br /&gt;   $allvotes += $votes[$i];&lt;br /&gt;}&lt;br /&gt;$option[1] = 'Yes, it`s great';&lt;br /&gt;$option[2] = 'Yes...';&lt;br /&gt;$option[3] = 'Not bad...';&lt;br /&gt;$option[4] = 'No!';&lt;br /&gt;&lt;span style="color:green;"&gt;//Generate the result in a HTML form by calculating the percentage of each option and showing the number of votes&lt;/span&gt;&lt;br /&gt;for($i=1;$i&amp;lt;=4;$i++){&lt;br /&gt;   echo &amp;quot;&amp;lt;div class='votes'&amp;gt;&amp;lt;div class='option'&amp;gt;&amp;quot; . $option[$i] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='percentage' style='width:&amp;quot; . floor($votes[$i] / $allvotes * 100) . &amp;quot;px'&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class='percentagetext'&amp;gt; - &amp;quot; . floor($votes[$i] / $allvotes * 100) . &amp;quot;% (&amp;quot; . $votes[$i] . &amp;quot;)&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;And the our poll system is ready to use. This is a very basic poll system, but this can be easily modified by adding more style or more functions to it.&lt;br /&gt;If you have any question, don`t hesitate, ask!&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6019809021433487074?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/wh8LGiuSrkW1meqcf11qYN9r-Uo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wh8LGiuSrkW1meqcf11qYN9r-Uo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/wh8LGiuSrkW1meqcf11qYN9r-Uo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/wh8LGiuSrkW1meqcf11qYN9r-Uo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/HFCXpo3ocOA" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">17</thr:total><feedburner:origLink>http://www.codingmix.com/2010/10/how-to-create-poll-system-using-php.html</feedburner:origLink></item><item><title>Simple Chat script in PHP, MySQL and Ajax</title><link>http://feedproxy.google.com/~r/codingmix/PHP/tutorials/~3/BTBGl786ams/simple-chat-script-in-php-mysql-and.html</link><category>PHP</category><category>PHP tutorials</category><author>noreply@blogger.com (Csabi)</author><pubDate>Fri, 05 Nov 2010 04:58:55 PDT</pubDate><guid isPermaLink="false">tag:blogger.com,1999:blog-5682776130825686229.post-6620182635715936266</guid><description>In this tutorial I will show you how to create a simple but &lt;b&gt;very&lt;/b&gt; effective Chat script, and I said effective because unlike the most of the chat scripts this one deletes automatically the old messages from the database. Here is a live demo:&lt;div id="full-post"&gt;&lt;iframe src="http://coolboycsaba.freehostia.com/chat/chat.php" style="width:530px;height:650px;"&gt;&lt;/iframe&gt;&lt;br /&gt;The chat is refreshed automatically each 30 seconds.&lt;br /&gt;&lt;br /&gt;Let`s start: First we need to create a MySQL table with 4 fields: &lt;div class="code"&gt;time - the time when the message was posted (UNIX)&lt;br /&gt;name - the name of the author of the message&lt;br /&gt;ip - the ip of the author of the message&lt;br /&gt;message - the message text&lt;/div&gt;To create the table (I will call it &lt;i&gt;chat&lt;/i&gt;) I`we used the following file:&lt;br /&gt;&lt;i&gt;create-table.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php &lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database')&lt;br /&gt;or die (mysql_error());&lt;br /&gt;&lt;span style="color:green;"&gt;//Create the table&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;create table chat(&lt;br /&gt;   time int(11) NOT NULL, &lt;br /&gt;   name varchar(30) NOT NULL, &lt;br /&gt;   ip varchar(15) NOT NULL, &lt;br /&gt;   message varchar(255) NOT NULL, &lt;br /&gt;   PRIMARY KEY (time)&lt;br /&gt;)&amp;quot;) or die (mysql_error());&lt;br /&gt;echo &amp;quot;Complete.&amp;quot;;&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;For the rest of the Chat script we will need 3 more files:&lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Let`s start with the chat.php what will contain the forms and all the Ajax scripts what will trigger the other 2 files: &lt;br /&gt;&lt;i&gt;chat.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;style&amp;gt;&lt;br /&gt;.message {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:498px;&lt;br /&gt;   margin-bottom:5px;&lt;br /&gt;   border:1px solid #999;&lt;br /&gt;}&lt;br /&gt;.messagehead {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   background:#FFC;&lt;br /&gt;   width:500px;&lt;br /&gt;}&lt;br /&gt;.messagecontent {&lt;br /&gt;   overflow:hidden;&lt;br /&gt;   width:496px;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;chat&amp;quot; style=&amp;quot;width:500px;margin:0 auto;overflow:hidden;&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain the messages&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;messages&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div will contain an eventual error message&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;error&amp;quot; style=&amp;quot;width:500px;text-align:center;color:red;&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This div contains the forms and the send button&lt;/span&gt;&lt;br /&gt;&amp;lt;div id=&amp;quot;write&amp;quot; style=&amp;quot;text-align:center;&amp;quot;&amp;gt;&amp;lt;textarea id=&amp;quot;message&amp;quot; cols=&amp;quot;50&amp;quot; rows=&amp;quot;5&amp;quot;&amp;gt;&amp;lt;/textarea&amp;gt;&amp;lt;br/&amp;gt;Name:&amp;lt;input type=&amp;quot;text&amp;quot; id=&amp;quot;name&amp;quot;/&amp;gt;&amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Send&amp;quot; onClick=&amp;quot;send();&amp;quot;/&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will display the messages&lt;/span&gt;&lt;br /&gt;function showmessages(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'show-message.php' file&lt;/span&gt;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;show-messages.php&amp;quot;,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,&amp;quot;showmessages.php&amp;quot;,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   &lt;span style="color:green;"&gt;//Replace the content of the &lt;i&gt;messages&lt;/i&gt; with the response from the 'show-messages.php' file&lt;/span&gt;&lt;br /&gt;   document.getElementById('messages').innerHTML = xmlhttp.responseText;&lt;br /&gt;   &lt;span style="color:green;"&gt;//Repeat the function each 30 seconds&lt;/span&gt;&lt;br /&gt;   setTimeout('showmessages()',30000);&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Start the &lt;i&gt;showmessages()&lt;/i&gt; function&lt;/span&gt;&lt;br /&gt;showmessages();&lt;br /&gt;&lt;span style="color:green;"&gt;//This function will submit the message&lt;/span&gt;&lt;br /&gt;function send(){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Send an XMLHttpRequest to the 'send.php' file with all the required informations&lt;/span&gt;&lt;br /&gt;   var sendto = 'send.php?message=' + document.getElementById('message').value + '&amp;amp;name=' + document.getElementById('name').value;&lt;br /&gt;   if(window.XMLHttpRequest){&lt;br /&gt;      xmlhttp = new XMLHttpRequest();&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send(null);&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      xmlhttp = new ActiveXObject(&amp;quot;Microsoft.XMLHTTP&amp;quot;);&lt;br /&gt;      xmlhttp.open(&amp;quot;GET&amp;quot;,sendto,false);&lt;br /&gt;      xmlhttp.send();&lt;br /&gt;   }&lt;br /&gt;   var error = '';&lt;br /&gt;   &lt;span style="color:green;"&gt;//If an error occurs the 'send.php' file send`s the number of the error and based on that number a message is displayed&lt;/span&gt;&lt;br /&gt;   switch(parseInt(xmlhttp.responseText)){&lt;br /&gt;   case 1:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 2:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;      break;&lt;br /&gt;   case 3:&lt;br /&gt;      error = 'Don`t forget the message!';&lt;br /&gt;      break;&lt;br /&gt;   case 4:&lt;br /&gt;      error = 'The message is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 5:&lt;br /&gt;      error = 'Don`t forget the name!';&lt;br /&gt;      break;&lt;br /&gt;   case 6:&lt;br /&gt;      error = 'The name is too long!';&lt;br /&gt;      break;&lt;br /&gt;   case 7:&lt;br /&gt;      error = 'This name is already used by somebody else!';&lt;br /&gt;      break;&lt;br /&gt;   case 8:&lt;br /&gt;      error = 'The database is down!';&lt;br /&gt;   }&lt;br /&gt;   if(error == ''){&lt;br /&gt;      document.getElementById('error').innerHTML = '';&lt;br /&gt;      showmessages();&lt;br /&gt;   }&lt;br /&gt;   else{&lt;br /&gt;      document.getElementById('error').innerHTML = error;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;send.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host', 'database', 'password') or die (1);&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die (2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is empty and send the error code&lt;/span&gt;&lt;br /&gt;if(strlen($message) &amp;lt; 1){&lt;br /&gt;   echo 3;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if message is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($message) &amp;gt; 255){&lt;br /&gt;   echo 4;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is empty&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;lt; 1){&lt;br /&gt;   echo 5;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if name is too long&lt;/span&gt;&lt;br /&gt;else if(strlen($name) &amp;gt; 29){&lt;br /&gt;   echo 6;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Check if the name is used by somebody else&lt;/span&gt;&lt;br /&gt;else if(mysql_num_rows(mysql_query(&amp;quot;select * from chat where name = '&amp;quot; . $name . &amp;quot;' and ip != '&amp;quot; . @$REMOTE_ADDR . &amp;quot;'&amp;quot;)) != 0){&lt;br /&gt;   echo 7;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//If everything is fine&lt;/span&gt;&lt;br /&gt;else{&lt;br /&gt;   &lt;span style="color:green;"&gt;//This array contains the characters what will be removed from the message and name, because else somebody could send redirection script or links&lt;/span&gt;&lt;br /&gt;   $search = array(&amp;quot;&amp;lt;&amp;quot;,&amp;quot;&amp;gt;&amp;quot;,&amp;quot;&amp;amp;gt;&amp;quot;,&amp;quot;&amp;amp;lt;&amp;quot;);&lt;br /&gt;   &lt;span style="color:green;"&gt;//Insert a new row in the chat table&lt;/span&gt;&lt;br /&gt;   mysql_query(&amp;quot;insert into chat values ('&amp;quot; . time() . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$name) . &amp;quot;', '&amp;quot; . @$REMOTE_ADDR . &amp;quot;', '&amp;quot; . str_replace($search,&amp;quot;&amp;quot;,$message) . &amp;quot;')&amp;quot;) or die(8);&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/div&gt;&lt;br /&gt;&lt;i&gt;show-messages.php&lt;/i&gt;&lt;div class="code"&gt;&amp;lt;?php&lt;br /&gt;&lt;span style="color:green;"&gt;//Connect to MySQL&lt;/span&gt;&lt;br /&gt;mysql_connect('host','database','password');&lt;br /&gt;&lt;span style="color:green;"&gt;//Select database&lt;/span&gt;&lt;br /&gt;mysql_select_db('database') or die(2);&lt;br /&gt;&lt;span style="color:green;"&gt;//Get the first 10 messages ordered by time&lt;/span&gt;&lt;br /&gt;$result = mysql_query(&amp;quot;select * from chat order by time desc limit 0,10&amp;quot;);&lt;br /&gt;$messages = array();&lt;br /&gt;&lt;span style="color:green;"&gt;//Loop and get in an array all the rows until there are not more to get&lt;/span&gt;&lt;br /&gt;while($row = mysql_fetch_array($result)){&lt;br /&gt;   &lt;span style="color:green;"&gt;//Put the messages in divs and then in an array&lt;/span&gt;&lt;br /&gt;   $messages[] = &amp;quot;&amp;lt;div class='message'&amp;gt;&amp;lt;div class='messagehead'&amp;gt;&amp;quot; . $row[name] . &amp;quot; - &amp;quot; . date('g:i A M, d Y',$row[time]) . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;div class='messagecontent'&amp;gt;&amp;quot; . $row[message] . &amp;quot;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;&lt;br /&gt;   &lt;span style="color:green;"&gt;//The last posts date&lt;/span&gt;&lt;br /&gt;   $old = $row[time];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//Display the messages in an ascending order, so the newest message will be at the bottom&lt;/span&gt;&lt;br /&gt;for($i=9;$i&amp;gt;=0;$i--){&lt;br /&gt;   echo $messages[$i];&lt;br /&gt;}&lt;br /&gt;&lt;span style="color:green;"&gt;//This is the more important line, this deletes each message older then the 10th message ordered by time is deleted, so the table will never have to store more than 10 messages.&lt;/span&gt;&lt;br /&gt;mysql_query(&amp;quot;delete from chat where time &amp;lt; &amp;quot; . $old);&lt;br /&gt;?&amp;gt;&lt;/div&gt;And this is it. A very effect chat system what uses only 10 rows of a MySQL table. This chat system can be easily upgraded with admin options or IP bans, smileys and other stuff like this. If you have any question related to this chat system just ASK!&lt;br /&gt;&lt;br /&gt;UPDATE: a new version of this script (that works in IE) is ready: &lt;a href="http://www.codingmix.com/2010/11/cross-browser-chat-script-using-php.html" title="chat"&gt;Cross-browser chat&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5682776130825686229-6620182635715936266?l=www.codingmix.com' alt='' /&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/IfZ-F5R87tcOhUILS9GnPGJjd5g/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IfZ-F5R87tcOhUILS9GnPGJjd5g/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/IfZ-F5R87tcOhUILS9GnPGJjd5g/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/IfZ-F5R87tcOhUILS9GnPGJjd5g/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/codingmix/PHP/tutorials/~4/BTBGl786ams" height="1" width="1"/&gt;</description><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">43</thr:total><feedburner:origLink>http://www.codingmix.com/2010/09/simple-chat-script-in-php-mysql-and.html</feedburner:origLink></item><media:rating>nonadult</media:rating></channel></rss>

