Here's an updated version of the perl order counter that was posted moons ago on the forum. It does much the same thing but is PHP based as opposed to perl. To install, save the attached code as whatever-i-want-to-call-it.php and upload to your desired folder online (any folder in any location should work) and that should be you. Obviously, your server has to PHP enabled.
NOTE: IN AN IDEAL WORLD THIS WILL BE UPLOADED TO A PASSWORD PROTECTED DIRECTORY. AT A MINIMUM, YOU WANT TO PUT IT IN A UNGUESSABLE DIRECTORY OR RISK THE WORLD KNOWING HOW MANY ORDERS YOU HAVE ETC ETC!
The script itself will count orders, sessions and saved carts by default but it could be amended easily to count anything inside the folder i.e html, jpegs etc etc. It will also display the results in the title tag of the page, particularly useful for tabbed browsing (there is a meta refresh on the page which will re-load it every 3 minutes so if you are working in another tab, you will know if you have any orders!).
It also displays how long your server has been up, however, this may or may not work on your server so you may need to remove this part of the code (it won't work on windows full stop)
I have commented all the PHP so that those who aren't so clued up on it know what is happening and should be able to amend anything they need to.
The stylesheet can obviously also be changed to colours/layouts that are more to your tastes!
This works particularly well for mobile phone browsing, for those who want to check their sites on the move. Any suggestions/changes/mistakes let me know. Code below:-
NOTE: IN AN IDEAL WORLD THIS WILL BE UPLOADED TO A PASSWORD PROTECTED DIRECTORY. AT A MINIMUM, YOU WANT TO PUT IT IN A UNGUESSABLE DIRECTORY OR RISK THE WORLD KNOWING HOW MANY ORDERS YOU HAVE ETC ETC!
The script itself will count orders, sessions and saved carts by default but it could be amended easily to count anything inside the folder i.e html, jpegs etc etc. It will also display the results in the title tag of the page, particularly useful for tabbed browsing (there is a meta refresh on the page which will re-load it every 3 minutes so if you are working in another tab, you will know if you have any orders!).
It also displays how long your server has been up, however, this may or may not work on your server so you may need to remove this part of the code (it won't work on windows full stop)
I have commented all the PHP so that those who aren't so clued up on it know what is happening and should be able to amend anything they need to.
The stylesheet can obviously also be changed to colours/layouts that are more to your tastes!
This works particularly well for mobile phone browsing, for those who want to check their sites on the move. Any suggestions/changes/mistakes let me know. Code below:-
Code:
<?php /****************************************************************************** Query directory and retrieve count results ******************************************************************************/ $shopdir = "acatalog"; /* Set shop directory, change as necessary */ $num_orders = count(glob($_SERVER['DOCUMENT_ROOT']."/$shopdir/*.ord")); /* Count .ord files in shop directory */ $num_sessions = count(glob($_SERVER['DOCUMENT_ROOT']."/$shopdir/*.session")); /* Count .session files in shop directory */ $num_saves = count(glob($_SERVER['DOCUMENT_ROOT']."/$shopdir/*.save")); /* Count .save files in shop directory */ ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta http-equiv="refresh" content="180" /> <title><?php /****************************************************************************** Create title tag ******************************************************************************/ echo "[OR " . $num_orders . "] "; /* Output number of orders */ echo "[SE " . $num_sessions . "] "; /* Output number of sessions */ echo "[SA " . $num_saves . "]"; /* Output number of saved carts */ ?></title> <style type="text/css"> <!-- body, h3, h4{ font: 10px Arial, sans-serif; background: #222222; padding: 0; margin: 0 } h3 { padding: 0.4em 0em 0.4em 0.4em; font-size: 1.1em; text-transform: uppercase; background: #98bc48; color: #ffffff } h4 { padding: 0.4em 0em 0.4em 0.4em; font-size: 1.2em; text-transform: uppercase; background: #222222; color: #ffffff } --> </style> </head> <body> <?php /****************************************************************************** Output current server time ******************************************************************************/ $servertime = date("F j, Y, g:i a"); echo "<h3>Date & Time</h3>\n<h4>" .$servertime . "</h4>"; /****************************************************************************** Retrieve count of Orders (.ord files) and output result ******************************************************************************/ echo "\n<h3>No of Orders</h3>\n<h4>"; if ($num_orders > 1) { /* If number of orders greater than 1, output following code */ echo $num_orders . " orders</h4>";} /* Output html code if above line equals true */ else if ($num_orders == 1) { /* If number of orders equal to 1, output following code */ echo $num_orders . " order</h4>";} /* Output html code if above line equals true */ else { /* If number of orders less than 1 (zero), output following code */ echo "There are no orders</h4>";} /* Output html code if above line equals true */ /****************************************************************************** Retrieve count of Sessions (.session files) and output result ******************************************************************************/ echo "\n<h3>No of Sessions</h3>\n<h4>"; if ($num_sessions > 1) { /* If number of sessions greater than 1, output following code */ echo $num_sessions . " active sessions</h4>";} /* Output html code if above line equals true */ else if ($num_sessions == 1) { /* If number of sessions equal to 1, output following code */ echo $num_sessions . " active session</h4>";} /* Output html code if above line equals true */ else { /* If number of sessions less than 1 (zero), output following code */ echo "There are no active sessions</h4>";} /* Output html code if above line equals true */ /****************************************************************************** Retrieve count of Saved carts (.save files) and output result ******************************************************************************/ echo "\n<h3>No of Saved Carts</h3>\n<h4>"; if ($num_saves > 1) { /* If number of saved carts greater than 1, output following code */ echo $num_saves . " saved carts</h4>";} /* Output html code if above line equals true */ else if ($num_saves == 1) { /* If number of saved carts equal to 1, output following code */ echo $num_saves . " saved cart</h4>";} /* Output html code if above line equals true */ else { /* If number of saved carts less than 1 (zero), output following code */ echo "There are no saved carts</h4>";} /* Output html code if above line equals true */ /****************************************************************************** Get server uptime and output result ******************************************************************************/ $data = shell_exec('uptime'); /* Get server uptime */ $uptime = explode(' up ', $data); /* Break up result into meaningful chunks */ $uptime = explode(',', $uptime[1]); $uptime = $uptime[0].','.$uptime[1]; echo "\n<h3>Server Uptime</h3>\n<h4>" . $uptime . "</h4>\n"; /* Output html code and result from above lines */ ?> </body> </html>
Comment