Generate Sitemap for Google and other Search Engines using PHP
Google has a Sitemap generator written using Python. Python is a great language, but I prefer PHP. I took the basic idea of the Sitemap generator and converted it into a solution more suitable for my application needs. If you are looking for a way to easily create a Sitemap for submitting to Google and other search engines, you have come to the right place. I call this one cron_gen_sm.php.
You can download cron_gen_sm.php
here. Also, you
can view partial code below.
You can upload cron_gen_sm.php to your current cron job script folder or anywhere else on your server. I prefer to send the Sitemap to Google once a week because I am not updating the links very often.
If you have questions or comments about this script, please use the live chat feature on the website here or send an email to the address on the contact page. This is not the only way to generate a Sitemap for Google, but it works well. Feel free to recommend revisions.
Send Email for HTTP Error Codes 401, 403, 404, 500 using Perl CGI-bin
Ever wondered how long one of your websites has been down, but you didn't check your error_log file? There is an easy way to be alerted when there is an error on your website, such as 404 Not Found, 500 Internal Server Error, and others. I have made a simple CGI script using Perl that sends an email to the webmaster saying what page caused the error, what the error code is, and what the visitor's IP address is. I call it sendmail.pl.
You can download sendmail.pl
here or copy and the code below and
paste it in your own file.
Take your copy of sendmail.pl and upload it to your cgi-bin directory. Use FTP, SSH, or anything similar to change it to an executable file. For example, in SSH you can type "chmod +x sendmail.pl" without the quotes. It sends an email and then forwards to the error document you specify. The default is error.html.
Once this is taken care of, modify .htaccess in your HTTP root directory (public_html), or create it if it does not exist. You can download a sample of .htaccess here. Be sure to save it as "All Files" for it to work properly. Inside .htaccess, place the following lines in it:
- ErrorDocument 401 /cgi-bin/sendmail.pl
- ErrorDocument 403 /cgi-bin/sendmail.pl
- ErrorDocument 404 /cgi-bin/sendmail.pl
- ErrorDocument 500 /cgi-bin/sendmail.pl
You can use whatever error codes you choose, but these are what I am using in this example. Using these codes, all Unauthorized, Forbidden, Not Found, and Internal Server Error requests will execute the script.
Be sure to have your error.html (or similar) document on your server because the script will forward to it after the script sends the email. You can configure the error document's name in the Perl script, as well as the webmaster's email address. To see my error.html, click here.
To review, you should have 3 files on your web server: cgi-bin/sendmail.pl, .htaccess, and error.html. All of these files work together to produce the webmaster's alert and keep the visitors from seeing the default error documents.
If you have questions or comments about this script, please use the live chat feature on the website here or send an email to the address on the contact page. This is not the only way to alert the webmaster, but it works well. Feel free to recommend revisions.