Your Ad Here

 Navigation
Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Books
Sample Chapters
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




 Sponsors
 Links
finance products
golfing products
dvd information
 Downloads
dzphp editor
EasyPHP
mysql_phpgenerator
php-studio-trial
phpdesigner_7_2_5
phpMyAdmin-3.4.3.2
/phptriad2-2-1
phpxedit_321
rapidphp 2011
WampServer2.1d-x64
WampServer2.1e-x32
xampp-win32-1.7.4-VC6-installer
xampplite-win32-1.7.3
 Misc
Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!


Log stats part 3


Log stats

Now for the final part we will simply display the results of the stats table on the page . Here is the script , remember you will have to modify the username and password values to your own values. In this example we will show only 10 entries maximum , you can change this by altering or removing the LIMIT 10;

<?php
//make a connection
$connection = mysql_connect("localhost","username","password");
//select the database
mysql_select_db("stats" , $connection);
//create a sql query select all from stats table
$sql_query = "SELECT * FROM stats LIMIT 10";
//store query results in the $results variable
$results = mysql_query($sql_query);
//start our table
echo ("<table width ='100%' border ='1'>");
//this is simply the headings
echo ("<tr><th>id</th><th>browser</th><th>I.P address</th><th>Date of visit</th></tr>");
//loop through the rows
while ($tablerows = mysql_fetch_row($results))
{
echo("<tr>");
//this displays the ID field
echo("<td>$tablerows[0]</td>");
//this displays the browser field
echo("<td>$tablerows[1]</td>");
//this displays the ip field
echo("<td>$tablerows[2]</td>");
//this displays the logdate field
echo("<td>$tablerows[3]</td>");
echo("</tr>");
}
echo ("</table>");
?>

This will now display a table with your stats on the screen , here was ours , note we have scored out the IP because we were accessing this off the same computer.


As you can see this displays the data from the database ,in this example you can see 8 entries for Microsoft Internet Explorer 5.5 and 1 for Opera . Notice how Opera 5 identifies itself as MSIE 5.0 . This sort of info is important for web developers using this we could optimize our site for Internet Explorer if we wished because this is the dominant browser . Another reason this data is important is what if you were wishing to check the browsers and display a browser share , if you tested for MSIE to get Internet Explorer share you would get faulty readings because Opera 5 has got MSIE 5.0 , you should check for Opera 5 instead . Also note that all browsers report back Mozilla so you could not use this as a check for netscape browsers .

In a future tutorial we will add more stats , produce percentage shares for browsers , Operating Systems and also display daily hits , weekly hits , monthly hits and yearly hits.




Books
 Sponsors


 Random Code
Twitter auto follow script(internet)
create a date(date and time)
Java version with php(php and java)
 Random Article
How to Implement CAPTCHA With PHP and GD

So, you have a submission form on your website and need to prevent spam by auto-submitters. The most common way to do this is to implement CAPTCHA - an image with a randomly generated string (quote from Wikipedia, free online enciclopedia: “A CAPTCHA is a type of challenge-response test used in computing to determine whether the user is human. "CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart", trademarked by Carnegie Mellon University.”)

Simple, quick and efficient PHP solution for implement CAPTCHA:

the advantage of this solution: it is easy to read symbols by human and automated captcha processor software, but hard to process the image by computer because common CAPTCHA processors can't understand which one of the outputted symbols it must ignore!

obviously you need PHP engine enabled for your webserver, for execute PHP scripts, and GD (PHP graphics library) for generate the image. Webserver, PHP and GD versions are no matter, the solution below is tested for Apache(Windows and Unix), IIS(Windows), PHP-4, PHP-5, GD, GD2

1) Make a PHP script (separate file captcha.php) which will generate the CAPTCHA image:
[?php
session_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
function _generateRandom($length=6){
$_rand_src = array(
array(48,57) //digits
, array(97,122) //lowercase chars
// , array(65,90) //uppercase chars
);
srand ((double) microtime() * 1000000);
$random_string = "";
for($i=0;$i<$length;$i++){
$i1=rand(0,sizeof($_rand_src)-1);
$random_string .= chr(rand($_rand_src[$i1][0],$_rand_src[$i1][1]));
}
return $random_string;
}
$im = @imagecreatefromjpeg("captcha.jpg");
$rand = _generateRandom(3);
$_SESSION['captcha'] = $rand;
ImageString($im, 5, 2, 2, $rand[0]." ".$rand[1]." ".$rand[2]." ", ImageColorAllocate ($im, 0, 0, 0));
$rand = _generateRandom(3);
ImageString($im, 5, 2, 2, " ".$rand[0]." ".$rand[1]." ".$rand[2], ImageColorAllocate ($im, 255, 0, 0));
Header ('Content-type: image/jpeg');
imagejpeg($im,NULL,100);
ImageDestroy($im);
?]

2) Add the following line at the top of the page where you need to implement the CAPTCHA (there should not be any output before this line, except you use php functions ob_start() and ob_end_flush() to turn on output buffering):
[?php session_start(); ?]

3) Add the following line for check is CAPTCHA entered by visitor valid, before the line where you will proceed submitted message:
[?php if($_SESSION["captcha"]==$_POST["captcha"])
{
//CAPTHCA is valid; proceed the message: save to database, send by e-mail ...
echo 'CAPTHCA is valid; proceed the message';
}
else {

echo 'CAPTHCA is not valid; ignore submission'; }?]

4) Finaly add the CAPTCHA to the form:
[img src="captcha.php" alt="captcha image"][input type="text" name="captcha" size="3" maxlength="3"]

P.S.
notice:
- the tags "[?" and "?]" in code samples above should be replaced to the "", you may download original article and code sample here: free download php captcha demo

- requirements: a webserver (windows or linux no matter) with PHP engine, with GD (graphic library) support, you may check your php settings with phpinfo() function

- you need some blank jpg image for use it as background for CAPTCHA string


PHP Form Series Part 1 Validators Client side Validation
  Network
Programming resources
Tutorials directory
Hosting resources
ASP site
Domain names
Progged
Maxi directory
bigarticle : free articles
A Code
Code N Tutorials
Get PHP
Programmers help




beginners PHP Copyright © 2004 onwards by beginnersPHP.