PHP Block How-To
- Monday, December 31 2001 @ 01:04 pm EST
- Contributed by: Tony
- Views: 15,896
PHP Blocks give you the power of letting a Geeklog block execute some code to generate dynamic output. To make it more secure, you are not allowed to add PHP code directly to the content of your block but, instead, must add a function to your /path/to/geeklog/lib-custom.php and then assign your PHP block to execute that function. To keep someone from executing arbitrary PHP functions we require PHP block functions to start with the phpblock_ prefix.
Once your function is called you have the full power of PHP at your disposal to do what ever you little heart desire.
Example
To drive the power of this home, let's try a real-world example that I recently added to Iowa Outdoors. This example will put a "refer this site" form on your site so others can refer your Geeklog website to others.
1) First, code the function in your lib-custom.php (remember function name must start with phpblock_ prefix). You can get the code for this how-to here.
2) Create the PHP block via the Geeklog block administration page:
Other Information
The function in the code-sample stores the number of referrals made in the database. If you want to ever find out how many referrals you have or want to add this to your stats.php page the SQL you would need is:
SELECT value FROM vars WHERE name = 'num_site_referrals'
Was this easy enough to follow?