 | | ^ click above ^ |
WebProWorld
Dev Forum |
Images disappearing+ code too ??
I have a site that i am working on www.yeclaserve.com/scanex
At the bottom of the left hand column is a screenshot image.gif, when i view it on my laptop this image file disappears, I view source and the url to the image file is also gone. I download the index.htm file to my laptop and view source without opening the browser and all code is there.
This says to me that the browser (for some strange reason)is stripping the reference to this file as it parses the html...
PHP Site Search
I just finished my "beta" site search for one of the sites I maintain. I would appreciate it if you all could check it out and let me know what you think.
You have to go to the site map, http://www.homesearch-md.com/site_map.html to use the search, and it's on the bottom of the page. Below is the php source that searches my database and arranges the results.
I am looking for feedback on the results mainly, so anything you have to say works...
Graphs from data: PHP or ColdFusion?
I am developing a site that basically collects data from what visitors look for in other websites (what they search for, which categories of products have the highest demand, which products are searched for that we don't have...) Then, I want to present all this data graphically, so that one could see trends, evolution in time and combine different criteria in order to predict future demand.
I have a lot of experience with ASP and I am starting to develop one site in PHP and another with ColdFusion. I have been checking and it seems easier to build such a site with ColdFusion (which is able to draw statistical graphs out of data in MySQL tables, for instance, with no external or additional components in the server side) or with PHP...
|
|
|
|
Recent Articles |
Compression And Other Server-Side Enhancements
While our twenty tips for code optimization in Part I began with the developer's source code, our discussion of cache control in Part II led us steadily towards the server-side in our quest for maximum Web site performance. If you are willing to put on your admin hat for a while, we will now see what other server-side changes can be made in order to speed up site delivery, starting with HTTP compression.
Optimal Cache Control
Now that our code has been optimized in order to send as little data as possible, in Part II, we will focus primarily on sending that data as infrequently as possible by means of better utilization of caching on the Web. Once you start to design your sites with an eye towards effective caching control, you will dramatically reduce page load times for your users - particularly your most loyal, repeat visitors - as well as lower your overall bandwidth consumption and free up your server resources.
JavaScript/File-Related Optimization
More and more sites rely on JavaScript to provide navigational menus, form validation, and a variety of other useful things. Not surprisingly, much of this code is quite bulky and begs for optimization. Many of the techniques for JavaScript optimization are similar to those used for markup and CSS. However, JavaScript optimization must be performed far more carefully because, if it is done improperly, the result is not just a visual distortion, but potentially a broken page! We start with the most obvious and easiest improvements and then move on to ones that require greater care.
Markup/CSS Optimization
Typical markup is either very tight, hand-crafted and standards-focused, filled with comments and formatting white space, or it is bulky, editor-generated markup with excessive indenting, editor-specific comments often used as control structures, and even redundant or needless markup or code. Neither case is optimal for delivery. The following tips are safe and easy ways to decrease file size:
Client-Side Code Optimization
Let's begin by taking a look at client-side code optimization -- the easiest and generally cheapest to implement of the three site acceleration techniques. |
|
|
|
12.07.04
Track Your Visitors, Using PHP
By Dennis Pallett
There are many different traffic analysis tools, ranging from simple counters to complete traffic analyzers.
Although there are some free ones, most of them come with a price tag. Why not do it yourself? With PHP, you can easily create a log file within minutes. In this article I will show you how!
Getting the information
The most important part is getting the information from your visitor. Thankfully, this is extremely easy to do in PHP (or any other scripting language for that matter). PHP has a special global variable called $_SERVER which contains several environment variables, including information about your visitor. To get all the information you want, simply use the following code:
// Getting the information
$ipaddress = $_SERVER['REMOTE_ADDR'];
$page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}";
$page .= iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", "");
$referrer = $_SERVER['HTTP_REFERER'];
$datetime = mktime();
$useragent = $_SERVER['HTTP_USER_AGENT'];
$remotehost = @getHostByAddr($ipaddress);
As you can see the majority of information comes from the $_SERVER variable. The mktime() (http://nl2.php.net/mktime) and getHostByAddr() (http://nl2.php.net/manual/en/function.gethostbyaddr.php) functions are used to get additional information about the visitor.
Note: I used a function in the above example called iif(). You can get this function at http://www.phpit.net/code/iif-function.
Logging the information
Now that you have all the information you need, it must be written to a log file so you can later look at it, and create useful graphs and charts. To do this you need a few simple PHP function, like fopen (http://www.php.net/fopen) and fwrite (http://www.php.net/fwrite).
The below code will first create a complete line out of all the information. Then it will open the log file in "Append" mode, and if it doesn't exist yet, create it.
If no errors have occurred, it will write the new logline to the log file, at the bottom, and finally close the log file again.
// Create log line
$logline = $ipaddress . '|' . $referrer . '|' . $datetime . '|' . $useragent . '|' . $remotehost . '|' . $page . "\n";
// Write to log file:
$logfile = '/some/path/to/your/logfile.txt';
// Open the log file in "Append" mode
if (!$handle = fopen($logfile, 'a+')) {
      die("Failed to open log file");
}
// Write $logline to our logfile.
if (fwrite($handle, $logline) === FALSE) {
      die("Failed to write to log file");
}
fclose($handle);
Now you've got a fully function logging module. To start tracking visitors on your website simply include the logging module into your pages with the include() function (http://www.php.net/include):
include ('log.php');
Okay, now I want to view my log file
After a while you'll probably want to view your log file. You can easily do so by simply using a standard text editor (like Notepad on Windows) to open the log file, but this is far from desired, because it's in a hard-to-read format.
Let's use PHP to generate useful overviews for is. The first thing that needs to be done is get the contents from the log file in a variable, like so:
// Open log file
$logfile = "/some/path/to/your/logfile.txt";
if (file_exists($logfile)) {
      $handle = fopen($logfile, "r");
      $log = fread($handle, filesize($logfile));
      fclose($handle);
} else {
      die ("The log file doesn't exist!");
}
Now that the log file is in a variable, it's best if each logline is in a separate variable. We can do this using the explode() function (http://www.php.net/explode), like so:
// Seperate each logline
$log = explode("\n", trim($log));
After that it may be useful to get each part of each logline in a separate variable. This can be done by looping through each logline, and using explode again:
// Seperate each part in each logline
for ($i = 0; $i < count($log); $i++) {
     $log[$i] = trim($log[$i]);
     $log[$i] = explode('|', $log[$i]);
}
Now the complete log file has been parsed, and we're ready to start generating some interesting stuff.
The first thing that is very easy to do is getting the number of pageviews. Simply use count() on the $log array, and there you have it;
echo count($log) . " people have visited this website.";
Read the rest of the article.
*Previously published at ArticleCity.com
About the Author:
Dennis Pallett is a young tech writer, with much experience in ASP, PHP and other web technologies. He enjoys writing, and has written several articles and tutorials. To find more of his work, look at his websites at http://www.phpit.net, http://www.aspit.net and http://www.ezfaqs.com.
|