<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Novices Design Courses &#187; PHP</title>
	<atom:link href="http://novices-design-courses.info/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://novices-design-courses.info</link>
	<description>Design Blog</description>
	<lastBuildDate>Thu, 15 Oct 2009 05:09:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PHP &#8211; Simple caching</title>
		<link>http://novices-design-courses.info/php-simple-caching/</link>
		<comments>http://novices-design-courses.info/php-simple-caching/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 07:01:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=59</guid>
		<description><![CDATA[What should be on the main page?? Correctly, there should be ponemnozhku from each unit of a site. And certainly your page is under construction automatically, proceeding from contents of forums, news lines and other sections of a site.
What should be on the main page?? Correctly, there should be ponemnozhku from each unit of a [...]]]></description>
			<content:encoded><![CDATA[<p>What should be on the main page?? Correctly, there should be ponemnozhku from each unit of a site. And certainly your page is under construction automatically, proceeding from contents of forums, news lines and other sections of a site.<span id="more-59"></span></p>
<p>What should be on the main page?? Correctly, there should be ponemnozhku from each unit of a site. And certainly your page is under construction automatically, proceeding from contents of forums, news lines and other sections of a site.</p>
<p>How much SQL searches it is carried out at loading the main page?? How much blocks are pumped up from other sites??</p>
<p>Now we shall consider a simple and effective way of caching of such data.</p>
<p>As an example we shall consider a case of import of news from the external server: http://news.novgorod.ru/ultramode.txt</p>
<p>Our problem{task} to receive this file, to process it{him} and to deduce{remove} to his{its} user. The program doing{making} it, looks as follows:</p>
<p>&lt;?</p>
<p>$d = file (&#8221; http: // news.novgorod.ru/ultramode.txt &#8220;);</p>
<p>for ($i=0; $i &lt;11; $i ++) {</p>
<p>$msg = $ d [2 + $ i*8];</p>
<p>$url = $ d [3 + $ i*8];</p>
<p>$date = $ d [4 + $ i*8];</p>
<p>print &#8221; &lt;a href =&#8217;http: // news.novgorod.ru &#8221; .trim ($url). &#8221; &#8216;&gt; &#8220;;</p>
<p>print trim ($msg.) &#8221; &lt;/a&gt; (&#8220;. $date. &#8220;)&#8221;;</p>
<p>}</p>
<p>?&gt;</p>
<p>At each loading our page there is a reference{manipulation} to the external server news.novgorod.ru, therefrom under report HTTP the file ultramode.txt is downloaded. And now we shall present a situation, that the server is on the other end of a planet and connection and furthermore the file transfer borrows{occupies} enough more time. Or moreover, the server can be temporarily inaccessible.</p>
<p>Conclusion. What for each time podgruzhat` a file ultamode.txt if news are updated not more often than an once at two &#8211; three o&#8217;clock?? Correctly. It is necessary kehshirovat`.</p>
<p>And we shall do{make} it very simply. As you could notice, the comment is stored{kept} in the first line of a file. The comment is not necessary for us and on his{its} place it is possible to place date of last updating of a file wonderfully.</p>
<p>Algorithm of job the following:</p>
<p>1. We read &#8211; out kehshirovannuju the version</p>
<p>2. If kehshirovannaja the version is obsolete, on its{her} place we read &#8211; out a file http://news.novgorod.ru/ultramode.txt, we replace the first line with current time and is saved in a cache.</p>
<p>3. We make out and is deduced{removed} given to the user.</p>
<p>The code making all this is below resulted:</p>
<p>&lt;?</p>
<p>// We read &#8211; out a file from a cache</p>
<p>$d = file (&#8220;/tmp/news.cache&#8221;);</p>
<p>$fs=trim ($d [1]);</p>
<p>// If the file was not updated 3600 seconds (1 hour) or the file is empty,</p>
<p>// That we update it{him}</p>
<p>if (intval ($d [0]) &lt;time ()-600 || empty ($fs)) {</p>
<p>$d = file (&#8221; http: // news.novgorod.ru/ultramode.txt &#8220;);</p>
<p>$fs=trim ($d [1]);</p>
<p>// We save new versju in a cache</p>
<p>if (! empty ($fs)) {</p>
<p>$fw=fopen (&#8220;/tmp/news.cache&#8221;, &#8220;wt&#8221;);</p>
<p>flock ($fw, LOCK_EX);</p>
<p>// In the first line we shall write down current time</p>
<p>fputs ($fw, time (). &#8220;n&#8221;);</p>
<p>// We shall save other lines</p>
<p>for ($i=1; $i &lt;count ($d); $i ++) fputs ($fw, trim ($d [$i]). &#8220;n&#8221;);</p>
<p>fclose ($fw);</p>
<p>}</p>
<p>// If, for some reason, the file has not been downloaded,</p>
<p>// That we shall use kehshirovannoj the version</p>
<p>else $d = file (&#8220;/tmp/news.cache&#8221;);</p>
<p>}</p>
<p>// A conclusion of the data</p>
<p>for ($i=0; $i &lt;11; $i ++) {</p>
<p>$msg = $ d [2 + $ i*8];</p>
<p>$url = $ d [3 + $ i*8];</p>
<p>$date = $ d [4 + $ i*8];</p>
<p>print &#8221; &lt;a href =&#8217;http: // news.novgorod.ru &#8221; .trim ($url). &#8221; &#8216;&gt; &#8220;;</p>
<p>print trim ($msg.) &#8221; &lt;/a&gt; (&#8220;. $date. &#8220;)&#8221;;</p>
<p>}</p>
<p>That&#8217;s all. In the same way it is possible kehshirovat` and SQL searches. Using this mechanism I managed to reduce time of creation of the main page with 1.5 sek till 0.05 sek</p>
<p>How to send letters PHP attachami</p>
<p>How to send the letter in HTML a kind? Attach to the letter attach with the name message.html and the letter to turn to the HTML-letter!</p>
<p>&lt;?</p>
<p>// Functions. It is possible to bear{take out} in dpugoj a file.</p>
<p>class html_mime_mail {</p>
<p>var $headers;</p>
<p>var $multipart;</p>
<p>var $mime;</p>
<p>var $html;</p>
<p>var $parts = array ();</p>
<p>function html_mime_mail ($headers = &#8220;&#8221;) {</p>
<p>$this-&gt; headers = $ headers;</p>
<p>}</p>
<p>function add_html ($html = &#8220;&#8221;) {</p>
<p>$this-&gt; html. = $ html;</p>
<p>}</p>
<p>function build_html ($orig_boundary, $kod) {</p>
<p>$this-&gt; multipart. = &#8221; &#8211; $orig_boundaryn &#8220;;</p>
<p>if ($kod == &#8216;w&#8217; || $kod == &#8216;win&#8217; || $kod == &#8216;windows-1251&#8242;) $kod =&#8217;windows-1251 &#8216;;</p>
<p>else $kod =&#8217;koi8-r &#8216;;</p>
<p>$this-&gt; multipart. = &#8221; Content-Type: text/html; charset = $ kodn &#8220;;</p>
<p>$this-&gt; multipart. = &#8221; BCC: del@ipo.spb.run &#8220;;</p>
<p>$this-&gt; multipart. = &#8221; Content-Transfer-Encoding: Quot-Printednn &#8220;;</p>
<p>$this-&gt; multipart. = &#8221; $ this-&gt; htmlnn &#8220;;</p>
<p>}</p>
<p>function add_attachment ($path = &#8220;&#8221;, $name = &#8221; &#8220;, $c_type = &#8220;application/octet-stream&#8221;) {</p>
<p>if (! file_exists ($path. $ name)) {</p>
<p>print &#8221; File $path. $ name dosn&#8217;t exist. &#8220;;</p>
<p>return;</p>
<p>}</p>
<p>$fp=fopen ($path. $ name, &#8220;r&#8221;);</p>
<p>if (! $fp) {</p>
<p>print &#8221; File $path. $ name coudn&#8217;t be read. &#8220;;</p>
<p>return;</p>
<p>}</p>
<p>$file=fread ($fp, filesize ($path. $ name));</p>
<p>fclose ($fp);</p>
<p>$this-&gt; parts [] =array (&#8220;body&#8221; =&gt; $file, &#8220;name&#8221; =&gt; $name, &#8220;c_type&#8221; =&gt; $c_type);</p>
<p>}</p>
<p>function build_part ($i) {</p>
<p>$message_part = &#8220;&#8221;;</p>
<p>$message_part. = &#8221; Content-Type: &#8220;. $this-&gt; parts [$i] ["c_type"];</p>
<p>if ($this-&gt; parts [$i] ["name"]! = &#8221; &#8220;)</p>
<p>$message_part. = &#8220;; name = &#8221; &#8220;. $this-&gt; parts [$i] ["name."] &#8221; &#8220;n&#8221;;</p>
<p>else</p>
<p>$message_part. = &#8220;n&#8221;;</p>
<p>$message_part. = &#8221; Content-Transfer-Encoding: base64n &#8220;;</p>
<p>$message_part. = &#8221; Content-Disposition: attachment; filename = &#8221; &#8220;.</p>
<p>$this-&gt; parts [$i] ["name."] &#8221; &#8220;nn&#8221;;</p>
<p>$message_part. = chunk_split (base64_encode ($this-&gt; parts [$i] ["body"])). &#8220;n&#8221;;</p>
<p>return $message_part;</p>
<p>}</p>
<p>function build_message ($kod) {</p>
<p>$boundary = &#8221; = _ &#8220;.md5 (uniqid (time));</p>
<p>$this-&gt; headers. = &#8221; MIME-Version: 1.0n &#8220;;</p>
<p>$this-&gt; headers. = &#8221; Content-Type: multipart/mixed; boundary = &#8221; $ boundary &#8220;n&#8221;;</p>
<p>$this-&gt; multipart = &#8220;&#8221;;</p>
<p>$this-&gt; multipart. = &#8221; This is a MIME encoded message.nn &#8220;;</p>
<p>$this-&gt; build_html ($boundary, $kod);</p>
<p>for ($i = (count ($this-&gt; parts)-1); $i&gt; =0; $i-)</p>
<p>$this-&gt; multipart. = &#8221; &#8211; $boundaryn &#8220;. $this-&gt; build_part ($i);</p>
<p>$this-&gt; mime = &#8221; $this-&gt; multipart &#8211; $boundary &#8211; n &#8220;;</p>
<p>}</p>
<p>function send ($server, $to, $from, $subject = &#8220;&#8221;, $headers = &#8220;&#8221;) {</p>
<p>$headers = &#8221; To: $tonFrom: $fromnSubject: $subjectnX-Mailer: The Mouse! n$headers &#8220;;</p>
<p>$fp = fsockopen ($server, 25, both $errno, and $errstr, 30);</p>
<p>if (! $fp)</p>
<p>die (&#8221; Server $server. Connection failed: $errno, $errstr &#8220;);</p>
<p>fputs ($fp, &#8221; HELO $servern &#8220;);</p>
<p>fputs ($fp, &#8221; MAIL FROM: $fromn &#8220;);</p>
<p>fputs ($fp, &#8221; RCPT TO: $ton &#8220;);</p>
<p>fputs ($fp, &#8220;DATAn&#8221;);</p>
<p>fputs ($fp, $this-&gt; headers);</p>
<p>if (strlen ($headers))</p>
<p>fputs ($fp, &#8220;$headersn&#8221;);</p>
<p>fputs ($fp, $this-&gt; mime);</p>
<p>fputs ($fp, &#8220;n.nQUITn&#8221;);</p>
<p>while (! feof ($fp))</p>
<p>$resp. = fgets ($fp, 1024);</p>
<p>fclose ($fp);</p>
<p>}</p>
<p>}</p>
<p>// *************************************************************************</p>
<p>//</p>
<p>// In quality attacha ppisoedinjaem the html-letter (opens automatically).</p>
<p>// The second attach &#8211; some file from the catalogue.</p>
<p>// So to cause all that is written above:</p>
<p>//</p>
<p>// *************************************************************************</p>
<p>$mail=new html_mime_mail ();</p>
<p>$mail-&gt; add_html (&#8221; &lt;html&gt; &lt;body&gt; &lt;center&gt; &lt;h2&gt; Ppivet! &lt;br&gt; &lt;br&gt; &#8220;.</p>
<p>&#8221; &lt;br&gt; I Send a binary file [/bin/ls...] &#8220;.</p>
<p>&#8221; &lt;/h2&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt; &#8220;);</p>
<p>$mail-&gt; add_attachment (&#8220;/bin / &#8220;, &#8220;ls&#8221;);</p>
<p>$mail-&gt; build_message (&#8216; win &#8216;); // if not &#8220;win&#8221;, kodipovka koi8</p>
<p>$mail-&gt; send (&#8216; POCHTOVYJJ_KHOST_VASHEGO_PROVAJJDERA &#8216;,</p>
<p>&#8216; TO WHOM _ (E-MAIL) &#8216;,</p>
<p>&#8216; OT_KOGO _ (E-MAIL) &#8216;,</p>
<p>&#8216; SUBJECT OF THE LETTER &#8216;);</p>
<p>//</p>
<p>// After arrival of the letter we swing on FTP original/bin/ls and it is compared with</p>
<p>// Imported from the letter:</p>
<p>//</p>
<p>// X:temp&gt; fc/b ls ls2</p>
<p>// Comparison of files ls and LS2</p>
<p>// FC: distinctions are not found</p>
<p>//</p>
<p>//</p>
<p>// Attention! If you do not have file/bin/ls it is simple zakommentirujte a line</p>
<p>// $mail-&gt; add_attachment (&#8220;/bin / &#8220;, &#8220;ls&#8221;) that the program did not try to attach</p>
<p>// To the letter necuhhestvujuhhie files.</p>
<p>//</p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/php-simple-caching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The guest book on PHP/MySQL</title>
		<link>http://novices-design-courses.info/the-guest-book-on-phpmysql/</link>
		<comments>http://novices-design-courses.info/the-guest-book-on-phpmysql/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 06:57:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[guest book]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=56</guid>
		<description><![CDATA[Today I shall tell to you about how to write the guest book on PHP and MySQL. Anything complex{difficult} in it no, and opportunities given guest not the biggest: a paginal conclusion of recordings, check of the entered data, an opportunity to delete recording.
Today I shall tell to you about how to write the guest [...]]]></description>
			<content:encoded><![CDATA[<p>Today I shall tell to you about how to write the guest book on PHP and MySQL. Anything complex{difficult} in it no, and opportunities given guest not the biggest: a paginal conclusion of recordings, check of the entered data, an opportunity to delete recording.<span id="more-56"></span></p>
<p>Today I shall tell to you about how to write the guest book on PHP and MySQL. Anything complex{difficult} in it no, and opportunities given guest not the biggest: a paginal conclusion of recordings, check of the entered data, an opportunity to delete recording.</p>
<p>We admit{allow}, that at you already is PHP, MySQL and the web &#8211; server. All of you have established and have adjusted.</p>
<p>Let&#8217;s start with creation of the table in which the data of our guest book will be stored{kept}. We shall ask the user a name and the comment. At desire the user can inform e-mail addresses and a homepage. For administration of the book we need one more field, unique for each recording, &#8211; the identifier. Well and date, certainly. In a result such table turns out:</p>
<p>CREATE TABLE gb (</p>
<p>id int (10) unsigned NOT NULL auto_increment,</p>
<p>datetime datetime DEFAULT &#8216; 0000-00-00 00:00:00 &#8216; NOT NULL,</p>
<p>name varchar (100) NOT NULL,</p>
<p>email varchar (100),</p>
<p>www varchar (100),</p>
<p>message text NOT NULL,</p>
<p>PRIMARY KEY (id)</p>
<p>);</p>
<p>The table at us is. Now it is possible to start programming.</p>
<p>For we shall create a file with adjustments of the guest book:</p>
<p>&lt;? php</p>
<p>// The general{common} constants</p>
<p>define (&#8216;PATH&#8217;, &#8216;/gb / &#8216;); // a way to the guest book</p>
<p>define (&#8216; RECSPERPAGE &#8216;, 10); // quantity{amount} of recordings on one page</p>
<p>define (&#8216; ADMIN_EMAIL &#8216;,&#8217; artem@sapegin.ru &#8216;); // email the manager</p>
<p>define (&#8216; ERROR_LOG_FILE &#8216;,&#8217; logs/error.log &#8216;); // a file of a broad gully of mistakes</p>
<p>// Parameters of a DB</p>
<p>define (&#8216; DBHOST &#8216;,&#8217; localhost &#8216;); // the host name</p>
<p>define (&#8216; DBUSER &#8216;,&#8217; root &#8216;); // a login name</p>
<p>define (&#8216; DBPASSWD &#8216;, &#8220;); // the password</p>
<p>define (&#8216; DBNAME &#8216;,&#8217; test &#8216;); // a name of a database</p>
<p>?&gt;</p>
<p>Now we shall think, what auxiliary functions will be necessary for us. On it will be necessary to cooperate with SUBD, will check up and to process the data entered by the user. As for functions of administration on it is required to distinguish the manager from simple users.</p>
<p>Let&#8217;s start with job with SUBD.</p>
<p>&lt;? php</p>
<p>/ ** recource db_connect (string host, string user, string passwd, string dbname)</p>
<p>* Connection to SUBD and opening of a database</p>
<p>*/</p>
<p>function db_connect ($host, $user, $passwd, $dbname)</p>
<p>{</p>
<p>$link = mysql_pconnect ($host, $user, $passwd) or die (&#8216; Could not connect to database &#8216;);</p>
<p>mysql_select_db ($dbname) or die (&#8216; Could not select database &#8216;);</p>
<p>return $link;</p>
<p>}</p>
<p>/ ** Carries out search to a DB</p>
<p>*</p>
<p>* @param the text of search</p>
<p>* @return resource id</p>
<p>*/</p>
<p>function db_query ($query)</p>
<p>{</p>
<p>$result = mysql_query ($query)</p>
<p>or die (&#8216; Bad database query &#8216;);</p>
<p>return $result;</p>
<p>}</p>
<p>/ ** Carries out search to a DB (placeholder)</p>
<p>*</p>
<p>* @param the text of search</p>
<p>* @param*</p>
<p>* @return resource id</p>
<p>*/</p>
<p>function db_query_ex ($query)</p>
<p>{</p>
<p>$values = func_get_args ();</p>
<p>array_shift ($values);</p>
<p>$i = 0;</p>
<p>return db_query (preg_replace (&#8216; %? %e &#8216;,&#8217; &#8220;&#8216;&#8221; .addslashes ($values [$i ++]). &#8220;&#8216;&#8221; &#8216;,</p>
<p>$query));</p>
<p>}</p>
<p>?&gt;</p>
<p>Processing of lines (check and kill of the data entered by the user).</p>
<p>&lt;? php</p>
<p>/ **</p>
<p>* Whether checks is the line e-mail address</p>
<p>*/</p>
<p>function strings_isemail ($string)</p>
<p>{</p>
<p>return preg_match (&#8216; % [-.w] + [-w] + (?:. [-w] +) + % &#8216;, $string);</p>
<p>}</p>
<p>/ **</p>
<p>* Addition of links on http and e-mail</p>
<p>*/</p>
<p>function strings_addlinks ($string)</p>
<p>{</p>
<p>return preg_replace (</p>
<p>&#8216; % ((?:http|ftp): // [-w] + (?:. [-w] +) +b [-w: and? = +! / ~ * $. ' %] *) (? &lt;! [.?!)]) % i &#8216;,</p>
<p>&#8216; &lt;a href = &#8220;\1 &#8220;&gt; \1 &lt;a&gt; &#8216;,</p>
<p>$string</p>
<p>);</p>
<p>}</p>
<p>/ **</p>
<p>* Cleaning a line</p>
<p>*/</p>
<p>function strings_clear ($string)</p>
<p>{</p>
<p>$string = trim ($string);</p>
<p>$string = stripslashes ($string);</p>
<p>return htmlspecialchars ($string, ENT_QUOTES);</p>
<p>}</p>
<p>/ **</p>
<p>* Trimming a line</p>
<p>*/</p>
<p>function strings_stripstring ($text, $wrap, $length)</p>
<p>{</p>
<p>$text = preg_replace (&#8216; % (S {&#8216;. $ wrap. &#8216;}) % &#8216;, &#8216;\1, $text);</p>
<p>return substr ($text, 0, $length);</p>
<p>}</p>
<p>?&gt;</p>
<p>autentifikacii the manager I leave a spelling to you as the domestic task. There are many ways and their discussion &#8211; a subject of separate clause{article}. I shall result only function &#8211; zaglushku:</p>
<p>&lt;? php</p>
<p>/ **</p>
<p>* Check: the manager or the usual user</p>
<p>*/</p>
<p>function auth_is_admin ()</p>
<p>{</p>
<p>return $ _GET [' admin '];</p>
<p>}</p>
<p>?&gt;</p>
<p>Further goes enough the big module which contains almost all HTML-code of the guest book, &#8211; a pattern. In him there is nothing complex{difficult} and his{its} spelling is possible quite under force verstal`hhiku a site if at you those is present.</p>
<p>&lt;? php</p>
<p>/ **</p>
<p>* Heading of page</p>
<p>*/</p>
<p>function template_header ($page)</p>
<p>{</p>
<p>?&gt; &lt;html&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;title&gt; page &lt;? = $page?&gt; &lt;fjGuestbook Demo &lt;/title&gt;</p>
<p>&lt;style&gt;</p>
<p>body {</p>
<p>padding: 15px;</p>
<p>margin: 0;</p>
<p>color: *333;</p>
<p>background-color: *eee;</p>
<p>border-left: 30px solid *adba8e;</p>
<p>font: 500 .9em verdana, arial, helvetica;</p>
<p>}</p>
<p>a:link {color: *250;}</p>
<p>a:visited {color: *639;}</p>
<p>a:active, a:hover {</p>
<p>color: *c00;</p>
<p>text-decoration: underline;</p>
<p>}</p>
<p>h1 {font-size: 150 %;}</p>
<p>h2 {font-size: 110 %;}</p>
<p>.c {margin-bottom: 10px;}</p>
<p>.cn {</p>
<p>background-color: *d2d6bc;</p>
<p>padding: 2px 4px;</p>
<p>margin-bottom: 4px;</p>
<p>}</p>
<p>&lt;/style&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;h1&gt; fjGuestbook Demo &lt;/h1&gt; &lt;? php</p>
<p>}</p>
<p>/ **</p>
<p>* The termination{ending} of page</p>
<p>*/</p>
<p>function template_footer ()</p>
<p>{</p>
<p>?&gt;</p>
<p>&lt;p&gt; fjGuestbook 1.2. Copyright © 2002-2004</p>
<p>&lt;a href = &#8221; http: // sapegin.ru &#8220;&gt; Artem Sapegin &lt;/a&gt; &lt;/p&gt;</p>
<p>&lt;/body&gt; &lt;/html&gt;</p>
<p>&lt;? php</p>
<p>}</p>
<p>/ **</p>
<p>* The form of addition of new recording</p>
<p>*/</p>
<p>function template_form ($name, $email, $www, $message, $error)</p>
<p>{</p>
<p>// A conclusion of the message on a mistake</p>
<p>function error ($error)</p>
<p>{</p>
<p>if ($error) echo &#8216; &lt;br&gt; &lt;font color = * 880000&gt; &#8216;. $ error.</p>
<p>&#8216; &lt;/font&gt; &#8216;;</p>
<p>}</p>
<p>echo &#8216; &lt;h2&gt; To add the new message &lt;/h2&gt;</p>
<p>&lt;p&gt; &lt;table cellspacing = &#8220;2&#8243; cellpadding = &#8220;2&#8243; border = &#8220;0&#8243;&gt;</p>
<p>&lt;form action = &#8216;.PATH. &#8216;? add=1 method=post&gt; &lt;tr&gt;</p>
<p>&lt;td&gt; the Name &lt;font color = * 880000&gt; * &lt;/font&gt;: &lt;/td&gt;</p>
<p>&lt;td&gt; &lt;input type=text name = &#8220;name&#8221; size=30</p>
<p>maxlength=100 value = &#8221; &#8216;. $ name. &#8216; &#8220;&gt; &#8216;;</p>
<p>@error ($error [' name ']);</p>
<p>echo &#8216; &lt;/td&gt;</p>
<p>&lt;/tr&gt; &lt;tr&gt;</p>
<p>&lt;td&gt; Email: &lt;/td&gt;</p>
<p>&lt;td&gt; &lt;input type=text name = &#8220;email&#8221; size=30</p>
<p>maxlength=100 value = &#8221; &#8216;. $ email. &#8216; &#8220;&gt; &#8216;;</p>
<p>@error ($error [' email ']);</p>
<p>echo &#8216; &lt;/td&gt;</p>
<p>&lt;/tr&gt; &lt;tr&gt;</p>
<p>&lt;td&gt; URL: &lt;/td&gt;</p>
<p>&lt;td&gt; &lt;input type=text name = &#8220;www&#8221; size=30</p>
<p>maxlength=100 value = &#8221; &#8216;. $ www. &#8216; &#8220;&gt; &#8216;;</p>
<p>echo &#8216; &lt;/td&gt;</p>
<p>&lt;/tr&gt; &lt;tr&gt;</p>
<p>&lt;td&gt; the Message &lt;font color = * 880000&gt; * &lt;/font&gt;: &lt;/td&gt;</p>
<p>&lt;td&gt; &lt;textarea cols=40 rows=5</p>
<p>name = &#8220;message&#8221;&gt; &#8216;. $ message. &#8216; &lt;/textarea&gt; &#8216;;</p>
<p>@error ($error [' message ']);</p>
<p>echo &#8216; &lt;/td&gt;</p>
<p>&lt;/tr&gt; &lt;tr&gt;</p>
<p>&lt;td&gt; &lt;/td&gt;</p>
<p>&lt;td&gt; &lt;small&gt; &lt;font color = * 880000&gt; * &lt;/font&gt;</p>
<p>- Obligatory fields &lt;/small&gt; &lt;/td&gt;</p>
<p>&lt;/tr&gt; &lt;tr&gt;</p>
<p>&lt;td&gt; &lt;/td&gt;</p>
<p>&lt;td&gt; &lt;input name = &#8220;sb&#8221; type=submit</p>
<p>value = &#8221; To add the message &#8220;&gt; &lt;/td&gt;</p>
<p>&lt;/form&gt; &lt;/tr&gt;</p>
<p>&lt;/table&gt; &#8216;;</p>
<p>}</p>
<p>/ **</p>
<p>* A seal of one recording the guest book</p>
<p>*/</p>
<p>function template_show_body ($id, $name, $email, $www, $message, $datetime)</p>
<p>{</p>
<p>$out = &#8216; &lt;div&gt; &lt;div&gt; &lt;b&gt; &#8216;. $ name. &#8216; &lt;/b&gt; &#8216;;</p>
<p>// If is email or homepage &#8211; it is printed them</p>
<p>if ($email || $www)</p>
<p>{</p>
<p>$out. = &#8216; (&#8216;;</p>
<p>if ($email)</p>
<p>$out. = &#8216; &lt;a href=mailto: &#8216;. $ email. &#8216;&gt; email &lt;/a&gt; &#8216;;</p>
<p>if ($email ** $www)</p>
<p>$out. = &#8216; | &#8216;;</p>
<p>if ($www)</p>
<p>$out. = &#8216; &lt;a href = &#8216;. $ www. &#8216;&gt; www &lt;/a&gt; &#8216;;</p>
<p>$out. = &#8216;) &#8216;;</p>
<p>}</p>
<p>$out. = &#8216; writes &#8216;. $ datetime. &#8216;: &lt;/div&gt; &#8216;. $ message. &#8216; &lt;/div&gt; &#8216;;</p>
<p>// If the guest book is looked through by the manager &#8211; print the button</p>
<p>// Removals{Distances} of recording</p>
<p>if (auth_is_admin ())</p>
<p>{</p>
<p>$out. = &#8216; &lt;div&gt; [&lt;a href = '.PATH. '? admin=1*del = '. $ id.</p>
<p>'&gt; to remove &lt;/a&gt;] &lt;/div&gt; &#8216;;</p>
<p>}</p>
<p>return $out;</p>
<p>}</p>
<p>?&gt;</p>
<p>And, we at last have reached the main thing. Up to the module of the guest book. I shall try to write more comments that to you it was understandable.</p>
<p>&lt;? php</p>
<p>/ **</p>
<p>* Creation of the table if she{it} still no</p>
<p>*/</p>
<p>function gb_install ()</p>
<p>{</p>
<p>db_query (</p>
<p>&#8216; CREATE TABLE IF NOT EXISTS gb (</p>
<p>id int (10) unsigned NOT NULL auto_increment,</p>
<p>datetime datetime NOT NULL default &#8216; 0000-00-00 00:00:00 &#8216;,</p>
<p>name varchar (100) NOT NULL default &#8220;,</p>
<p>email varchar (100) default NULL,</p>
<p>www varchar (100) default NULL,</p>
<p>message text NOT NULL,</p>
<p>PRIMARY KEY (id),</p>
<p>INDEX (datetime)</p>
<p>) TYPE=MyISAM; &#8216;</p>
<p>);</p>
<p>}</p>
<p>/ **</p>
<p>* Addition of recording in the guest book</p>
<p>*/</p>
<p>function gb_add ($name, $email, $www, $message, and $error)</p>
<p>{</p>
<p>// We check correctness of filling of fields</p>
<p>$error = &#8220;;</p>
<p>if (empty ($name))</p>
<p>$error [' name '] = &#8216; This obligatory field &#8216;;</p>
<p>if (empty ($message))</p>
<p>$error [' message '] = &#8216; This obligatory field &#8216;;</p>
<p>if (! empty ($email) **! strings_isemail ($email))</p>
<p>$error [' email '] = &#8216; It not email &#8216;;</p>
<p>// If not was mistakes &#8211; it is added</p>
<p>if (! $error)</p>
<p>{</p>
<p>// We clean the data</p>
<p>$name = strings_clear ($name);</p>
<p>$message = strings_clear ($message);</p>
<p>$name = strings_stripstring ($name, 15, 100);</p>
<p>$email = strings_stripstring ($email, 100, 100);</p>
<p>$www = strings_stripstring ($www, 100, 100);</p>
<p>$message = strings_stripstring ($message, 100, 2000);</p>
<p>$message = nl2br ($message);</p>
<p>// If the user was too lazy to write http:// before the address &#8211; we shall make</p>
<p>// It for him{it}</p>
<p>if (! empty ($www) ** &#8216; http:// &#8216;! = substr ($www, 0, 7))</p>
<p>$www = &#8216; http: // &#8216;. $ www;</p>
<p>// Search about addition of recording in a database</p>
<p>db_query_ex (&#8216; INSERT INTO gb (name, email, www, message, datetime)</p>
<p>VALUES (????, NOW ()) &#8216;, $name, $email, $www, $message);</p>
<p>// We throw a browser on the first page</p>
<p>// It is necessary, that if the user will press button Refresh,</p>
<p>// Recording was not added once again</p>
<p>header (&#8216; Location: &#8216;.PATH. &#8220;? page=1 &#8220;);</p>
<p>}</p>
<p>}</p>
<p>// Removal{Distance} of recording from the guest book</p>
<p>function gb_delete ($id)</p>
<p>{</p>
<p>// Search about removal{distance} of recording from a database</p>
<p>// WHERE id = &#8216;. $ id specifies recording which should be removed</p>
<p>db_query_ex (&#8216; DELETE FROM gb WHERE id =? &#8216;, $id);</p>
<p>header (&#8216; Location: &#8216;.PATH. &#8220;? page=1 &#8220;); //???</p>
<p>}</p>
<p>// A conclusion of page with recordings</p>
<p>function gb_show ($page)</p>
<p>{</p>
<p>// Position of the first recording page</p>
<p>$begin = ($page &#8211; 1) * 10;</p>
<p>// Sample of recordings of a database</p>
<p>// SELECT * FROM gb &#8211; all fields from bd gb</p>
<p>// ORDER BY datetime DESC &#8211; sorting by date of, new from above</p>
<p>// LIMIT &#8216;. $ begin. &#8216;, &#8216;.RECSPERPAGE &#8211; restriction:</p>
<p>// RECSPERPAGE (see defines.php) recordings since $begin</p>
<p>$result = db_query (&#8216; SELECT * FROM gb ORDER BY datetime DESC LIMIT &#8216;.</p>
<p>$begin. &#8216;, &#8216;.RECSPERPAGE);</p>
<p>$out = &#8220;;</p>
<p>// A cycle on all chosen recordings</p>
<p>while ($row = mysql_fetch_array ($result))</p>
<p>$out. = template_show_body ($row [' id '], $row [' name '], $row [' email '],</p>
<p>$row [' www '], $row [' message '], $row [' datetime ']);</p>
<p>// We destroy result</p>
<p>mysql_free_result ($result);</p>
<p>echo $out;</p>
<p>}</p>
<p>// A conclusion of the list of pages</p>
<p>function gb_showpages ($current)</p>
<p>{</p>
<p>// We learn{We find out} number of recordings in the guest book</p>
<p>$result = db_query (&#8216; SELECT * FROM gb &#8216;);</p>
<p>$rows = mysql_num_rows ($result);</p>
<p>if ($rows)</p>
<p>{</p>
<p>$pages = ceil ($rows / RECSPERPAGE);</p>
<p>// We print links to pages (number{room} of the current page is not the link)</p>
<p>echo &#8216; &lt;div&gt; &#8216;;</p>
<p>for ($i = 1; $i &lt;= $pages; $i ++)</p>
<p>{</p>
<p>if ($i! = $current)</p>
<p>echo &#8216; | &lt;a href = &#8216;.PATH. &#8216;? page = &#8216;. $ i. &#8216;&gt;&#8217;. $ i. &#8216; &lt;/a&gt; &#8216;;</p>
<p>else</p>
<p>echo &#8216; | &#8216;. $ i;</p>
<p>}</p>
<p>echo &#8216; | &#8216;;</p>
<p>// If it not polslednjaja page we print the link &#8220;Further&#8221;</p>
<p>if ($current &lt;$pages)</p>
<p>echo &#8216;&gt; a href = &#8216;.PATH. &#8216;? page = &#8216;. ($ current + 1).</p>
<p>&#8216;&gt; is Farther&gt;&gt; &lt;/a&gt; &#8216;;</p>
<p>echo &#8216; &lt;/div&gt; &#8216;;</p>
<p>}</p>
<p>}</p>
<p>?&gt;</p>
<p>And the last &#8211; it is united all together.</p>
<p>&lt;? php</p>
<p>/ **</p>
<p>* fjGuestbook 1.2</p>
<p>*</p>
<p>* A nucleus of the guest book</p>
<p>*</p>
<p>* Copyright 2002-2004 Artem Sapegin</p>
<p>* http://sapegin.ru</p>
<p>*/</p>
<p>// We connect modules</p>
<p>require_once &#8216; my/defines.php &#8216;;</p>
<p>require_once &#8216; my/template.php &#8216;;</p>
<p>require_once &#8216; engine/lib/strings.php &#8216;;</p>
<p>require_once &#8216; engine/lib/auth.php &#8216;;</p>
<p>require_once &#8216; engine/lib/bd.php &#8216;;</p>
<p>require_once &#8216; engine/gb.php &#8216;;</p>
<p>// We are connected to a DB</p>
<p>db_connect (DBHOST, DBUSER, DBPASSWD, DBNAME);</p>
<p>// We create the table if she{it} no</p>
<p>gb_install ();</p>
<p>// We obtain the given forms if the form has been sent</p>
<p>if (! empty ($ _POST [' sb ']))</p>
<p>{</p>
<p>$name = $ _POST [' name '];</p>
<p>$email = $ _POST [' email '];</p>
<p>$www = $ _POST [' www '];</p>
<p>$message = $ _POST [' message '];</p>
<p>$formerr = &#8220;;</p>
<p>}</p>
<p>else</p>
<p>{</p>
<p>$name = $email = $www = $message = $formerr = &#8220;;</p>
<p>}</p>
<p>// If number{room} of page is not specified in GET-search, we deduce{remove} the first</p>
<p>if (is_numeric ($ _GET [' page ']))</p>
<p>$page = $ _GET [' page '];</p>
<p>else</p>
<p>$page = 1;</p>
<p>// If it is necessary to add recording, we add</p>
<p>if ($ _GET [' add '])</p>
<p>gb_add ($name, $email, $www, $message, $formerr);</p>
<p>// If it is necessary to remove recording, we delete</p>
<p>if (isset ($ _GET [' del ']) ** auth_is_admin ())</p>
<p>gb_delete (intval ($ _GET [' del ']));</p>
<p>// We print the guest book</p>
<p>template_header ($page);</p>
<p>gb_showpages ($page);</p>
<p>gb_show ($page);</p>
<p>gb_showpages ($page);</p>
<p>template_form ($name, $email, $www, $message, $formerr);</p>
<p>template_footer ();</p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/the-guest-book-on-phpmysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The guest book step by step</title>
		<link>http://novices-design-courses.info/the-guest-book-step-by-step/</link>
		<comments>http://novices-design-courses.info/the-guest-book-step-by-step/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 06:56:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[guest book]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=54</guid>
		<description><![CDATA[In this clause{article} we shall learn to create the guest book on PHP. And though this clause{article} is written for newbies, but you should possess even elements of programming on PHP.
In this clause{article} we shall learn to create the guest book on PHP. And though this clause{article} is written for newbies, but you should possess [...]]]></description>
			<content:encoded><![CDATA[<p>In this clause{article} we shall learn to create the guest book on PHP. And though this clause{article} is written for newbies, but you should possess even elements of programming on PHP.<span id="more-54"></span></p>
<p>In this clause{article} we shall learn to create the guest book on PHP. And though this clause{article} is written for newbies, but you should possess even elements of programming on PHP.</p>
<p>So, for the beginning let&#8217;s be defined{determined}, that we shall write. In a result we should receive the guest book with the following properties:</p>
<p>* The visitor necessarily should enter the name and the message, and at will the e-mail and the address of a homepage.</p>
<p>* Splitting into pages.</p>
<p>* Our guest book should work with register_globals = Off.</p>
<p>* All recordings are stored{kept} in a usual text file (i.e. we will not need a database).</p>
<p>* The guest book will consist of one file.</p>
<p>The note. All below-mentioned have been tested on PHP 4.3.0.</p>
<p>With problems{tasks} like were defined{determined}, now let&#8217;s understand as at us all will be vygdjadet`. The form and recordings will be is deduced on one page. Our file will be called gb.php. We shall write a code of the form. At me it has turned out that:</p>
<p>&lt;form action = &#8220;gb.php&#8221; method = &#8220;post&#8221;&gt;</p>
<p>&lt;table width = &#8220;500&#8243; cellpadding = &#8220;2&#8243;</p>
<p>cellspacing = &#8220;0&#8243; style = &#8221; border: 1px solid rgb (0, 75, 151); &#8221; bgcolor = &#8221; * d7ecff &#8220;&gt;</p>
<p>&lt;tbody&gt; &lt;tr&gt;</p>
<p>&lt;td align = &#8220;right&#8221;&gt;</p>
<p>* A name:</p>
<p>&lt;/td&gt;</p>
<p>&lt;td align = &#8220;left&#8221;&gt;</p>
<p>&lt;input type = &#8220;text&#8221; name = &#8220;msg_from&#8221; maxlength = &#8220;40&#8243; size = &#8220;30&#8243;&gt;</p>
<p>&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
<p>&lt;tr&gt;</p>
<p>&lt;td align = &#8220;right&#8221;&gt;</p>
<p>E-Mail:</p>
<p>&lt;/td&gt;</p>
<p>&lt;td align = &#8220;left&#8221;&gt;</p>
<p>&lt;input type = &#8220;text&#8221; name = &#8220;msg_mail&#8221; maxlength = &#8220;40&#8243; size = &#8220;30&#8243;&gt;</p>
<p>&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
<p>&lt;tr&gt;</p>
<p>&lt;td align = &#8220;right&#8221;&gt;</p>
<p>** URL:</p>
<p>&lt;/td&gt;</p>
<p>&lt;td align = &#8220;left&#8221;&gt;</p>
<p>&lt;input type = &#8220;text&#8221; name = &#8220;msg_url&#8221; maxlength = &#8220;40&#8243; size = &#8220;30&#8243;&gt;</p>
<p>&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
<p>&lt;tr&gt;</p>
<p>&lt;td align = &#8220;right&#8221;&gt;</p>
<p>* The message:</p>
<p>&lt;/td&gt;</p>
<p>&lt;td align = &#8220;left&#8221;&gt;</p>
<p>&lt;textarea cols = &#8220;45&#8243; rows = &#8220;7&#8243; name = &#8220;msg_message&#8221;&gt; &lt;/textarea&gt;</p>
<p>&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
<p>&lt;tr&gt;</p>
<p>&lt;td align = &#8220;center&#8221; colspan = &#8220;2&#8243;&gt;</p>
<p>&lt;input type = &#8220;submit&#8221; name = &#8220;msg_submit&#8221; value = &#8220;To add&#8221;&gt;</p>
<p>&lt;input type = &#8220;reset&#8221;&gt;</p>
<p>&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
<p>&lt;tr&gt;</p>
<p>&lt;td align = &#8220;center&#8221; colspan = &#8220;2&#8243;&gt;</p>
<p>* Fields obligatory for filling &lt;br&gt;</p>
<p>** url to enter without http://</p>
<p>&lt;/td&gt;</p>
<p>&lt;/tr&gt;</p>
<p>&lt;/tbody&gt; &lt;/table&gt;</p>
<p>&lt;/form&gt;</p>
<p>Now we shall understand with the basic adjustments of our guest book:</p>
<p>//&#8212;&#8212;&#8212;-Adjustments GB&#8212;&#8212;&#8212;-//</p>
<p>$file_gb = &#8220;c:/HTTP/CoderPRO/site/gb.dat&#8221;; // a file where recordings GB are stored{kept}</p>
<p>$max_rec = 128; // a maximum quantity of recordings in a file</p>
<p>$rec_page = 6; // quantity{amount} of recordings deduced{removed} on one page</p>
<p>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-//</p>
<p>Let&#8217;s write a code of heading of our page:</p>
<p>&lt;html&gt; &lt;head&gt;</p>
<p>&lt;title..&gt;:: the Guest book::.. &lt;/title&gt;</p>
<p>&lt;meta http-equiv = &#8220;Pragma&#8221; content = &#8220;no-cache&#8221;&gt;</p>
<p>&lt;meta http-equiv = &#8220;expires&#8221; content = &#8220;0&#8243;&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body&gt;</p>
<p>&lt;div align = &#8220;center&#8221;&gt; &lt;h1&gt; the Guest book &lt;/h1&gt; &lt;/div&gt;</p>
<p>Lines with META are necessary that our page not kehshirovalas`. The first line speaks a browser, that page kehshirovat` it is not necessary, and the second &#8211; if a browser does not understand the first parameter Pragma, that a storage time of our page in a cache &#8211; 0 sek.</p>
<p>Now we shall start actually programming. For the beginning we shall write function of check of the entered data:</p>
<p>// Check of the entered data //</p>
<p>function test () {</p>
<p>global $HTTP_POST_VARS;</p>
<p>if (! isset ($HTTP_POST_VARS [' msg_from '], $HTTP_POST_VARS [' msg_mail '],</p>
<p>$HTTP_POST_VARS [' msg_url '], $HTTP_POST_VARS [' msg_message '])) {</p>
<p>echo &#8221; &lt;p align = &#8220;center&#8221;&gt; the Mistake at transfer of parameters to a script!</p>
<p>Address to the manager of a site. &lt;/p&gt; n &#8220;;</p>
<p>return (false);</p>
<p>}</p>
<p>if (trim ($HTTP_POST_VARS [' msg_from ']) == &#8221; &#8220;) {</p>
<p>echo &#8221; &lt;p align = &#8220;center&#8221;&gt; you have not entered the name. Repeat input. &lt;/p&gt; n &#8220;;</p>
<p>return (false);</p>
<p>}</p>
<p>if (trim ($HTTP_POST_VARS [' msg_message ']) == &#8221; &#8220;) {</p>
<p>echo &#8221; &lt;p align = &#8220;center&#8221;&gt; you have not entered the message. Repeat input. &lt;/p&gt; n &#8220;;</p>
<p>return (false);</p>
<p>}</p>
<p>return (true);</p>
<p>} // test ()</p>
<p>$HTTP_POST_VARS is a file containing all keys and values transferred{handed} by method POST (works at register_globals = Off). Whether all over again in function all is checked was transferred{handed}, and then whether obligatory fields the Name and the Message have been filled. Certainly, it is possible to make still check on a correctness entered e-mail and url and much that else, but it already if would be desirable you, do{make}, and we shall not be on it zamorachivat`sja and we shall go further.</p>
<p>Let&#8217;s consider as at us will be it is stored{kept} recordings in a file. In one line of a file &#8211; one recording in the following format:</p>
<p>Imja|E-Mail|URL|Data And time dobavlenija|Soobhhenie</p>
<p>Before addition of recording we should a little podredaktirovat` the data. As it is possible to notice, for division of parts of recording we use a sign |, means our data should not contain this sign &#8211; we shall replace it{him} with analogue in a html-code: *brvbar;. Further we should check up length of the message, and if she more than some size (for example more than 1000 symbols) to cut off the message till the necessary length. Then we convert all special symbols in mnemonic HTML (function htmlspecialchars). And at last, we shall replace all carries of lines to the message on &lt;br&gt; and we shall format the data in the format necessary to us for recording in a file. Certainly here again it is possible to make still a heap of everyones pribambasov, but it we shall leave for independent jobs and we shall do{make} our guestbook further. So for recording in a file we have generated a line and now she{it} should be added in a file, thus not privysiv a limit of quantity{amount} of recordings in a file (recollect adjustments of our page: $max_rec = 128;) . I write something much, and a code it is not visible: to you our function of addition of recording in a file:</p>
<p>// Function of addition of recording //</p>
<p>function add () {</p>
<p>global $max_rec;</p>
<p>global $file_gb;</p>
<p>global $HTTP_POST_VARS;</p>
<p>$recs = @file ($file_gb) or $recs = array ();</p>
<p>$from = $HTTP_POST_VARS [' msg_from '];</p>
<p>$mail = $HTTP_POST_VARS [' msg_mail '];</p>
<p>$url = $HTTP_POST_VARS [' msg_url '];</p>
<p>$message = $HTTP_POST_VARS [' msg_message '];</p>
<p>$from = str_replace (&#8220;|&#8221;, &#8221; *brvbar; &#8220;, $from);</p>
<p>$mail = str_replace (&#8220;|&#8221;, &#8221; *brvbar; &#8220;, $mail);</p>
<p>$url = str_replace (&#8220;|&#8221;, &#8221; *brvbar; &#8220;, $url);</p>
<p>if (strlen ($message)&gt; 1000) $message=substr ($message, 0,1000);</p>
<p>$message = htmlspecialchars ($message, ENT_QUOTES);</p>
<p>$message = str_replace (&#8220;|&#8221;, &#8221; *brvbar; &#8220;, $message);</p>
<p>$message = trim ($message);</p>
<p>$message = ereg_replace (&#8221;</p>
<p>&#8220;,&#8221; &lt;br&gt; &#8220;, $message);</p>
<p>array_unshift ($recs, &#8221; $from | $ mail | $ url | &#8220;.date (&#8221; d M Y, H:i &#8220;). &#8221; | $messagen &#8220;);</p>
<p>if (count ($recs)&gt; $max_rec) $recs=array_slice ($recs, 0, $max_rec);</p>
<p>$count = count ($recs);</p>
<p>$f = fopen ($file_gb, &#8220;w&#8221;);</p>
<p>for ($i=0; $i &lt;$count; $i ++) {</p>
<p>fwrite ($f, $recs [$i]);</p>
<p>}</p>
<p>fclose ($f);</p>
<p>} // add ()</p>
<p>$recs is a file with recordings. If the file $file_gb exists, with the help of function file () we appropriate{give} each line of a file to one element of a file, in an opposite case $recs &#8211; an empty file. Further there is an editing the data described above. Then with the help of function array_unshift () we add in the beginning of recordings our recording. Check on quantity{amount} of recordings further follows, and if quantity{amount} more necessary, with the help of function array_slice () we select the first elements in the quantity{amount} necessary to us. Well and, at last, we write down our recordings in a file.</p>
<p>So, for addition of recordings we have made functions, now it is necessary to make function for a paginal conclusion of the data to the screen. Basically in a conclusion of the data anything complex{difficult} no, counted recording &#8211; have deduced{removed} according to design and everything, but in fact we want to draw a conclusion paginal &#8211; in it just and there can be a complexity. So we shall start: First I shall result a code of function view (), and then we shall disassemble it{him}.</p>
<p>// Function of a conclusion of recordings //</p>
<p>function view () {</p>
<p>global $file_gb;</p>
<p>global $HTTP_GET_VARS;</p>
<p>global $rec_page;</p>
<p>if (file_exists ($file_gb)) {</p>
<p>$messages = file ($file_gb);</p>
<p>$count = count ($messages);</p>
<p>if ($count&gt; $rec_page) {</p>
<p>nav_page (ceil ($count / $ rec_page), (isset ($HTTP_GET_VARS [' page '])?</p>
<p>$HTTP_GET_VARS [' page ']: 1), &#8221; gb.php? page = &#8220;);</p>
<p>echo &#8220;&lt;br&gt;&#8221;;</p>
<p>}</p>
<p>$num_page=1;</p>
<p>if (isset ($HTTP_GET_VARS [' page '])) {</p>
<p>if (($HTTP_GET_VARS [' page ']&gt; 0) and</p>
<p>($HTTP_GET_VARS [' page '] &lt;=ceil ($count / $ rec_page)))</p>
<p>$num_page = $ HTTP_GET_VARS [' page '];</p>
<p>}</p>
<p>for ($i = ($ num_page-1) * $rec_page; $i &lt;= (($num_page * $ rec_page &lt;$count)?</p>
<p>$num_page * $ rec_page-1: $count-1); $i ++) {</p>
<p>$tmp = explode (&#8220;|&#8221;, $messages [$i]);</p>
<p>echo &#8221; &lt;table class = &#8220;text_info&#8221; border = &#8220;0&#8243; width = &#8221; 100 % &#8220;&gt; n &#8220;;</p>
<p>echo &#8221; &lt;tr class = &#8220;sel_p&#8221;&gt; n &#8220;;</p>
<p>echo &#8221; &lt;td&gt; n &#8220;;</p>
<p>echo &#8221; &lt;b&gt; From: &lt;/b&gt; &lt;br&gt; &#8220;;</p>
<p>if ($tmp [2] &lt;&gt; &#8221; &#8220;) echo &#8221; &lt;b&gt; URL: &lt;/b&gt; &lt;br&gt; &#8220;;</p>
<p>echo &#8221; &lt;b&gt; Date: &lt;/b&gt; n &#8220;;</p>
<p>echo &#8221; &lt;/td&gt; n &#8220;;</p>
<p>echo &#8221; &lt;td class = &#8220;text_info_sel&#8221; width = &#8221; 100 % &#8220;&gt; n &#8220;;</p>
<p>echo $tmp [0];</p>
<p>if ($tmp [1] &lt;&gt; &#8221; &#8220;) {echo &#8221; | &lt;a href = &#8221; mailto: &#8220;. $ tmp [1]. &#8221; &#8220;&gt; &#8220;. $tmp [1.] &#8221; &lt;/a&gt; &#8220;;}</p>
<p>echo &#8220;&lt;br&gt;&#8221;;</p>
<p>if ($tmp [2] &lt;&gt; &#8221; &#8220;) echo &#8221; &lt;a href = &#8221; http: // &#8220;. $tmp [2]. &#8221; &#8220;&gt; &#8220;. $tmp [2.] &#8221; &lt;/a&gt; &lt;br&gt; &#8220;;</p>
<p>echo $tmp [3.] &#8220;n&#8221;;</p>
<p>echo &#8221; &lt;/td&gt; n &lt;/tr&gt; n &#8220;;</p>
<p>echo &#8221; &lt;td colspan = &#8220;2&#8243;&gt; &lt;br&gt; n &#8220;;</p>
<p>echo $tmp [4];</p>
<p>echo &#8221; &lt;/td&gt; n &lt;/tr&gt; n &lt;/table&gt; n &#8220;;</p>
<p>echo &#8220;&lt;br&gt;&#8221;;</p>
<p>} // for</p>
<p>if ($count&gt; $rec_page) {nav_page (ceil ($count / $ rec_page),</p>
<p>(isset ($HTTP_GET_VARS [' page '])? $HTTP_GET_VARS [' page ']: 1), &#8221; gb.php? page = &#8220;);}</p>
<p>echo &#8220;&lt;br&gt;&#8221;;</p>
<p>} else {</p>
<p>echo &#8221; &lt;center&gt; Recordings no. You can be the first;) &lt;/center&gt; &lt;br&gt; n &#8220;;</p>
<p>}</p>
<p>} // view ()</p>
<p>Global variables: $file_gb &#8211; a file with recordings, $rec_page &#8211; deduced{removed} on one page &#8211; these variables we have defined{determined} quantity{amount} of recordings right at the beginning in adjustments of our guest book. And $HTTP_GET_VARS is a file containing all keys and values transferred{handed} by method GET, i.e. through URL (works at register_globals = Off) is to us it is required, since we shall just pass number{room} of page through URL. We shall understand, that our function does{makes}. First check is carried out &#8211; whether there is a file with recordings &#8211; and if is job on a conclusion of recordings and if there is no file the message is deduced is carried out, that recordings no. So, if it&#8217;s OK and we have file with recordings with the help of function file () we create a file of lines of a file $messages, and a variable $count appropriate{give} kol-in elements of the received file, i.e. quantity{amount} of recordings. Further goes the conclusion of navigation of pages and recordings is carried out according to the necessary page. In particular we use function nav_page, I shall result only its{her} code.</p>
<p>// Function of a conclusion of navigation on pages //</p>
<p>function nav_page (</p>
<p>$count, // the General{Common} kol-in pages</p>
<p>$num_page, // Number{Room} of the current page</p>
<p>$url // What URL for the link to page</p>
<p>// (to it{him} number{room} of page) is added</p>
<p>) {</p>
<p>$page_nav = 3; // how much pages to deduce{remove} simultaneously</p>
<p>$begin_loop=1; // initial value in a cycle</p>
<p>$end_loop = $ count; // final value in a cycle</p>
<p>echo &#8221; &lt;div align = &#8220;center&#8221;&gt; [Pages ($count): ";</p>
<p>// Check on a correctness of number{room} of the current page</p>
<p>if ($num_page&gt; $count or $num_page &lt;1) $num_page=1;</p>
<p>// Further in function there is a conclusion of navigation, all is received here by practical consideration</p>
<p>if ($num_page&gt; $page_nav) {</p>
<p>echo " &lt;a href = " $ url ". ($page_nav * (floor ($num_page / $ page_nav)-</p>
<p>($num_page % $ page_nav == 0? 1 : 0))). " "&gt; (". ($page_nav * (floor ($num_page / $ page_nav)-</p>
<p>1-($ num_page % $ page_nav == 0? 1 : 0)) +1). "-". ($page_nav * (floor ($num_page / $ page_nav)-</p>
<p>($num_page % $ page_nav == 0? 1 : 0))). ") &lt;/a...&gt; ";</p>
<p>$begin_loop = $ page_nav * (floor ($num_page / $ page_nav) - ($num_page % $ page_nav == 0? 1 : 0)) +1;</p>
<p>}</p>
<p>if ($count&gt; $page_nav * (floor ($num_page / $ page_nav) - ($num_page % $ page_nav == 0? 1 : 0) +1)) {</p>
<p>$end_loop = $ page_nav*ceil ($num_page / $ page_nav);</p>
<p>}</p>
<p>for ($i = $begin_loop; $i &lt;= $end_loop; $i ++) {</p>
<p>if ($i == $num_page) echo " *nbsp; &lt;b&gt; $i &lt;/b&gt; ";</p>
<p>else echo " *nbsp; &lt;a href = " $ url$i "&gt; $i &lt;/a&gt; ";</p>
<p>} // for</p>
<p>if ($count&gt; $page_nav * (floor ($num_page / $ page_nav) - ($num_page % $ page_nav == 0? 1 : 0) +1)) {</p>
<p>echo " *nbsp; *nbsp;... &lt;a href = " $ url ". ($page_nav*ceil ($num_page / $ page_nav) + 1).</p>
<p>" "&gt; (". ($page_nav*ceil ($num_page / $ page_nav) + 1);</p>
<p>if ($page_nav*ceil ($num_page / $ page_nav) +1 &lt;$count) {</p>
<p>echo "-". ($count &lt;= $page_nav * (ceil ($num_page / $ page_nav) +1)?</p>
<p>$count: $page_nav * (ceil ($num_page / $ page_nav) +1));</p>
<p>}</p>
<p>echo ") &lt;/a&gt; ";</p>
<p>}</p>
<p>echo " *nbsp; *nbsp;] &lt;/div&gt; n &#8220;;</p>
<p>} // nav_page ()</p>
<p>I shall not describe this piece, you can read about it in my clause{article} a paginal conclusion where all this is in detail described. Here I shall describe only how we deduce{remove} recordings. We have a cycle in which initial and final value $i &#8211; changes depending on page which we want to display. In a cycle we from an element of a file $messages [$i] create a file $tmp with the help of function explode which breaks a line into lines on borders formed{educated} by a separator |. I.e. we receive a file in which 0-th element &#8211; the Name, 1-st &#8211; e-mail, 2-nd &#8211; url, 3-rd &#8211; date and time of addition, 4-th &#8211; the message. Well and further we deduce{remove} our recording as we want.</p>
<p>We also have written all necessary functions for the guest book, remained only will write a code which to be carried out in the beginning, i.e. will choose, what function to start. He:</p>
<p>if (isset ($HTTP_POST_VARS [' msg_submit '])) {if (test ()) add ();}</p>
<p>view ();</p>
<p>I think anything complex{difficult} in him there are no also you will understand that where:)</p>
<p>All! We have written everything, that is necessary! Now collect all in a heap and receive the high-grade guest book. To collect in the following order: 1) Heading of a file, 2) Adjustments GB, 3) Functions, 4) our last written line, 5) the Form for addition, 6) a page header.</p>
<p>To whom laziness all to collect &#8211; can download available. See a file gb.zip.</p>
<p>Let&#8217;s sum up: we have written the high-grade guest book and all problems{tasks} which have put before itself have carried out. Certainly it is possible to make still a heap of any chesspieces, to write administration of the guest book and many other things, but it already a subject of other clause{article}. In general, I hope clause{article} to you it was useful. If something was not understandable, favour I ask: write on a soap &#8211; I shall necessarily answer.</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/the-guest-book-step-by-step/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generation of the image</title>
		<link>http://novices-design-courses.info/generation-of-the-image/</link>
		<comments>http://novices-design-courses.info/generation-of-the-image/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 06:53:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=50</guid>
		<description><![CDATA[The author has offered the following algorithm: the complex{difficult} image in a picture is formed with the help of beforehand prepared substrates. Then on substrates the text, by a casual font, casual the size and, naturally, the casual maintenance{contents} is deduced.
The author has offered the following algorithm: the complex{difficult} image in a picture is formed [...]]]></description>
			<content:encoded><![CDATA[<p>The author has offered the following algorithm: the complex{difficult} image in a picture is formed with the help of beforehand prepared substrates. Then on substrates the text, by a casual font, casual the size and, naturally, the casual maintenance{contents} is deduced.<span id="more-50"></span></p>
<p>The author has offered the following algorithm: the complex{difficult} image in a picture is formed with the help of beforehand prepared substrates. Then on substrates the text, by a casual font, casual the size and, naturally, the casual maintenance{contents} is deduced.</p>
<p>The basic lack of such algorithm consists that existing &#8220;substrate&#8221; can be calculated quickly. And after that to deduct from the image which is necessary for distinguishing and thus to receive a picture with the pure{clean} text. And for recognition of such text already today there is a weight of programs.</p>
<p>Our problem{task} &#8211; to make absolutely casual substrate, with the text which not that what to distinguish difficultly, it{him} to read hardly.</p>
<p>I would offer the following algorithm:</p>
<p>1. We create a substrate (for this purpose it is possible to use algorithm of construction of fractals)</p>
<p>2. We add handicapes &#8211; some casual lines, color of the body text.</p>
<p>3. We deduce{remove} the body text</p>
<p>4. The most interesting &#8211; we increase the image in rough quantity{amount} of times &#8211; for example, in 1.7, in 1.6</p>
<p>5. We reduce the image till the original sizes</p>
<p>To increase and reduce the image it is not necessary with use of smoothing, differently even the person can read the text.</p>
<p>If it seems to you that to draw a fractal too difficultly it is possible to draw a simple grid.</p>
<p>Principle of job of the mechanism</p>
<p>At call of the user on page with the form, we create session and we write down in the registered variable a casual code:</p>
<p>session_start ();</p>
<p>session_register (&#8220;secret_number&#8221;);</p>
<p>if (intval ($ _SESSION ["secret_number"]) &lt;1000) {</p>
<p>srand (doubleval (microtime));</p>
<p>$ _SESSION ["secret_number"] =rand (1000,9999);</p>
<p>}</p>
<p>After the casual text is generated, it is necessary to deduce{remove} the form:</p>
<p>&lt;form action = &#8220;index.php&#8221; method = &#8220;post&#8221;&gt;</p>
<p>Yours E-Mail: &lt;br&gt;</p>
<p>&lt;input type = &#8220;text&#8221; name = &#8220;email&#8221; value = &#8220;&#8221;&gt; &lt;br&gt;</p>
<p>&lt;br&gt;</p>
<p>Enter a code which you see in a picture: &lt;br&gt;</p>
<p>&lt;input type = &#8220;text&#8221; name = &#8220;secretcode&#8221; value = &#8220;&#8221;&gt; &lt;br&gt;</p>
<p>&lt;img src =&#8217;code.php? &lt;? =doubleval (microtime ());?&gt; &#8216;</p>
<p>width=101 height=26 vspace=5&gt;</p>
<p>&lt;br&gt; &lt;br&gt;</p>
<p>&lt;input type = &#8220;submit&#8221;&gt;</p>
<p>&lt;/form&gt;</p>
<p>The script processing the data, sent by means of the form, should work approximately as follows:</p>
<p>session_start ();</p>
<p>session_register (&#8220;secret_number&#8221;);</p>
<p>if ($ _SERVER ["REQUEST_METHOD"] == &#8220;POST&#8221;) {</p>
<p>$error=0;</p>
<p>if ($ _POST ["secretcode"]! = $ _SESSION ["secret_number"] ||</p>
<p>intval ($ _POST ["secretcode"]) == 0) $error=1;</p>
<p>if ($error == 0) {</p>
<p>$ _SESSION ["secret_number"] =rand (1000,9999);</p>
<p>// We carry out necessary actions with the data</p>
<p>//.</p>
<p>print &#8220;Hello&#8221; .htmlspecialchars (StripSlashes ($ _POST ["email"]));</p>
<p>exit;</p>
<p>}</p>
<p>if ($error == 1)</p>
<p>print &#8221; &lt;font color=red&gt; the Number from a picture is entered incorrectly &lt;/font&gt; &#8220;;</p>
<p>}</p>
<p>// We deduce{remove} the form repeatedly</p>
<p>//..</p>
<p>Generation of the image</p>
<p>&lt;?</p>
<p>// We register a variable</p>
<p>session_start ();</p>
<p>session_register (&#8220;secret_number&#8221;);</p>
<p>function mt () {</p>
<p>list ($usec, $sec) = explode (&#8216; &#8216;, microtime ());</p>
<p>return (float) $sec + ((float) $usec * 100000);</p>
<p>}</p>
<p>header (&#8221; Content-type: image/png &#8220;);</p>
<p>// We create the image</p>
<p>$im=imagecreate (101, 26);</p>
<p>// We select color of a background (white)</p>
<p>$w=imagecolorallocate ($im, 255, 255, 255);</p>
<p>// We select color for a background (light grey)</p>
<p>$g1=imagecolorallocate ($im, 192, 192, 192);</p>
<p>// We select color for more dark handicapes (dark grey)</p>
<p>$g2=imagecolorallocate ($im, 64,64,64);</p>
<p>// We select four casual dark colors for symbols</p>
<p>$cl1=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));</p>
<p>$cl2=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));</p>
<p>$cl3=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));</p>
<p>$cl4=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));</p>
<p>// We draw a grid</p>
<p>for ($i=0; $i &lt;=100; $i + = 5) imageline ($im, $i, 0, $i, 25, $g1);</p>
<p>for ($i=0; $i &lt;=25; $i + = 5) imageline ($im, 0, $i, 100, $i, $g1);</p>
<p>// We deduce{remove} each figure separately, it is a little displacing casual image</p>
<p>imagestring ($im, 5, 0+rand (0,10), 5+rand (-5,5),</p>
<p>substr ($ _SESSION ["secret_number"], 0,1), $cl1);</p>
<p>imagestring ($im, 5, 25+rand (-10,10), 5+rand (-5,5),</p>
<p>substr ($ _SESSION ["secret_number"], 1,1), $cl2);</p>
<p>imagestring ($im, 5, 50+rand (-10,10), 5+rand (-5,5),</p>
<p>substr ($ _SESSION ["secret_number"], 2,1), $cl3);</p>
<p>imagestring ($im, 5, 75+rand (-10,10), 5+rand (-5,5),</p>
<p>substr ($ _SESSION ["secret_number"], 3,1), $cl4);</p>
<p>// We deduce{remove} a pair of casual lines of close color, it is direct atop of symbols.</p>
<p>// For increase in quantity{amount} of lines it is possible to increase,</p>
<p>// Having changed number selected with red color</p>
<p>for ($i=0; $i &lt;8; $i ++)</p>
<p>imageline ($im, rand (0,100), rand (0,25), rand (0,100), rand (0,25), $g2);</p>
<p>// Factor of increase / reduction of a picture</p>
<p>$k=1.7;</p>
<p>// We create the new image, the increased size</p>
<p>$im1=imagecreatetruecolor (101 * $ k, 26 * $ k);</p>
<p>// We copy the image with change of the sizes in the big party{side}</p>
<p>imagecopyresized ($im1, $im, 0, 0, 0, 0, 101 * $ k, 26 * $ k, 101, 26);</p>
<p>// We create the new image, the normal size</p>
<p>$im2=imagecreatetruecolor (101,26);</p>
<p>// We copy the image with change of the sizes in the smaller party{side}</p>
<p>imagecopyresampled ($im2, $im1, 0, 0, 0, 0, 101, 26, 101 * $ k, 26 * $ k);</p>
<p>// We generate the image</p>
<p>imagepng ($im2);</p>
<p>// We release{exempt} memory</p>
<p>imagedestroy ($im2);</p>
<p>imagedestroy ($im1);</p>
<p>imagedestroy ($im);</p>
<p>?&gt;</p>
<p>Like all. If something, leave comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/generation-of-the-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>21 mistake of programmer PHP</title>
		<link>http://novices-design-courses.info/21-mistake-of-programmer-php/</link>
		<comments>http://novices-design-courses.info/21-mistake-of-programmer-php/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 06:48:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=41</guid>
		<description><![CDATA[This series of clauses{articles} is intended for those programmers in language PHP which want to avoid most the general{common} mistakes in a spelling of a code. The reader, at least, should know general{common} syntax PHP, and also some experience of use of language in practice is rather desirable.
This series of clauses{articles} is intended for those [...]]]></description>
			<content:encoded><![CDATA[<p>This series of clauses{articles} is intended for those programmers in language PHP which want to avoid most the general{common} mistakes in a spelling of a code. The reader, at least, should know general{common} syntax PHP, and also some experience of use of language in practice is rather desirable.<span id="more-41"></span></p>
<p>This series of clauses{articles} is intended for those programmers in language PHP which want to avoid most the general{common} mistakes in a spelling of a code. The reader, at least, should know general{common} syntax PHP, and also some experience of use of language in practice is rather desirable.</p>
<p>Introduction</p>
<p>One of most strengths PHP is, simultaneously, and his{its} weakness: PHP it is very simple in studying. It involves many people; however, despite of his{its} seeming simplicity, not so simply to learn to use this language correctly and effectively.</p>
<p>As a rule, put in insufficient practice of programming. Inexperienced programmers become before the person of necessity of creation of complex{difficult} webs &#8211; applications. Therefore mistakes of which would be avoided by the skilled programmer, such as unreasonable use of function printf () or misuse of semantics PHP are pretty often supposed.</p>
<p>In this series from three clauses{articles} characteristic mistakes are submitted most, in our opinion. These mistakes can be classified on several categories, from &lt;noncritical&gt; up to &lt;fatal&gt;. Alongside with the analysis of these mistakes, ways of their avoidance, and also the some people &lt;small cunnings&gt;, saved up for many years of practice of programming are submitted.</p>
<p>Part 1: 7 &lt;children&#8217;s&gt; mistakes (¹ 21-15 Are described, upside-down, according to a degree of gravity on our classification). Such mistakes do not cause serious problems, but result in reduction of an overall performance of the program, and also are expressed in bulky trudnochitaemom a code in which, besides, it is difficult to make changes.</p>
<p>Part 2: the Following of 7 mistakes (¹ 14-8) concern to &lt;serious&gt;. They conduct to even more significant reduction of speed of performance of a code, reduction of safety of scripts; the code becomes even more confusing.</p>
<p>Part 3: Descriptions seven, last, &lt;fatal&gt; mistakes. These mistakes are conceptual by the nature and are the reason of occurrence of the mistakes described in 1-st and 2-nd parts of clause{article}. They include also such mistakes, as insufficient the attention, given both to the project as a whole, and to a code of the program, in particular.</p>
<p>21. Unjustified use of function printf ()</p>
<p>Function printf () is intended for a conclusion of the formatted data.</p>
<p>For example, she{it} should be used if necessary a conclusion of a variable in a format from a floating point with the certain accuracy, or in any other case when there is a necessity of change of a format of the deduced{removed} data.</p>
<p>The example of the proved application of function printf () is below resulted. In this case she is used for the formatted conclusion of number &lt;pi&gt;:</p>
<p>&lt;? php</p>
<p>printf (&#8221; Number Pi: %2fn &lt;br&gt; n &#8220;, M_PI);</p>
<p>printf (&#8221; It too number Pi: %3fn &lt;br&gt; n &#8220;, M_PI;</p>
<p>printf (&#8221; And it Pi: %4fn &lt;br&gt; n &#8220;, M_PI);</p>
<p>?&gt;</p>
<p>The note: cases of pathological fear of function printf () when people write the functions of the formatted conclusion, at times till 30-40 lines Are observed, though the unique call of function printf could solve all problems ().</p>
<p>Many programmers use function printf () for a conclusion of variables, results of a call of functions, and sometimes even the usual text data. Most often it occurs in the following two cases:</p>
<p>* When it was necessary to use function print ();</p>
<p>* At a conclusion of the results returned by functions.</p>
<p>When it is necessary to use print ()</p>
<p>The call of function printf () is frequently used there, where it was necessary to use print (). In the following example function printf () is used for a conclusion of four variables:</p>
<p>&lt;? php</p>
<p>$name = &#8216; Sterling Hughes&#8217;;</p>
<p>$job = &#8216; Senior Engineer &#8216;;</p>
<p>$company = &#8216; DesignMultimedia &#8216;;</p>
<p>$email = &#8216; shughes@designmultimedia.com &#8216;;</p>
<p>printf (&#8221; My name is %sn &lt;br&gt; n</p>
<p>I work %s, %sn &lt;br&gt; n</p>
<p>My E-mail address: % sn &lt;br&gt; n &#8220;,</p>
<p>$name, $job, $company, $email);</p>
<p>?&gt;</p>
<p>In this case it is possible (and it is desirable!) application print ():</p>
<p>print &#8221; My name is $namen &lt;br&gt; n</p>
<p>I work in $company, $jobn &lt;br&gt; n</p>
<p>My E-mail address: $emailn &lt;br&gt; n &#8220;;</p>
<p>Use print () instead of printf () in cases when the unformatted data as in the given example, gives the following benefits are deduced:</p>
<p>* Increase in productivity: Function printf () formats the arguments before a conclusion. Thus, time of its{her} performance is more, than for functions print () or echo ().</p>
<p>* Clearer code: All the same, it is necessary to recognize, that use of function printf () is complicated with reading a code (having sufficient experience of programming on C, it, certainly, concerns to a lesser degree). That function printf () has not led the most unexpected for you in the image, need as knowledge of syntax of the given function, (i.e. %s defines{determines} a line format of a conclusion whereas %d &#8211; decimal), and knowledge of types of variables.</p>
<p>Use of function printf () for a conclusion of the value returned by function</p>
<p>One more characteristic mistake of use of function printf () &#8211; a conclusion of the value returned by function, as in the following example:</p>
<p>&lt;? php</p>
<p>printf (&#8221; It is found %d ocurrences of a line %s &#8220;, count ($result), $search_term);</p>
<p>?&gt;</p>
<p>Alongside with function print (), at its{her} use in the same purposes, it is necessary to use the operator &#8216;. &#8216; In this case this operator adds the text to result of a call of function:</p>
<p>&lt;? php</p>
<p>print &#8220;is found&#8221;.</p>
<p>count ($result).</p>
<p>&#8221; Ocurrences of a line $search_term &#8220;;</p>
<p>?&gt;</p>
<p>Use of the operator. In pair with function print () allows to avoid use of slower function printf ().</p>
<p>20. Incorrect application of semantics of language</p>
<p>Many programmers use in job PHP, actually not understanding subtleties of this language. One of subtleties &#8211; a difference between syntax and semantics PHP.</p>
<p>* Syntax PHP:Predstavljaet itself corrected a set for definition of elements of language. For example, how we determine a variable? We put a sign $ before its{her} name. How we determine function? Generally, using brackets, arguments, etc.</p>
<p>* Semantics PHP: Represents a set corrected for application of syntax. For example, we shall take function with two arguments that is defined{determined} by its{her} syntax. And as arguments she should be passed variables of line type? Is it is defined{determined} by semantics.</p>
<p>Notice: &lt;follows&gt;. In languages with clear split of types (such as Java or C) no concept &lt;follows&gt; (generally though there are also exceptions). In that case the compiler will compel to use variables of strictly certain type.</p>
<p>Languages in which there is no definition of types of variables, give more flexibility in a spelling of a code. But, anyway, in case of misuse of semantics for the majority of functions PHP it is necessary to expect occurrence of the message on a mistake.</p>
<p>Let&#8217;s take a piece of a code which opens a file and deduces it{him} postrochno:</p>
<p>&lt;? php</p>
<p>$fp = @fopen (&#8216; somefile.txt &#8216;,&#8217; r &#8216;)</p>
<p>or die (&#8216; I can not open a file somefile.txt &#8216;);</p>
<p>while ($line = @fgets (&#8220;$fp&#8221;, 1024)) // Here a mistake!</p>
<p>{</p>
<p>print $line;</p>
<p>}</p>
<p>@fclose (&#8220;$fp&#8221;) // Here again too color</p>
<p>or die (&#8216; I can not close a file somefile.txt &#8216;);</p>
<p>?&gt;</p>
<p>In this case the message on a mistake of type will appear:</p>
<p>&#8221; Warning: Supplied argument is not a valid File-Handle resource in tst.php on line 4 &#8221;</p>
<p>(&#8221; Attention: the argument cannot be a descriptor of a file &#8220;)</p>
<p>It is called by that, that the variable $fp is made in double inverted commas, that unequivocally defines{determines} her{it} as a line, whereas function fopen () expects as the first argument a descriptor, but not a line. Accordingly, you should use a variable which can contain a descriptor.</p>
<p>The note: In this case, the line type is allowable sintaksicheski.</p>
<p>For the decision of a problem it is necessary to clean{remove} double inverted commas simply:</p>
<p>&lt;? php</p>
<p>$fp = @fopen (&#8216; somefile.txt &#8216;,&#8217; r &#8216;)</p>
<p>or die (&#8216; I can not open a file somefile.txt &#8216;);</p>
<p>while ($line = @fgets ($fp, 1024))</p>
<p>{</p>
<p>print $line;</p>
<p>}</p>
<p>@fclose ($fp)</p>
<p>or die (&#8216; I can not close a file somefile.txt &#8216;);</p>
<p>?&gt;</p>
<p>How to avoid the wrong application of semantics?</p>
<p>In the resulted example the message on a mistake is generated. But PHP gives the programmer of more freedom, than other, traditional programming languages. It allows to receive interesting results. At least, it is theoretically possible to write a correct code, incorrectly using semantics of language.</p>
<p>But be cautious, making advances to semantics of language! Occurrence of hardly perceptible mistakes in programs is possible. If all of you-taki have decided to experiment, you should understand three key moments:</p>
<p>* Types: In PHP each variable at any moment concerns to the certain type. And despite of that fact, that its{her} type it is possible to change it freely. In other words, in language PHP the variable cannot exist, thus not concerning to the certain type (and, accordingly, not possessing the characteristics, inherent in this type). In PHP there are 7 basic types of variables: Boolean, resource, integer, double, string, array and object.</p>
<p>* Area of visibility: In PHP variables have area of visibility which defines{determines} that, whence she can be accessible, and as far as will exist for a long time. Nedoponimanie concepts &lt;areas of visibility&gt; it can be shown as a various sort of &lt;floating&gt; mistakes.</p>
<p>* php.ini: At a spelling of a code it is necessary to understand, what not all users have the same configuration of hardware-software means, as well as you. Thus, it is completely necessary to be convinced once again, whether serviceability of your code in that configuration in which the program should work is saved, instead of in in what it was developed.</p>
<p>19. There is not enough or too much kommentirovannyj the text</p>
<p>Badly documentary text of the program is an attribute ehgoistichnogo the programmer. Result of attempt of the analysis of your program with the purpose of entering improvements will be only a headache. And all programmers count the self-documentary code a good form, but extremely seldom write comments.</p>
<p>It is necessary to avoid superfluous comments also. It too meets very seldom, and, besides, creates difficultly readable initial code. The following example illustrates it:</p>
<p>&lt;? php // the Beginning of a code</p>
<p>$age = 18; // the Age is equal 18</p>
<p>$age ++; // we Shall increase $age by one year</p>
<p>// We shall print a greeting</p>
<p>print &#8221; to you now 19 years, and it means, that to you already was: &#8220;;</p>
<p>print &#8221; n &lt;br&gt; n &lt;br&gt; n &#8220;;</p>
<p>// A cycle &#8216; for &#8216; to deduce{remove} all</p>
<p>// The previous values of age</p>
<p>for ($idx = 0; $idx &lt;$age; $idx ++)</p>
<p>{</p>
<p>// We shall print each value of age</p>
<p>print &#8221; $idx letn &lt;br&gt; n &#8220;;</p>
<p>}</p>
<p>// The end of a code</p>
<p>?&gt;</p>
<p>And nevertheless: where a golden mean?</p>
<p>So, what volume of comments should be placed in a script?! It depends on much: from time which you have, from politics of the company, complexity of the project, etc. Nevertheless, remember some main principles which should be followed at a spelling of programs without dependence from your decision:</p>
<p>* Before a body of function always place the comment &#8211; purpose{appointment} of function.</p>
<p>* Add comments in doubtful sites of a code, when there is no confidence, that he will work as it is necessary.</p>
<p>* If purpose{appointment} of a code unevidently, bring in the information on applicability of this site. You then will use this comment.</p>
<p>* Avoid comments of a kind * &#8211; use only/* */or //.</p>
<p>The following example illustrates good style of comments:</p>
<p>&lt;? php</p>
<p>// Random_Numbers.lib</p>
<p>// Generation of random numbers of various type</p>
<p>mt_srand ((double) microtime () *1000000);</p>
<p>//</p>
<p>// mixed random_element (array $elements [, array weights])</p>
<p>// Returns a stochastic element of file &#8211; argument</p>
<p>// The file weights contains relative probabilities</p>
<p>// Samples of elements</p>
<p>//</p>
<p>function random_element ($elements, $weights = array ())</p>
<p>{</p>
<p>// For correct functioning this algorithm</p>
<p>// The quantity{amount} of elements of a file should be equal</p>
<p>// To quantity{amount} of elements of a file of relative probabilities</p>
<p>if (count ($weights) == count ($elements)) {</p>
<p>foreach ($elements as $element) {</p>
<p>foreach ($weights as $idx) {</p>
<p>// The note: we do not use $idx, because</p>
<p>// Access to separate elements is not necessary for us</p>
<p>// A file weights</p>
<p>$randomAr [] = $element;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>else {</p>
<p>$randomAr = $elements;</p>
<p>}</p>
<p>$random_element = mt_rand (0, count ($randomAr) &#8211; 1);</p>
<p>return $randomAr [$random_element];</p>
<p>}</p>
<p>?&gt;</p>
<p>18. It is too much variables &#8211; too big execution time</p>
<p>The some people directly suffer obsession to enter time variables where it is necessary and where it is not necessary. It is completely impossible to understand, than the person written such code was guided:</p>
<p>&lt;? php</p>
<p>$tmp = date (&#8221; F d, h:i a &#8220;); // i.e. a format of date February 23, 2:30 pm</p>
<p>print $tmp;</p>
<p>?&gt;</p>
<p>For what the time variable here is used?! She simply is not necessary:</p>
<p>&lt;? php</p>
<p>print date (&#8221; F d, h:i a &#8220;);</p>
<p>?&gt;</p>
<p>Unfortunately, many programmers cannot get rid of this bad habit in any way. Use of time variables slows down performance of the program. For increase in speed of a code where it is possible, it is better to use an investment of functions. Use of time variables frequently increase execution time of scripts almost by a quarter.</p>
<p>One more reason on which it is necessary to avoid use of excessive quantity{amount} of time variables, this deterioration of readership of a code. Compare two resulted examples. What from them looks more elegantly &#8211; with use of a time variable or without? What code is easier for reading? Use of superfluous time variables conducts to a spelling of less readable and clear code.</p>
<p>Pluss of use of time variables</p>
<p>Introduction of time variables allows to simplify some complex{difficult} expressions or calls of functions. Still they benefit, when allow to avoid a repeated call of function with the same arguments.</p>
<p>Example in which it is not used superfluous variables:</p>
<p>&lt;? php</p>
<p>// string reverse_characters (string str)</p>
<p>// Overturns a line of symbols</p>
<p>function reverse_characters ($str)</p>
<p>{</p>
<p>return implode (&#8221; &#8220;, array_reverse (preg_split (&#8220;//&#8221;, $str)));</p>
<p>}</p>
<p>?&gt;</p>
<p>To call of function implode () as one of parameters it is passed the result of performance of the enclosed functions, therefore such code is difficult for reading. In this case to us can use of a time variable is healthy to help:</p>
<p>&lt;? php</p>
<p>// string reverse_characters (string str)</p>
<p>// Overturns a line of symbols</p>
<p>function reverse_characters ($str)</p>
<p>{</p>
<p>$characters = preg_split (&#8220;//&#8221;, $str);</p>
<p>$characters = array_reverse ($characters);</p>
<p>return implode (&#8221; &#8220;, $characters);</p>
<p>}</p>
<p>?&gt;</p>
<p>Gold rule</p>
<p>If you think, to enter whether or not one more time variable, set to yourself two questions:</p>
<p>* Whether this variable will be used even twice?</p>
<p>* Whether readership of a code will considerably improve with its{her} introduction?</p>
<p>If you have answered any of these questions &lt;yes&gt; then enter a time variable. Otherwise combine calls of functions (if it is necessary) and do without its{her} use.</p>
<p>17. We copy standard functions</p>
<p>Someone recommends to rename standard functions that on Visual Basic&#8217;? it was easier to programmers to proceed{pass} to use of language PHP:</p>
<p>&lt;? php</p>
<p>function len ($str) {</p>
<p>return strlen ($str);</p>
<p>}</p>
<p>?&gt;</p>
<p>There are also recommendations, starting programming on PHP, first of all to replace names of the built &#8211; in functions with more habitual.</p>
<p>There are, at least, two reasons of it to not do{make}. First and first of all, we receive less readable code. People reading your code, will see weight of obviously unnecessary functions and will be strongly surprised, why you did not use standard functions PHP.</p>
<p>Well and, at last, it slows down the program. Business not only in necessity of processing of great volume of a code, but also that for a call of such user function, is required to more time, than for a direct call of standard function.</p>
<p>Use standard functions of language!</p>
<p>Sometimes so it is difficult to resist{stand}! In fact the programmer seldom knows at once all set of functions &#8211; he{it} usually does not have time to remember them all. Why simply to not rename function? But, we shall be repeated, it is not necessary to do{make} it by virtue of the reasons stated above.</p>
<p>Well to have near at hand the directory on functions PHP (it is convenient to use the indexed version in format PDF). And before writing any function, closely{attentively} to see &#8211; whether there is she already in the list of standard functions.</p>
<p>But it is necessary to notice, that in codes of programs it is possible to meet the user functions written still{even} before their introduction as standard (for example, functions of comparison of two files). It does not mean, that you necessarily should copy a code and replace with their standard functions.</p>
<p>16. The client part of the program is not separated from a server part</p>
<p>Many programmers recommend to unite code HTML (interpretive on the party{side} of the client) and code PHP (carried out by the server) in one big file.</p>
<p>For small sites it, probably, not bad. But, when your site will start to grow, you can face problems if necessary to add any new functions. Such style of programming results in very &lt;disobedient&gt; and bulky code.</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/21-mistake-of-programmer-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to protect a site from total uploading.</title>
		<link>http://novices-design-courses.info/how-to-protect-a-site-from-total-uploading/</link>
		<comments>http://novices-design-courses.info/how-to-protect-a-site-from-total-uploading/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 06:47:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=39</guid>
		<description><![CDATA[There are such cases when the owner of a site does not wish, or cannot, give the site entirely to the visitors. We shall result a simple example:There are such cases when the owner of a site does not wish, or cannot, give the site entirely to the visitors. We shall result a simple example:
You [...]]]></description>
			<content:encoded><![CDATA[<p>There are such cases when the owner of a site does not wish, or cannot, give the site entirely to the visitors. We shall result a simple example:<span id="more-39"></span>There are such cases when the owner of a site does not wish, or cannot, give the site entirely to the visitors. We shall result a simple example:</p>
<p>You have site on which, you publish wall-paper for a desktop. Total amount of a site &#8211; 500Mb, attendance of 7000 hosts in day, the provisional traffic &#8211; 300Gb in a month or 10 Gb in day.</p>
<p>Let&#8217;s add to these visitors 20 more person, downloaded your site entirely. We receive increase in the traffic on 10Gb either twice. Or in other words 0.28 % of visitors have created 50 % of the traffic. Not absolutely fairly, especially if you pay the traffic.</p>
<p>Ways of protection of a site from uploading</p>
<p>1. An interdiction on User Agent</p>
<p>User Agent &#8211; so the data which each browser passes the server are called. These data the operational system, the list of plug-ins and many other things can comprise such information, as type of a browser.</p>
<p>It is the most simple, but the least effective way. His{its} advantage that whom superfluous you do not forbid, and lack that practical everyone Download the agent can mask under standard browsers.</p>
<p>Example:</p>
<p>$agent = &#8221; &#8220;. $HTTP_USER_AGENT;</p>
<p>if (strpos ($agent, &#8221; DISCo Pump &#8220;) ||</p>
<p>strpos ($agent, &#8221; Offline Explorer &#8220;) ||</p>
<p>strpos ($agent, &#8220;Teleport&#8221;) ||</p>
<p>strpos ($agent, &#8220;WebZIP&#8221;) ||</p>
<p>strpos ($agent, &#8220;WebCopier&#8221;) ||</p>
<p>strpos ($agent, &#8220;Wget&#8221;) ||</p>
<p>strpos ($agent, &#8220;FlashGet&#8221;) ||</p>
<p>strpos ($agent, &#8221; CIS TE &#8220;) ||</p>
<p>strpos ($agent, &#8221; DTS Agent &#8220;) ||</p>
<p>strpos ($agent, &#8220;WebReaper&#8221;) ||</p>
<p>strpos ($agent, &#8220;HTTrack&#8221;) ||</p>
<p>strpos ($agent, &#8221; Web Downloader &#8220;)) {</p>
<p>die (&#8221; Access Denied &#8220;);</p>
<p>}</p>
<p>2. Restriction by quantity{amount} of the seen{overlooked} pages for the certain time interval.</p>
<p>Too disputable enough method. But it is necessary to understand, that the normal person cannot see{overlook} 60 pages for 1 minute. But on the other hand and Download the agent can do{make} pauses between uploading of pages.</p>
<p>Even if you will not block Download the agent absolutely then, strongly complicate uploading.</p>
<p>3. An interdiction with the help of the latent link.</p>
<p>Probably, one of the most correct methods. You should make the latent link to page, on which &#8220;alive&#8221; person will not pass, and Download the agent and other robots will make it. IP the address with which is made viewing the latent page blocked, say, for 3 minutes.</p>
<p>The main lack is that you, thus, block search robots. To struggle with it it is possible in two ways:</p>
<p>* To check $HTTP_USER_AGENT. For this purpose it will be necessary for you to know how all search robots subscribe. Besides at such way Download the agent can mask under the search robot. (see an example 2)</p>
<p>* To forbid IP the address it is possible not on the fact of loading of the latent page, and on the fact of loading of the picture established on latent page. Search robots usually do not request the image placed on pages, and Download agents usually do{make} it.</p>
<p>Conclusions.</p>
<p>As you can see, a method which would work for hundred percent{interests}, no, and it is necessary to you something (or someone) to sacrifice. Code PHP of a class which realizes protection against the uploading, described in the third method is below resulted.</p>
<p>Example PHP of a class</p>
<p>flooders.inc.php:</p>
<p>&lt;?</p>
<p>class Flooders {</p>
<p>var $filename;/* the Name of a file in which the list */is stored{kept}</p>
<p>/* Forbidden IP */addresses</p>
<p>var $timeout;/* Time on which it is made ban IP */</p>
<p>/* Addresses. By default &#8211; 600 (10 minutes) */</p>
<p>var $log;/* the Name of a broad gully &#8211; file. */</p>
<p>var $AGENTS;/* the File &#8211; the list of the resolved{allowed} agents */</p>
<p>/* */</p>
<p>/* The designer &#8211; in parameters it is possible to specify the basic adjustments */</p>
<p>/* */</p>
<p>/* $filename &#8211; a name of a file in which the list */is stored{kept}</p>
<p>/* zabanennykh addresses. */</p>
<p>/* $timeout &#8211; time, in seconds, on which banitsja IP. */</p>
<p>/* */</p>
<p>/* An example: $f=new Flooders (&#8220;ban.txt&#8221;, 3600); */</p>
<p>/* */</p>
<p>function Flooders ($filename = &#8220;flooders.txt&#8221;, $timeout=600) {</p>
<p>$this-&gt; filename = $ filename;</p>
<p>$this-&gt; timeout = $ timeout;</p>
<p>$this-&gt; AGENTS=Array ();</p>
<p>$this-&gt; log = &#8220;&#8221;;</p>
<p>}</p>
<p>/* */</p>
<p>/* Sets a name of a broad gully &#8211; file. If a name of a file empty, a broad gully &#8211; file */</p>
<p>/* Not ispol`hhuetsja */</p>
<p>/* */</p>
<p>function SetLogFileName ($filename) {</p>
<p>$this-&gt; log = $ filename;</p>
<p>}</p>
<p>/* */</p>
<p>/* Check IP of the address on a presence{finding} in a ban-sheet. */</p>
<p>/* */</p>
<p>/* If $http_errror == 0 returns true if IP */address</p>
<p>/* zabanen, and false if IP the address is resolved{allowed}. */</p>
<p>/* */</p>
<p>/* If $http_error == 404 and IP zabanen address it is deduced */</p>
<p>/* Standard page 404 of Apache */server</p>
<p>/* */</p>
<p>/* If $http_error == 403 and IP zabanen address it is deduced */</p>
<p>/* Standard page 403 of Apache */server</p>
<p>/* */</p>
<p>function Check ($http_error=0) {</p>
<p>GLOBAL $HTTP_SERVER_VARS;</p>
<p>$ip1 = $ HTTP_SERVER_VARS ["REMOTE_ADDR"];</p>
<p>$ip2 = $ HTTP_SERVER_VARS ["HTTP_X_FORWARDED_FOR"];</p>
<p>$ip1=str_replace (&#8220;:&#8221;, &#8220;_&#8221;, $ip1);</p>
<p>$ip2=str_replace (&#8220;:&#8221;, &#8220;_&#8221;, $ip2);</p>
<p>$curtime=time ();</p>
<p>$d = file ($this-&gt; filename);</p>
<p>if (! is_array ($d)) {print &#8221; the Mistake of reading from a file *quot; &#8220;. $this-&gt; filename. &#8221; and quot;. &#8220;; return (false);}</p>
<p>$found=false;</p>
<p>for ($i=0; $i &lt;count ($d); $i ++) {</p>
<p>$e=explode (&#8220;:&#8221;, $d [$i]);</p>
<p>if ($e [1] == $ip1 ** trim ($e [2]) == $ip2 ** $e [0] + $this-&gt; timeout&gt; $curtime) {$found=true; break;}</p>
<p>}</p>
<p>if ($http_error == 404 ** $found == true) {</p>
<p>header (&#8221; HTTP/1.0 404 Not Found &#8220;);</p>
<p>die (&#8221; &lt;! DOCTYPE HTML PUBLIC &#8221; &#8211; // IETF // DTD HTML 2.0 // EN &#8220;&gt; n &lt;HTML&gt; &lt;HEAD&gt; n &lt;TITLE&gt; 404 Not Found &lt;/TITLE&gt; n &lt;/HEAD&gt; &lt;BODY&gt; n &lt;H1&gt; Not Found &lt;/H1&gt; nThe requested URL &#8220;. $HTTP_SERVER_VARS ["REQUEST_URI."] &#8221; was not found on this server. &lt;P&gt; n &lt;HR&gt; n &#8220;. $HTTP_SERVER_VARS ["SERVER_SIGNATURE."] &#8221; n &lt;/BODY&gt; &lt;/HTML&gt; &#8220;);</p>
<p>}</p>
<p>if ($http_error == 403 ** $found == true) {</p>
<p>header (&#8221; HTTP/1.0 403 Forbidden &#8220;);</p>
<p>die (&#8221; &lt;! DOCTYPE HTML PUBLIC &#8221; &#8211; // IETF // DTD HTML 2.0 // EN &#8220;&gt; n &lt;HTML&gt; &lt;HEAD&gt; n &lt;TITLE&gt; 403 Forbidden &lt;/TITLE&gt; n &lt;/HEAD&gt; &lt;BODY&gt; n &lt;H1&gt; Forbidden &lt;/H1&gt; nYou do not have permission to access &#8220;. $HTTP_SERVER_VARS ["REQUEST_URI."] &#8221; non this server. &lt;P&gt; n &lt;HR&gt; n &#8220;. $HTTP_SERVER_VARS ["SERVER_SIGNATURE."] &#8221; n &lt;/BODY&gt; &lt;/HTML&gt; &#8220;);</p>
<p>}</p>
<p>return ($found);</p>
<p>}</p>
<p>/* */</p>
<p>/* Additions IP of the address in a ban-sheet */</p>
<p>/* */</p>
<p>function Ban () {</p>
<p>GLOBAL $HTTP_SERVER_VARS;</p>
<p>$agent = &#8221; &#8220;. $HTTP_SERVER_VARS ["HTTP_USER_AGENT"];</p>
<p>for ($i=0; $i &lt;count ($this-&gt; AGENTS); $i ++) {</p>
<p>if (strpos ($agent, $this-&gt; AGENTS [$i])) return;</p>
<p>}</p>
<p>$ip1 = $ HTTP_SERVER_VARS ["REMOTE_ADDR"];</p>
<p>$ip2 = $ HTTP_SERVER_VARS ["HTTP_X_FORWARDED_FOR"];</p>
<p>$ip1=str_replace (&#8220;:&#8221;, &#8220;_&#8221;, $ip1);</p>
<p>$ip2=str_replace (&#8220;:&#8221;, &#8220;_&#8221;, $ip2);</p>
<p>$curtime=time ();</p>
<p>$d = file ($this-&gt; filename);</p>
<p>if (! is_array ($d)) {print &#8221; the Mistake of reading from a file *quot; &#8220;. $this-&gt; filename. &#8221; and quot;. &#8220;;}</p>
<p>for ($i=0; $i &lt;count ($d); $i ++) {</p>
<p>$e=explode (&#8220;:&#8221;, $d [$i]);</p>
<p>if ($e [1] == $ip1 ** trim ($e [2]) == $ip2) unset ($d [$i]);</p>
<p>}</p>
<p>if (need_add) {</p>
<p>if (! empty ($this-&gt; log)) {</p>
<p>$fw=fopen ($this-&gt; log, &#8220;at&#8221;);</p>
<p>if ($fw) {</p>
<p>fputs ($fw, date (&#8221; Y-m-d H:i:s &#8220;) &#8220;. [". $ip1. "|". $ ip2. "]&#8220;. $ agent. &#8220;n&#8221;);</p>
<p>fclose ($fw);</p>
<p>}</p>
<p>}</p>
<p>$d [] = $curtime. &#8220;:&#8221;. $ip1. &#8220;:&#8221;. $ip2. &#8220;n&#8221;;</p>
<p>}</p>
<p>$fw = fopen ($this-&gt; filename, &#8220;wt&#8221;);</p>
<p>if (! $fw) {print &#8221; the Mistake of recording in a file *quot; &#8220;. $this-&gt; filename. &#8221; and quot;. &#8220;; return;}</p>
<p>foreach ($d as $e) fputs ($fw, $e);</p>
<p>fclose ($fw);</p>
<p>}</p>
<p>function AddAlowAgent ($agent) {</p>
<p>$this-&gt; AGENTS [] = $agent;</p>
<p>}</p>
<p>}</p>
<p>?&gt;</p>
<p>Examples of use</p>
<p>Example 1</p>
<p>This code should be established on the latent page:</p>
<p>&lt;?</p>
<p>include &#8220;flooders.inc.php&#8221;;</p>
<p>$f=new Flooders ();</p>
<p>$f-&gt; Ban ();</p>
<p>?&gt;</p>
<p>This code should be established in the top part of all pages of a site:</p>
<p>&lt;?</p>
<p>include &#8220;flooders.inc.php&#8221;;</p>
<p>$f=new Flooders ();</p>
<p>$f-&gt; Check (404);</p>
<p>?&gt;</p>
<p>Example 2 &#8211; not forbidding known search robots.</p>
<p>This code should be established on the latent page:</p>
<p>&lt;?</p>
<p>include &#8220;flooders.inc.php&#8221;;</p>
<p>$f=new Flooders (&#8220;/tmp/ban.txt&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;StackRambler&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;Googlebot&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;Yandex&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;Aport&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;msnbot&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;FAST-WebCrawler&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;Slurp/cat&#8221;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;ASPseek/1.2.10&#8243;);</p>
<p>$f-&gt; AddAlowAgent (&#8220;CNSearch&#8221;);</p>
<p>$f-&gt; SetLogFileName (&#8220;/tmp/ban.log&#8221;);</p>
<p>$f-&gt; Ban ();</p>
<p>?&gt;</p>
<p>This code should be established in the top part of all pages of a site:</p>
<p>&lt;?</p>
<p>include &#8220;flooders.inc.php&#8221;;</p>
<p>$f=new Flooders (&#8220;/tmp/ban.txt&#8221;);</p>
<p>$f-&gt; Check (403);</p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/how-to-protect-a-site-from-total-uploading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple banner system phpFBS</title>
		<link>http://novices-design-courses.info/simple-banner-system-phpfbs/</link>
		<comments>http://novices-design-courses.info/simple-banner-system-phpfbs/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 06:46:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=37</guid>
		<description><![CDATA[For small projects if they initially are not focused on advertising, often there is a need{requirement} of a partner exchange of banners. Usually such happens few times in a month, and you decide what not bad to have near at hand the tool with which help it is possible to operate easily and simply banner [...]]]></description>
			<content:encoded><![CDATA[<p>For small projects if they initially are not focused on advertising, often there is a need{requirement} of a partner exchange of banners. Usually such happens few times in a month, and you decide what not bad to have near at hand the tool with which help it is possible to operate easily and simply banner places on pages of your site.<span id="more-37"></span></p>
<p>For small projects if they initially are not focused on advertising, often there is a need{requirement} of a partner exchange of banners. Usually such happens few times in a month, and you decide what not bad to have near at hand the tool with which help it is possible to operate easily and simply banner places on pages of your site.</p>
<p>Introduction</p>
<p>For small projects if they initially are not focused on advertising, often there is a need{requirement} of a partner exchange of banners. Usually such happens few times in a month, and you decide what not bad to have near at hand the tool with which help it is possible to operate easily and simply banner places on pages of your site.</p>
<p>What in our case means &lt;to operate banner places&gt;? What it is necessary for us from banner system? We list necessary functions:</p>
<p>1. The centralized storage of banners and information on them.</p>
<p>2. Loading a banner on a site through the web &#8211; interface.</p>
<p>3. Installation of the directing link.</p>
<p>4. Addition of new recordings about banners.</p>
<p>5. Removal{Distance} of recordings about banners.</p>
<p>6. Viewing a code and testing of a banner.</p>
<p>All these functions are carried out simple, in my opinion, by banner system phpFBS (FoxWeb Banner System), written on language PHP with base MySQL for 4 hours.</p>
<p>The description of banner system</p>
<p>The system will consist of three PHP-scripts:</p>
<p>1. adm.php &#8211; the panel of administration of banners.</p>
<p>2. conf.php &#8211; connections to base and adjustments.</p>
<p>3. i.php &#8211; for two functions: show and transition of a banner.</p>
<p>Banners will be stored{kept} and be loaded into directories &lt;b&gt; by default a file &#8211; picture, that is. Naturally, rights should be established on it{her} chmod 777 for an opportunity of loadings.</p>
<p>ATTENTION! It is not recommended to use in names of scripts and directories a word banner or similar words, in that case the data, sent to the user automatically &lt;obrezajutsja&gt; proxies and fajrvolami. At testing banner system at my customer it also happened:)</p>
<p>Let&#8217;s begin with simple &#8211; connection to DB MySQL. It carries out a script conf.php. Establish in him necessary registration given MySQL-connections. He is born separately because connection is necessary for &lt;adminskoj&gt; and for &lt;vyvodnoj&gt; parts. In a database we need only one table banners the following structure:</p>
<p>CREATE TABLE ` banners ` (</p>
<p>` banner_id ` tinyint (1) unsigned NOT NULL auto_increment,</p>
<p>` bannername ` varchar (50) default NULL,</p>
<p>` filename ` varchar (50) default NULL,</p>
<p>` url ` varchar (50) default NULL,</p>
<p>` comment ` varchar (50) default NULL,</p>
<p>PRIMARY KEY (` banner_id `)</p>
<p>) ENGINE=MyISAM;</p>
<p>At once I want to please supporters of a file way of storage of recordings &#8211; you are free to think out the functions, but from a DB this system has turned out extremely simple. And if the future it is required to you of 100 and more recordings &#8211; here certainly the DB undoubtedly wins.</p>
<p>conf.php</p>
<p>&lt;? php</p>
<p>mysql_connect (&#8220;localhost&#8221;, &#8220;db_user&#8221;, &#8220;db_pass&#8221;);</p>
<p>mysql_select_db (&#8220;db_name&#8221;);</p>
<p>?&gt;</p>
<p>Let&#8217;s pass to a script of a conclusion and perenapravlenija. To him it is passed two parameters: action (action) and id (number{room} of a banner in the table). First of all the script is connected to base and carries out search about recording id to learn{find out} a way to a file of a banner and the link on which he conducts. Generally speaking, in both cases it is carried out perenapravlenie:</p>
<p>* i.php? action=redirect*id=1 &#8211; it is carried out perenapravlenie on the address of a banner specified in base in a field url. This habitual all action at a clique on a banner the mouse.</p>
<p>* i.php? id=1 &#8211; it is carried out perenapravlenie on the file of a banner specified in base in a field filename. Actually the banner is deduced in a window of a browser as though we have requested it{him} directly (but by means of readdressing from i.php). Well, in general you have understood:)</p>
<p>i.php</p>
<p>&lt;? php</p>
<p>include &#8220;conf.php&#8221;;</p>
<p>$query = &#8221; SELECT * FROM banners WHERE banner_id = $ id &#8220;;</p>
<p>$f = mysql_fetch_array (mysql_query ($query));</p>
<p>extract ($f);</p>
<p>if ($action == &#8220;redirect&#8221;) header (&#8221; Location: &#8220;. $url);</p>
<p>elseif (! $action) header (&#8221; Location: http: // $HTTP_HOST/b / &#8220;. $ filename);</p>
<p>?&gt;</p>
<p>Perenapravlenie standard function PHP header () carries out. Apparently from a code, anything complex{difficult}.</p>
<p>The most complex{difficult} part (in comparison with the others, but actually all is very simple) is a script of administration adm.php. brief structure of this file:</p>
<p>* include (&#8220;conf.php&#8221;) &#8211; connection to a DB.</p>
<p>* function http ($str) &#8211; adds http:// if necessary. The user can enter URL a banner both with a prefix http://, and without him{it} and system it takes into account.</p>
<p>* function banners_table () &#8211; deduces the table of banners. Actually on the screen &#8211; contents of the table banners from a DB.</p>
<p>* function banner_code ($ banner _ id) &#8211; deduces a HTML-code of a banner to the user.</p>
<p>* function banner_show ($banner_id) &#8211; shows the test of a banner. He will be shown how will look on HTML-page of a site.</p>
<p>* Updating the data in base and zakachka a file by pressing the button of sending the form</p>
<p>if ($action == &#8220;write&#8221; ** $banner_id)</p>
<p>* Addition of new recording (it is strict after max numbers{rooms})</p>
<p>if ($action == &#8220;add&#8221; ** $comment)</p>
<p>* Removal{Distance} of recording with specified id</p>
<p>if ($action == &#8220;delete&#8221; ** $banner_id)</p>
<p>* Loading the data in the form from recording with specified id</p>
<p>if ($action == &#8220;read&#8221; ** $banner_id)</p>
<p>* Displays a HTML-code of a banner</p>
<p>if ($action == &#8220;code&#8221; ** $banner_id)</p>
<p>Let&#8217;s say, you have added and have edited recordings, have loaded banners and what is farther? Now having clicked on the link &lt;code&gt; in a line corresponding to the necessary banner, you receive a HTML-code the image &#8211; link like:</p>
<p>&lt;a href = &#8220;./i.php? action=redirect*id=1 &#8220;&gt; &lt;img src = &#8220;./i.php? id=1 &#8221; border = &#8220;0&#8243;/&gt; &lt;/a&gt;</p>
<p>Now you can place it a code in the necessary places of your HTML-pages and&#8230; To forget about them as now at change of a banner you will need to change only recording in the panel of administration.</p>
<p>The complete set of files is accessible here. In the same place the SQL-script for creation of the table banners and a demo of system is stored{kept}.</p>
<p>The described banner system is really used on a site http://58region.ru. It is necessary to note, what is it very simple banner system, and I have tried to make its{her} maximum &#8220;transparent&#8221; for the subsequent escalating and perfection.</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/simple-banner-system-phpfbs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change of appearance of the counter in CNStats</title>
		<link>http://novices-design-courses.info/change-of-appearance-of-the-counter-in-cnstats/</link>
		<comments>http://novices-design-courses.info/change-of-appearance-of-the-counter-in-cnstats/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 11:55:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=34</guid>
		<description><![CDATA[At installation CNStats in section &#8221; the Configuration &#8211; the Code of the counter &#8221; is offered to you for accommodation on a site two types of a code:
At installation CNStats in section &#8221; the Configuration &#8211; the Code of the counter &#8221; is offered to you for accommodation on a site two types of [...]]]></description>
			<content:encoded><![CDATA[<p>At installation CNStats in section &#8221; the Configuration &#8211; the Code of the counter &#8221; is offered to you for accommodation on a site two types of a code:</p>
<p><span id="more-34"></span>At installation CNStats in section &#8221; the Configuration &#8211; the Code of the counter &#8221; is offered to you for accommodation on a site two types of a code:</p>
<p>* An obligatory code of gathering of statistics of a site &#8211; he counts visitors of a site;</p>
<p>* opcional`nyj a code of display of the counter &#8211; this code simply draws a picture with figures of visitings &#8211; the graphic counter.</p>
<p>Appearance of the counter which displays the current visitings a site it is possible to change. In given clause{article} variants of graphic counter CNStats are considered{examined}.</p>
<p>By default, counter CNStats looks as follows:</p>
<p>On him three figures are displayed. The uppermost &#8211; it is hit everything, average &#8211; it is hit today, bottom &#8211; hosts today. In this note we shall consider ways of change of appearance of the counter and ways of display on him another, not less the helpful information.</p>
<p>At the end of a note you can see all kinds of considered{examined} counters and to download them for use.</p>
<p>The initial data</p>
<p>CNStats can give the following information for display to the counter:</p>
<p>* It is hit today, yesterday and all;</p>
<p>* Hosts today, yesterday and all;</p>
<p>* Users today, yesterday and all;</p>
<p>* Users now on a site.</p>
<p>As CNStats can takes into account visitings robots it is possible to deduce{remove} the information and on them:</p>
<p>* Robots today, yesterday and all;</p>
<p>* Percentage attitudes{relations} robots / users.</p>
<p>Besides it is possible to make various counters changes of attendance of a site graphically displaying dynamics{changes}.</p>
<p>Display of counters in CNStats</p>
<p>By default, the script displaying a picture of the counter is in CNStats root and called cnts.php (from English Counter-Show). I recommend to name files of your counters in a similar way, for example cnts-big.php, cnts-ttf.php, etc.</p>
<p>Let&#8217;s begin a spelling of a code with some, standard &#8220;fish&#8221; whom the code of any counter CNStats should contain:</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>// We are connected to a configuration file.</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// We create images, from a preset pattern.</p>
<p>$im=ImageCreateFromPng (&#8220;button.png&#8221;);</p>
<p>// We are connected with MySql the server.</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose a database</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>//. Here all necessary actions are carried out</p>
<p>// On creation of the image&#8230;</p>
<p>}</p>
<p>}</p>
<p>// We send HTTP heading Content-Type</p>
<p>Header (&#8221; Content-type: image/png &#8220;);</p>
<p>// We generate images</p>
<p>ImagePng ($im);</p>
<p>// We clear memory</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>Further this code will be inserted without comments.</p>
<p>The counter ¹1 &#8211; standard</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>$im=ImageCreateFromPng (&#8220;button.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// t_hits &#8211; it is hit all</p>
<p>// hits &#8211; it is hit today</p>
<p>// hosts &#8211; hosts today</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, hits, hosts FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// Vydeljam necessary colors</p>
<p>$black=ImageColorAllocate ($im, 0,0,0);</p>
<p>$color=ImageColorAllocate ($im, $COUNTER ["inkR"],</p>
<p>$COUNTER ["inkG"],</p>
<p>$COUNTER ["inkB"]);</p>
<p>// We deduce{remove} numbers</p>
<p>ImageString ($im, 2,86-6*strlen ($res ["t_hits"]), 1, $res ["t_hits"], $color);</p>
<p>ImageString ($im, 1,85-5*strlen ($res ["hits"]), 13, $res ["hits"], $color);</p>
<p>ImageString ($im, 1,85-5*strlen ($res ["hosts"]), 20, $res ["hosts"], $color);</p>
<p>}</p>
<p>}</p>
<p>Header (&#8221; Content-type: image/png &#8220;);</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The most interesting part of this code is SQL search which chooses the displayed data from the table:</p>
<p>SELECT t_hits, hits, hosts FROM cns_counter</p>
<p>Let&#8217;s consider, that else we can &#8220;pull out&#8221; from tables CNStats so that it practically did not load the server.</p>
<p>SELECT hits, hosts, users,</p>
<p>t_hits, t_hosts, t_users,</p>
<p>u_hits, u_hosts,</p>
<p>u_t_hits, u_t_hosts</p>
<p>FROM cns_counter;</p>
<p>Here:</p>
<p>* hits &#8211; it is hit today</p>
<p>* hosts &#8211; hosts today</p>
<p>* users &#8211; users today</p>
<p>* t_hits &#8211; it is hit all</p>
<p>* t_hosts &#8211; hosts of all</p>
<p>* t_users &#8211; users of all</p>
<p>* u_hits &#8211; it is hit from visitors for today (robots are excluded)</p>
<p>* u_hosts &#8211; hosts from visitors for today (robots are excluded)</p>
<p>* u_t_hits &#8211; it is hit from visitors of all (robots are excluded)</p>
<p>* u_t_hosts &#8211; hosts from visitors of all (robots are excluded)</p>
<p>* u_hits-hits &#8211; it is hit from robots for today</p>
<p>* u_hosts-hosts &#8211; hosts from robots for today</p>
<p>* u_t_hits-t_hits &#8211; it is hit from robots of all</p>
<p>* u_t_hosts-t_hosts &#8211; hosts from robots of all</p>
<p>Remember! Robots are taken into account only at use &#8220;PHP-Include&#8221; and the &#8220;combined&#8221; counters.</p>
<p>The search which obtains quantity{amount} of visitors in the data the moment taking place on a site (conditionally) is below resulted.</p>
<p>SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 3 MINUTE;</p>
<p>The counter ¹2 &#8211; is hit everything, hit today, users today and now on a site</p>
<p>As you see from the image of the counter, here we used other base image, for that what to find room for figure &#8221; now on a site &#8220;. (red color)</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>$im=ImageCreateFromPng (&#8220;button-tt.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// t_hits &#8211; it is hit all</p>
<p>// hits &#8211; it is hit today</p>
<p>// users &#8211; users today</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, hits, users FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// We select necessary colors</p>
<p>$black=ImageColorAllocate ($im, 0,0,0);</p>
<p>$red=ImageColorAllocate ($im, 255,0,0);</p>
<p>// We deduce{remove} numbers</p>
<p>ImageString ($im, 2,3,1, $res ["t_hits"], $black);</p>
<p>ImageString ($im, 1,3,13, $res ["hits"], $black);</p>
<p>ImageString ($im, 1,3,20, $res ["users"], $black);</p>
<p>// We choose &#8221; now on a site &#8221;</p>
<p>$r = mysql_query (&#8221; SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 3 MINUTE; &#8220;);</p>
<p>$text = mysql_result ($r, 0,0);</p>
<p>@mysql_free_result ($r);</p>
<p>// We deduce{remove} &#8221; now on a site &#8221;</p>
<p>ImageString ($im, 1,80-5*strlen ($text), 4, $text, $red);</p>
<p>}</p>
<p>}</p>
<p>Header (&#8221; Content-type: image/png &#8220;);</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The counter ¹3 &#8211; use True-Type of fonts at generation of counters</p>
<p>Unfortunately, that support TrueType of fonts is established far from being on all servers, such counter is not included in the distribution kit. It is a pity, very beautiful counter</p>
<p>On this counter, for a change, we have deduced{removed} is hit today, hosts today and users today.</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// This function allows to define{determine} length of a line in pixels</p>
<p>function width ($text) {</p>
<p>$box=imagettfbbox (7, 0, FONT_TAHOMA, $text);</p>
<p>return ($box [2] &#8211; $box [1]);</p>
<p>}</p>
<p>// A font which we use for a conclusion of the counter.</p>
<p>// It is possible to take from C:WindowsFonts</p>
<p>define (&#8216; FONT_TAHOMA &#8216;,&#8217; tahoma.ttf &#8216;);</p>
<p>// Attention! The image should be True-Color (24 bat)</p>
<p>$im=ImageCreateFromPng (&#8220;button-tt.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// hits &#8211; it is hit today</p>
<p>// hosts &#8211; hosts today</p>
<p>// users &#8211; users today</p>
<p>$r = mysql_query (&#8221; SELECT hits, hosts, users FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// We deduce{remove} the text</p>
<p>$text = $res ["hits"];</p>
<p>Imagettftext ($im, 7, 0, 4, 10, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = $res ["hosts"];</p>
<p>Imagettftext ($im, 7, 0, 4, 19, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = $res ["users"];</p>
<p>Imagettftext ($im, 7, 0, 4, 28, 0&#215;03814A, FONT_TAHOMA, $text);</p>
<p>$r=mysql_query (&#8221; SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 10 MINUTE; &#8220;);</p>
<p>$text = mysql_result ($r, 0,0);</p>
<p>Imagettftext ($im, 7, 0, 80-width ($text), 12, 0xC0314A, FONT_TAHOMA, $text);</p>
<p>}</p>
<p>}</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The counter ¹4 &#8211; is hit everything, the percent{interest} of robots is hit today, users today,</p>
<p>In this example, besides robots we shall a little change appearance of the counter &#8211; we shall add shadows, and with the help of spaces we shall make numbers more legible.</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// This function allows to define{determine} length of a line in pixels</p>
<p>function width ($text) {</p>
<p>$box=imagettfbbox (7, 0, FONT_TAHOMA, $text);</p>
<p>return ($box [2] &#8211; $box [1]);</p>
<p>}</p>
<p>// A font which we use for a conclusion of the counter.</p>
<p>// It is possible to take from C:WindowsFonts</p>
<p>define (&#8216; FONT_TAHOMA &#8216;,&#8217; tahoma.ttf &#8216;);</p>
<p>// Attention! The image should be True-Color (24 bat)</p>
<p>$im=ImageCreateFromPng (&#8220;button-tt.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// t_hits &#8211; it is hit all</p>
<p>// hits &#8211; it is hit today</p>
<p>// users &#8211; users today</p>
<p>// u_hits &#8211; it is hit from visitors</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, hits, users, u_hits FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// We deduce{remove} the text</p>
<p>$text = number_format ($res ["t_hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 5, 11, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 4, 10, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 5, 20, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 4, 19, 0&#215;04476C, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["users"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 5, 29, 0xcccccc, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 4, 28, 0&#215;04876C, FONT_TAHOMA, $text);</p>
<p>// We consider percentage of robots</p>
<p>if ($res ["hits"]! =0)</p>
<p>$text = intval ((1-$ res ["u_hits"] / $res ["hits"]) *100). &#8220;%&#8221;;</p>
<p>else</p>
<p>$text = &#8220;0&#8243;;</p>
<p>// We deduce{remove} the text</p>
<p>Imagettftext ($im, 7, 0, 80-width ($text), 12, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 79-width ($text), 11, 0&#215;03804A, FONT_TAHOMA, $text);</p>
<p>}</p>
<p>}</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The counter ¹5 &#8211; all together</p>
<p>This big counter is the sum of all previous.</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// This function allows to define{determine} length of a line in pixels</p>
<p>function width ($text) {</p>
<p>$box=imagettfbbox (7, 0, FONT_TAHOMA, $text);</p>
<p>return ($box [2] &#8211; $box [1]);</p>
<p>}</p>
<p>// A font which we use for a conclusion of the counter.</p>
<p>// It is possible to take from C:WindowsFonts</p>
<p>define (&#8216; FONT_TAHOMA &#8216;,&#8217; tahoma.ttf &#8216;);</p>
<p>// Attention! The image should be True-Color (24 bat)</p>
<p>$im=ImageCreateFromPng (&#8220;button-big.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONFs ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, t_hosts, t_users, hits, hosts,</p>
<p>users, u_hits FROM cns_counter &#8220;);</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>@mysql_free_result ($r);</p>
<p>$text = number_format ($res ["t_hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 11, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 10, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 20, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 19, 0&#215;0331FF, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["t_hosts"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 31, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 30, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["hosts"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 40, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 39, 0&#215;0331FF, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["t_users"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 51, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 50, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["users"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 60, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 59, 0&#215;0331FF, FONT_TAHOMA, $text);</p>
<p>$r=mysql_query (&#8221; SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 3 MINUTE; &#8220;);</p>
<p>$text = mysql_result ($r, 0,0);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 70, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 69, 0xC0314A, FONT_TAHOMA, $text);</p>
<p>$text = sprintf (&#8221; % .2f %% &#8220;, (1-$ res ["u_hits"] / $res ["hits"]) *100);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 82, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 81, 0&#215;03804A, FONT_TAHOMA, $text);</p>
<p>}</p>
<p>}</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/change-of-appearance-of-the-counter-in-cnstats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Job with the text and graphic data in common in PHP and MySQL</title>
		<link>http://novices-design-courses.info/job-with-the-text-and-graphic-data-in-common-in-php-and-mysql/</link>
		<comments>http://novices-design-courses.info/job-with-the-text-and-graphic-data-in-common-in-php-and-mysql/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 11:52:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://novices-design-courses.info/?p=31</guid>
		<description><![CDATA[I have read many documents devoted to this subject, in result have tried ten from them, and nothing having received in the answer correctly working, have decided to write itself more less suitable for my problem{task} the decision.
I have read many documents devoted to this subject, in result have tried ten from them, and nothing [...]]]></description>
			<content:encoded><![CDATA[<p>I have read many documents devoted to this subject, in result have tried ten from them, and nothing having received in the answer correctly working, have decided to write itself more less suitable for my problem{task} the decision.</p>
<p><span id="more-31"></span>I have read many documents devoted to this subject, in result have tried ten from them, and nothing having received in the answer correctly working, have decided to write itself more less suitable for my problem{task} the decision.</p>
<p>So, production of a problem{task}:</p>
<p>1. It is required to store{keep} such information in a database:</p>
<p>Surname, name, patronymic email, a photo and the brief description (or the biography) the person.</p>
<p>For achievement of an object in view quite widespread complete set of the web &#8211; server is chosen: Apache 1.3.20, PHP 4.1.0, MySQL 4.0.0.</p>
<p>For the beginning we create a DB:</p>
<p>mysqladmin-p create testdb</p>
<p>Then we do{make} its{her} current:</p>
<p>use testdb.</p>
<p>Further we create the table for storage of the information:</p>
<p>CREATE TABLE infouser (</p>
<p>id_infouser int (7) unsigned NOT NULL auto_increment,</p>
<p>lastname varchar (255) NOT NULL default &#8220;,</p>
<p>firstname varchar (255) NOT NULL default &#8220;,</p>
<p>patronym varchar (255) NOT NULL default &#8220;,</p>
<p>imageinfouser mediumblob,</p>
<p>filename1 varchar (50) default NULL,</p>
<p>filesize1 varchar (50) default NULL,</p>
<p>filetype1 varchar (50) default NULL,</p>
<p>infoinfouser varchar (255) default NULL,</p>
<p>emailinfouser varchar (100) default NULL,</p>
<p>PRIMARY KEY (id_infouser))</p>
<p>First we shall create a file for storage of functions, such as, connection with a DB, and patterns that ten times to not copy same:</p>
<p>&lt;? php</p>
<p>// tags for open html-docs</p>
<p>function html_begin ($header)</p>
<p>{</p>
<p>print (&#8221; &lt;html&gt; n &#8220;);</p>
<p>print (&#8221; &lt;head&gt; n &#8220;);</p>
<p>print (&#8221; &lt;META HTTP-EQUIV = &#8220;Content-Type&#8221;</p>
<p>Content = &#8220;text/html&#8221;&gt; &#8220;);</p>
<p>print (&#8221; &lt;title&gt; the Test DB &lt;/title&gt; n &#8220;);</p>
<p>print (&#8221; &lt;/head&gt; n &#8220;);</p>
<p>print (&#8221; &lt;body text = &#8220;*000000&#8243; bgcolor</p>
<p>= &#8220;*52FA90&#8243;&gt; n &#8220;);</p>
<p>print (&#8221; &lt;br&gt; &lt;center&gt; &lt;table width = &#8221; 90 % &#8221;</p>
<p>border = &#8220;1&#8243; bgcolor = &#8220;green&#8221; cols = &#8220;1&#8243;&gt; &#8220;);</p>
<p>print (&#8221; &lt;tr&gt; &lt;td&gt; &lt;p style = &#8221; text-align:</p>
<p>justify; margin-left: 50 px; margin-right: 50 px &#8220;&gt;&#8221;);</p>
<p>if ($header)</p>
<p>print (&#8221; &lt;h3&gt; $header &lt;/h3&gt; n &#8220;);</p>
<p>print (&#8221; &lt;/p&gt; &lt;hr width = &#8221; 100 % &#8221;</p>
<p>size = &#8220;1&#8243; color = &#8220;*c0c0c0&#8243;&gt; &lt;p&gt; &#8220;);</p>
<p>}</p>
<p>//</p>
<p>// tags for close html-docs</p>
<p>function html_end ()</p>
<p>{</p>
<p>print (&#8221; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/center&gt; &#8220;);</p>
<p>print (&#8221; &lt;/body&gt; &lt;/html&gt; &#8220;);</p>
<p>}</p>
<p>//</p>
<p>// function for connect mysql and select database</p>
<p>function connect_mysql ()</p>
<p>{</p>
<p>define (&#8220;DBName&#8221;, &#8220;testdb&#8221;);</p>
<p>define (&#8220;HostName&#8221;, &#8220;localhost&#8221;);</p>
<p>define (&#8220;UserName&#8221;, &#8220;valery&#8221;);</p>
<p>define (&#8220;Password&#8221;, &#8221; &#8220;);</p>
<p>if (! mysql_connect (HostName, UserName, Password))</p>
<p>{echo &#8221; the Server temporarily does not work, come later. &#8220;. DBName. &#8220;! &lt;br&gt; &#8220;;</p>
<p>echo mysql_error ();</p>
<p>exit;</p>
<p>}</p>
<p>mysql_select_db (DBName);</p>
<p>}</p>
<p>?&gt;</p>
<p>We do{make} the form for input of the information.</p>
<p>File with a name insert.php</p>
<p>&lt;? php</p>
<p>include (&#8220;function.inc&#8221;);</p>
<p>$header = (&#8221; to enter the new person &#8220;);</p>
<p>html_begin ($header);</p>
<p>?&gt;</p>
<p>&lt;form action = &#8220;insert2.php&#8221; method = &#8220;post&#8221;</p>
<p>enctype = &#8220;multipart/form-data&#8221;&gt;</p>
<p>Surname: &lt;input type = &#8220;text&#8221; name = &#8220;lastname&#8221;</p>
<p>size = &#8220;30&#8243; maxlenght = &#8220;30&#8243;&gt; &lt;br&gt;</p>
<p>Name: &lt;input type = &#8220;text&#8221; name = &#8220;firstname&#8221;</p>
<p>size = &#8220;30&#8243; maxlenght = &#8220;30&#8243;&gt; &lt;br&gt;</p>
<p>Patronymic: &lt;input type = &#8220;text&#8221; name = &#8220;patronym&#8221;</p>
<p>size = &#8220;30&#8243; maxlenght = &#8220;30&#8243;&gt; &lt;br&gt;</p>
<p>Email: &lt;input type = &#8220;text&#8221; name = &#8220;email&#8221;</p>
<p>size = &#8220;30&#8243; maxlenght = &#8220;30&#8243;&gt; &lt;br&gt;</p>
<p>Photo: &lt;input type = &#8220;file&#8221; name = &#8220;userfile&#8221;&gt; &lt;br&gt;</p>
<p>The information on the person: &lt;br&gt;</p>
<p>&lt;textarea name = &#8220;infoinfouser&#8221; cols = &#8220;40&#8243;</p>
<p>rows = &#8220;5&#8243;&gt; &lt;/textarea&gt;</p>
<p>&lt;br&gt;</p>
<p>&lt;input type = &#8220;submit&#8221; value = &#8221; To enter the new person &#8220;&gt; &lt;br&gt;</p>
<p>&lt;/form&gt;</p>
<p>&lt;? php</p>
<p>html_end ();</p>
<p>?&gt;</p>
<p>Then there is a page accepting the information a name of a file obviously enough insert2.php:</p>
<p>&lt;? php</p>
<p>include (&#8220;function.inc&#8221;);</p>
<p>$header = (&#8221; input of the information &#8220;);</p>
<p>html_begin ($header);</p>
<p>//</p>
<p>// read file image</p>
<p>$fd = fopen ($userfile, &#8220;rb&#8221;);</p>
<p>$userfile2 = fread ($fd, filesize ($userfile));</p>
<p>fclose ($fd);</p>
<p>$userfile2 = addslashes ($userfile2);</p>
<p>//</p>
<p>// insert in db</p>
<p>//</p>
<p>connect_mysql ();</p>
<p>mysql_query (&#8221; SELECT * FROM infouser &#8220;);</p>
<p>mysql_query (&#8221; INSERT INTO infouser (id_infouser, lastname, firstname, patronym,</p>
<p>imageinfouser, filename1, filesize1, filetype1, infoinfouser, email_infouser)</p>
<p>VALUES (&#8220;, &#8216; $ lastname &#8216;,&#8217; $firstname &#8216;,&#8217; $patronym &#8216;,&#8217; $userfile2 &#8216;,&#8217; $userfile_name &#8216;,</p>
<p>&#8216; $userfile_size &#8216;,&#8217; $userfile_type &#8216;,&#8217; $infoinfouser &#8216;,&#8217; $email &#8216;) &#8220;);</p>
<p>echo &#8220;&lt;br&gt;&#8221;;</p>
<p>print &#8221; the New user is successfully entered &#8220;;</p>
<p>mysql_close ();</p>
<p>html_end ();</p>
<p>?&gt;</p>
<p>That&#8217;s all we have entered the data, now they should be read somehow.</p>
<p>For this purpose it is used three more files.</p>
<p>The first file gives out the list of users.</p>
<p>prev.php</p>
<p>&lt;? php</p>
<p>include (&#8220;function.inc&#8221;);</p>
<p>//</p>
<p>$header = (&#8221; viewing of recordings &#8220;);</p>
<p>html_begin ($header);</p>
<p>//</p>
<p>connect_mysql ();</p>
<p>//</p>
<p>print (&#8221; &lt;table cols = &#8220;1&#8243;&gt; &#8220;);</p>
<p>// We deduce{remove} all recordings</p>
<p>$r=mysql_query (&#8221; SELECT * FROM infouser &#8220;);</p>
<p>for ($i=0; $i &lt;mysql_num_rows ($r); $i ++)</p>
<p>{$f=mysql_fetch_array ($r);</p>
<p>print &#8220;&lt;tr&gt;&#8221;;</p>
<p>print &#8221; &lt;td align = &#8220;center&#8221;&gt; &#8220;;</p>
<p>print &#8221; &lt;a target = &#8221; _new &#8221; href = &#8221; sample.php? id = $ f [id_infouser] &#8220;&gt; $f [lastname]</p>
<p>$f [firstname] $f [patronym] &lt;/a&gt; &#8220;;</p>
<p>print &#8220;&lt;p&gt;&#8221;;</p>
<p>//</p>
<p>print &#8220;&lt;/td&gt;&#8221;;</p>
<p>print &#8220;&lt;/tr&gt;&#8221;;</p>
<p>}</p>
<p>print &#8220;&lt;/table&gt;&#8221;;</p>
<p>mysql_close ();</p>
<p>html_end ();</p>
<p>?&gt;</p>
<p>The second file is used for delivery of the data on one user: sample.php</p>
<p>&lt;? php</p>
<p>//</p>
<p>include (&#8220;function.inc&#8221;);</p>
<p>$header = (&#8221; viewing of recordings &#8220;);</p>
<p>html_begin ($header);</p>
<p>//</p>
<p>connect_mysql ();</p>
<p>//</p>
<p>reset ($HTTP_GET_VARS);</p>
<p>while (list ($key, $val) = each ($HTTP_GET_VARS)) {</p>
<p>//</p>
<p>$sql = &#8221; SELECT * FROM infouser WHERE id_infouser = &#8216; $val &#8216; &#8220;;</p>
<p>$result = mysql_query ($sql);</p>
<p>$rows = mysql_num_rows ($result);</p>
<p>echo &#8221; &lt;table border = &#8220;0&#8243; width = &#8221; 70 % &#8220;&gt; n &#8220;;</p>
<p>for ($i = 0; $i &lt;$rows; $i ++) {</p>
<p>$data = mysql_fetch_object ($result);</p>
<p>echo &#8221; &lt;tr&gt; n &#8220;;</p>
<p>echo &#8221; &lt;td&gt; &lt;font color = &#8220;red&#8221; size</p>
<p>= &#8220;+1&#8243;&gt; $data-&gt; lastname &lt;br&gt; $data-&gt; firstname &lt;br&gt;</p>
<p>$data-&gt; patronym &lt;br&gt; &lt;/font&gt; &lt;/td&gt; n &#8220;;</p>
<p>echo &#8221; &lt;td rowspan = &#8220;2&#8243;&gt; &lt;center&gt; &lt;img</p>
<p>src = &#8216; download.php? id = $ data-&gt; id_infouser &#8216; border =</p>
<p>&#8216; 2 &#8216; bgcolor = &#8216; *01cccc &#8216;&gt; &lt;/center&gt; &lt;/td&gt; n &#8220;;</p>
<p>echo &#8221; &lt;/tr&gt; n &#8220;;</p>
<p>echo &#8221; &lt;tr&gt; n &#8220;;</p>
<p>echo &#8221; &lt;td&gt; &lt;font color = &#8220;green&#8221;&gt; $data-&gt; emailinfouser &lt;/font&gt; &lt;/td&gt; n &#8220;;</p>
<p>echo &#8221; &lt;/tr&gt; n &#8220;;</p>
<p>echo &#8221; &lt;tr&gt; n &#8220;;</p>
<p>echo &#8221; &lt;td colspan = &#8220;2&#8243;&gt; $data-&gt; infoinfouser &lt;/td&gt; n &#8220;;</p>
<p>echo &#8221; &lt;/tr&gt; n &#8220;;</p>
<p>}</p>
<p>mysql_free_result ($result);</p>
<p>}</p>
<p>mysql_close ();</p>
<p>//</p>
<p>html_end ();</p>
<p>?&gt;</p>
<p>The following file realizes processing photos and delivery of them: download.php</p>
<p>&lt;? php</p>
<p>//</p>
<p>reset ($HTTP_GET_VARS);</p>
<p>while (list ($key, $val) = each ($HTTP_GET_VARS)) {</p>
<p>//</p>
<p>//</p>
<p>define (&#8220;DBName&#8221;, &#8220;testdb&#8221;);</p>
<p>define (&#8220;HostName&#8221;, &#8220;localhost&#8221;);</p>
<p>define (&#8220;UserName&#8221;, &#8220;valery&#8221;);</p>
<p>define (&#8220;Password&#8221;, &#8221; &#8220;);</p>
<p>if (! mysql_connect (HostName, UserName, Password))</p>
<p>{echo &#8221; the Server temporarily does not work, come</p>
<p>Later. &#8220;. DBName. &#8220;! &lt;br&gt; &#8220;;</p>
<p>echo mysql_error ();</p>
<p>exit;</p>
<p>}</p>
<p>mysql_select_db (DBName);</p>
<p>//</p>
<p>//</p>
<p>$sql = &#8221; SELECT imageinfouser, filename1, filetype1 FROM</p>
<p>infouser WHERE id_infouser = &#8216; $ val &#8216; &#8220;;</p>
<p>$result = @mysql_query ($sql);</p>
<p>$data = @mysql_result ($result, 0, &#8220;imageinfouser&#8221;);</p>
<p>$name = @mysql_result ($result, 0, &#8220;filename1&#8243;);</p>
<p>$type = @mysql_result ($result, 0, &#8220;filetype1&#8243;);</p>
<p>header (&#8221; Content-type: $type &#8220;);</p>
<p>echo $data;</p>
<p>}</p>
<p>mysql_close ();</p>
<p>?&gt;</p>
<p>Change of appearance of the counter in CNStats</p>
<p>Requirements: CNStats 2.7 and is higher. GD 1.0 and is higher</p>
<p>At installation CNStats in section &#8221; the Configuration &#8211; the Code of the counter &#8221; is offered to you for accommodation on a site two types of a code:</p>
<p>* An obligatory code of gathering of statistics of a site &#8211; he counts visitors of a site;</p>
<p>* opcional`nyj a code of display of the counter &#8211; this code simply draws a picture with figures of visitings &#8211; the graphic counter.</p>
<p>Appearance of the counter which displays the current visitings a site it is possible to change. In given clause{article} variants of graphic counter CNStats are considered{examined}.</p>
<p>By default, counter CNStats looks as follows:</p>
<p>On him three figures are displayed. The uppermost &#8211; it is hit everything, average &#8211; it is hit today, bottom &#8211; hosts today. In this note we shall consider ways of change of appearance of the counter and ways of display on him another, not less the helpful information.</p>
<p>At the end of a note you can see all kinds of considered{examined} counters and to download them for use.</p>
<p>The initial data</p>
<p>CNStats can give the following information for display to the counter:</p>
<p>* It is hit today, yesterday and all;</p>
<p>* Hosts today, yesterday and all;</p>
<p>* Users today, yesterday and all;</p>
<p>* Users now on a site.</p>
<p>As CNStats can takes into account visitings robots it is possible to deduce{remove} the information and on them:</p>
<p>* Robots today, yesterday and all;</p>
<p>* Percentage attitudes{relations} robots / users.</p>
<p>Besides it is possible to make various counters changes of attendance of a site graphically displaying dynamics{changes}.</p>
<p>Display of counters in CNStats</p>
<p>By default, the script displaying a picture of the counter is in CNStats root and called cnts.php (from English Counter-Show). I recommend to name files of your counters in a similar way, for example cnts-big.php, cnts-ttf.php, etc.</p>
<p>Let&#8217;s begin a spelling of a code with some, standard &#8220;fish&#8221; whom the code of any counter CNStats should contain:</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>// We are connected to a configuration file.</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// We create images, from a preset pattern.</p>
<p>$im=ImageCreateFromPng (&#8220;button.png&#8221;);</p>
<p>// We are connected with MySql the server.</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose a database</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>//. Here all necessary actions are carried out</p>
<p>// On creation of the image&#8230;</p>
<p>}</p>
<p>}</p>
<p>// We send HTTP heading Content-Type</p>
<p>Header (&#8221; Content-type: image/png &#8220;);</p>
<p>// We generate images</p>
<p>ImagePng ($im);</p>
<p>// We clear memory</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>Further this code will be inserted without comments.</p>
<p>The counter ¹1 &#8211; standard</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>$im=ImageCreateFromPng (&#8220;button.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// t_hits &#8211; it is hit all</p>
<p>// hits &#8211; it is hit today</p>
<p>// hosts &#8211; hosts today</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, hits, hosts FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// Vydeljam necessary colors</p>
<p>$black=ImageColorAllocate ($im, 0,0,0);</p>
<p>$color=ImageColorAllocate ($im, $COUNTER ["inkR"],</p>
<p>$COUNTER ["inkG"],</p>
<p>$COUNTER ["inkB"]);</p>
<p>// We deduce{remove} numbers</p>
<p>ImageString ($im, 2,86-6*strlen ($res ["t_hits"]), 1, $res ["t_hits"], $color);</p>
<p>ImageString ($im, 1,85-5*strlen ($res ["hits"]), 13, $res ["hits"], $color);</p>
<p>ImageString ($im, 1,85-5*strlen ($res ["hosts"]), 20, $res ["hosts"], $color);</p>
<p>}</p>
<p>}</p>
<p>Header (&#8221; Content-type: image/png &#8220;);</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The most interesting part of this code is SQL search which chooses the displayed data from the table:</p>
<p>SELECT t_hits, hits, hosts FROM cns_counter</p>
<p>Let&#8217;s consider, that else we can &#8220;pull out&#8221; from tables CNStats so that it practically did not load the server.</p>
<p>SELECT hits, hosts, users,</p>
<p>t_hits, t_hosts, t_users,</p>
<p>u_hits, u_hosts,</p>
<p>u_t_hits, u_t_hosts</p>
<p>FROM cns_counter;</p>
<p>Here:</p>
<p>* hits &#8211; it is hit today</p>
<p>* hosts &#8211; hosts today</p>
<p>* users &#8211; users today</p>
<p>* t_hits &#8211; it is hit all</p>
<p>* t_hosts &#8211; hosts of all</p>
<p>* t_users &#8211; users of all</p>
<p>* u_hits &#8211; it is hit from visitors for today (robots are excluded)</p>
<p>* u_hosts &#8211; hosts from visitors for today (robots are excluded)</p>
<p>* u_t_hits &#8211; it is hit from visitors of all (robots are excluded)</p>
<p>* u_t_hosts &#8211; hosts from visitors of all (robots are excluded)</p>
<p>* u_hits-hits &#8211; it is hit from robots for today</p>
<p>* u_hosts-hosts &#8211; hosts from robots for today</p>
<p>* u_t_hits-t_hits &#8211; it is hit from robots of all</p>
<p>* u_t_hosts-t_hosts &#8211; hosts from robots of all</p>
<p>Remember! Robots are taken into account only at use &#8220;PHP-Include&#8221; and the &#8220;combined&#8221; counters.</p>
<p>The search which obtains quantity{amount} of visitors in the data the moment taking place on a site (conditionally) is below resulted.</p>
<p>SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 3 MINUTE;</p>
<p>The counter ¹2 &#8211; is hit everything, hit today, users today and now on a site</p>
<p>As you see from the image of the counter, here we used other base image, for that what to find room for figure &#8221; now on a site &#8220;. (red color)</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>$im=ImageCreateFromPng (&#8220;button-tt.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// t_hits &#8211; it is hit all</p>
<p>// hits &#8211; it is hit today</p>
<p>// users &#8211; users today</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, hits, users FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// We select necessary colors</p>
<p>$black=ImageColorAllocate ($im, 0,0,0);</p>
<p>$red=ImageColorAllocate ($im, 255,0,0);</p>
<p>// We deduce{remove} numbers</p>
<p>ImageString ($im, 2,3,1, $res ["t_hits"], $black);</p>
<p>ImageString ($im, 1,3,13, $res ["hits"], $black);</p>
<p>ImageString ($im, 1,3,20, $res ["users"], $black);</p>
<p>// We choose &#8221; now on a site &#8221;</p>
<p>$r = mysql_query (&#8221; SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 3 MINUTE; &#8220;);</p>
<p>$text = mysql_result ($r, 0,0);</p>
<p>@mysql_free_result ($r);</p>
<p>// We deduce{remove} &#8221; now on a site &#8221;</p>
<p>ImageString ($im, 1,80-5*strlen ($text), 4, $text, $red);</p>
<p>}</p>
<p>}</p>
<p>Header (&#8221; Content-type: image/png &#8220;);</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The counter ¹3 &#8211; use True-Type of fonts at generation of counters</p>
<p>Unfortunately, that support TrueType of fonts is established far from being on all servers, such counter is not included in the distribution kit. It is a pity, very beautiful counter</p>
<p>On this counter, for a change, we have deduced{removed} is hit today, hosts today and users today.</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// This function allows to define{determine} length of a line in pixels</p>
<p>function width ($text) {</p>
<p>$box=imagettfbbox (7, 0, FONT_TAHOMA, $text);</p>
<p>return ($box [2] &#8211; $box [1]);</p>
<p>}</p>
<p>// A font which we use for a conclusion of the counter.</p>
<p>// It is possible to take from C:WindowsFonts</p>
<p>define (&#8216; FONT_TAHOMA &#8216;,&#8217; tahoma.ttf &#8216;);</p>
<p>// Attention! The image should be True-Color (24 bat)</p>
<p>$im=ImageCreateFromPng (&#8220;button-tt.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// hits &#8211; it is hit today</p>
<p>// hosts &#8211; hosts today</p>
<p>// users &#8211; users today</p>
<p>$r = mysql_query (&#8221; SELECT hits, hosts, users FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// We deduce{remove} the text</p>
<p>$text = $res ["hits"];</p>
<p>Imagettftext ($im, 7, 0, 4, 10, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = $res ["hosts"];</p>
<p>Imagettftext ($im, 7, 0, 4, 19, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = $res ["users"];</p>
<p>Imagettftext ($im, 7, 0, 4, 28, 0&#215;03814A, FONT_TAHOMA, $text);</p>
<p>$r=mysql_query (&#8221; SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 10 MINUTE; &#8220;);</p>
<p>$text = mysql_result ($r, 0,0);</p>
<p>Imagettftext ($im, 7, 0, 80-width ($text), 12, 0xC0314A, FONT_TAHOMA, $text);</p>
<p>}</p>
<p>}</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The counter ¹4 &#8211; is hit everything, the percent{interest} of robots is hit today, users today,</p>
<p>In this example, besides robots we shall a little change appearance of the counter &#8211; we shall add shadows, and with the help of spaces we shall make numbers more legible.</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// This function allows to define{determine} length of a line in pixels</p>
<p>function width ($text) {</p>
<p>$box=imagettfbbox (7, 0, FONT_TAHOMA, $text);</p>
<p>return ($box [2] &#8211; $box [1]);</p>
<p>}</p>
<p>// A font which we use for a conclusion of the counter.</p>
<p>// It is possible to take from C:WindowsFonts</p>
<p>define (&#8216; FONT_TAHOMA &#8216;,&#8217; tahoma.ttf &#8216;);</p>
<p>// Attention! The image should be True-Color (24 bat)</p>
<p>$im=ImageCreateFromPng (&#8220;button-tt.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONF ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>// We choose the data</p>
<p>// t_hits &#8211; it is hit all</p>
<p>// hits &#8211; it is hit today</p>
<p>// users &#8211; users today</p>
<p>// u_hits &#8211; it is hit from visitors</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, hits, users, u_hits FROM cns_counter &#8220;);</p>
<p>// It is transferable{tolerable} the unique chosen recording in an associative file</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>// We release{exempt} memory</p>
<p>@mysql_free_result ($r);</p>
<p>// We deduce{remove} the text</p>
<p>$text = number_format ($res ["t_hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 5, 11, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 4, 10, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 5, 20, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 4, 19, 0&#215;04476C, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["users"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 5, 29, 0xcccccc, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 4, 28, 0&#215;04876C, FONT_TAHOMA, $text);</p>
<p>// We consider percentage of robots</p>
<p>if ($res ["hits"]! =0)</p>
<p>$text = intval ((1-$ res ["u_hits"] / $res ["hits"]) *100). &#8220;%&#8221;;</p>
<p>else</p>
<p>$text = &#8220;0&#8243;;</p>
<p>// We deduce{remove} the text</p>
<p>Imagettftext ($im, 7, 0, 80-width ($text), 12, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 79-width ($text), 11, 0&#215;03804A, FONT_TAHOMA, $text);</p>
<p>}</p>
<p>}</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
<p>The counter ¹5 &#8211; all together</p>
<p>This big counter is the sum of all previous.</p>
<p>&lt;?</p>
<p>error_reporting (E_ALL and ~E_NOTICE);</p>
<p>include &#8220;config.php&#8221;;</p>
<p>// This function allows to define{determine} length of a line in pixels</p>
<p>function width ($text) {</p>
<p>$box=imagettfbbox (7, 0, FONT_TAHOMA, $text);</p>
<p>return ($box [2] &#8211; $box [1]);</p>
<p>}</p>
<p>// A font which we use for a conclusion of the counter.</p>
<p>// It is possible to take from C:WindowsFonts</p>
<p>define (&#8216; FONT_TAHOMA &#8216;,&#8217; tahoma.ttf &#8216;);</p>
<p>// Attention! The image should be True-Color (24 bat)</p>
<p>$im=ImageCreateFromPng (&#8220;button-big.png&#8221;);</p>
<p>$CONN = mysql_connect ($STATS_CONF ["sqlhost"],</p>
<p>$STATS_CONF ["sqluser"],</p>
<p>$STATS_CONFs ["sqlpassword"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>@mysql_select_db ($STATS_CONF ["dbname"]);</p>
<p>if (mysql_errno () == 0) {</p>
<p>$r = mysql_query (&#8221; SELECT t_hits, t_hosts, t_users, hits, hosts,</p>
<p>users, u_hits FROM cns_counter &#8220;);</p>
<p>$res = mysql_fetch_array ($r, MYSQL_ASSOC);</p>
<p>@mysql_free_result ($r);</p>
<p>$text = number_format ($res ["t_hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 11, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 10, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["hits"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 20, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 19, 0&#215;0331FF, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["t_hosts"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 31, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 30, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["hosts"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 40, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 39, 0&#215;0331FF, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["t_users"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 51, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 50, 0&#215;03314A, FONT_TAHOMA, $text);</p>
<p>$text = number_format ($res ["users"], 0 &#8220;,&#8221;, &#8221; &#8220;);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 60, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 59, 0&#215;0331FF, FONT_TAHOMA, $text);</p>
<p>$r=mysql_query (&#8221; SELECT count (DISTINCT hid) as online</p>
<p>FROM cns_log</p>
<p>WHERE date&gt; NOW () &#8211; INTERVAL 3 MINUTE; &#8220;);</p>
<p>$text = mysql_result ($r, 0,0);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 70, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 69, 0xC0314A, FONT_TAHOMA, $text);</p>
<p>$text = sprintf (&#8221; % .2f %% &#8220;, (1-$ res ["u_hits"] / $res ["hits"]) *100);</p>
<p>Imagettftext ($im, 7, 0, 86-width ($text), 82, 0xCCCCCC, FONT_TAHOMA, $text);</p>
<p>Imagettftext ($im, 7, 0, 85-width ($text), 81, 0&#215;03804A, FONT_TAHOMA, $text);</p>
<p>}</p>
<p>}</p>
<p>ImagePng ($im);</p>
<p>ImageDestroy ($im);</p>
<p>?&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://novices-design-courses.info/job-with-the-text-and-graphic-data-in-common-in-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
