Home :: Programming :: Solutions
Creation date:
PHP Solutions
PHP TinyAds
PHP TinyAds is a small control application to control banners on your site. The program consists of two files:
tinyAds.php - this is a program
ads.xml - the file of banners catalogue
This PHP script is an XML based advertising module. Each advertisement is shown with frequency, that you assign in ads.xml file.ads.xml consists of the following items:
<item>
<title>here is your alternate text</title>
<img>here comes your image src location</img>
<url>here is your href url</url>
<weight>the frequency of this item</weight>
</item>
Parameter in <weight> tag is the frequency, in which this advertisement will be shown. The weight is an integer number, that is the showing frequency of this banner between all ads. The module calculates overall weight and the frequency for every banner item. The greater the weight the frequent the advertisement block. You can assign the values to <img>, <title> and <url> separately or use advert block. In this case U must assign it to <url> parameter and leave <title> and <img> tags blank. You can use it for Commission Junction banners too.
Note that in this case U must use html version of banners, not JavaScript. Here is the example of ads.xml file. All url and image data are dummy.
<?xml version="1.0" encoding="utf-8"?>
<catalog>
<item>
<title>Advert block</title>
<img>some_banner.gif</img>
<url>someadvertisementsite.info/go/ads</url>
<weight>1</weight>
</item>
<item>
<title></title>
<img></img>
<url><![CDATA[
<a href="http://www.kqzyfj.com/click-3820618-10603636" target="_top">
<img src="http://www.awltovhc.com/image-3820618-10603636" width="468" height="60" alt="AbeBooks Christmas Bookshop - Signed books for eve" border="0"/></a> ]]>
</url>
<weight>3</weight>
</item>
<item>
<title>other</title>
<img></img>
<url><![CDATA[
<a href="http://www.tkqlhce.com/click-3820618-10577325" target="_top">
<img src="http://www.awltovhc.com/image-3820618-10577325" width="468" height="60" alt="Save up to 60% on textbooks and 50% on eBooks." border="0"/></a> ]]>
</url>
<weight>1</weight>
</item>
</catalog>
The first item has normal image, url and alt text that you may assign. The second and third items are the ads block from Commission Junction network. For such blocks <img> tag mus be left empty. The <title> tag in this case is ignored and can hold anything. If you insert the code with tags, like mine, you have insert it between <![CDATA[ and ]]> block in order to escape the tags in content from parsing with XML.
author: Jafar N.Aliyev (Jsoft)
Source: Included (PHP)
Version: 1.0
License: Free
RSS Parser with cache
If you use RSS parser and include many RSS feeds to your page, every time when a user opens your page, your site will download the same feed from other site. If the downloading site is down you gonna get error or PHP Warning on your page. Our RSS parser has cache to hold all RSS feeds untill the Time To Live is expire. It downloads and creates unique name for each feed to store in \cache catalog.
rss_jparser updates cached feeds in following maner. In first read it stores the feed. Then in every attempt to read the feed it reads from locally stored cache and checks the value of <ttl> tag. If the time has gone, it connects to source and updates the cache. If <ttl> tag is absent on RSS feed it uses the DEFAULT_TTL parameter set by you. I use 1 day for default ttl. Note, that this parameter is given on seconds, but RSS <ttl> uses minutes to measure the time, elapsed from last update. If the source site is down at the time of request it keeps the cache and returns the last feed until the site will be accessible. You can restrict the count of feeds with $max_count parameter of parse_rss function. The benefits of rss_jparser:
- it prevents you from downloading the tremendous RSS feeds every time;
- it protects you from error message when callee site is unreachable;
- you can control the quantity of feeds
Package contains the following modules:
rss_parser.php - the main program, cache creator and checker
rss_php.php - the thirdparty parser from rssphp.net
example.php - an example program
author: Jafar N.Aliyev (Jsoft)
Source: Included (PHP)
Version: 1.0
License: Free
Cron Job on PHP
This sample shows how to write and set Cron Job on PHP. date.php is an example script that writes the current day to the given file via FTP access. It forms the result as HTML file and returns as page. But we ignore it and only in case of failure send it as error message to the given mail to inform the administrator.
To set this script as Cron Job open your cPanel or other Admin Panel that gives the ability to set Cron Job and add new job. Specify the time and email address where to send the result.
To ignore the succeed messages redirect the result to null
lynx -dump http://yourhostname.net/date.php > /dev/null
If the job succeeds no report will be sent to e-mail, on error it sends the log to the email shown in cron.
author: Jafar N.Aliyev (Jsoft)
Source: Included (PHP)