Joomla PHP Pages

Joomla PHP Pages Component allows you to create simple PHP pages and link them to the Joomla Menu. This allows you to easily create a custom page without having to create a whole component. It is similar to the PHP Module for Joomla, except that it is a full Component.

Joomla PHP Component Compatibility
The Joomla PHP Component is compatible with Joomla1.0 and Joomla1.5. You need to download the correct version for your Joomla version as there is no backward compatibility between versions.

Joomla PHP Component is currently listed on the IBM vulnerabilities database. However, this listing is incorrect. There is NO SQL vulnerability in the PHP Component. However, since the PHP Component allows you to embed PHP inside Joomla, please make sure you use secure code. (Please see "Secure PHP programming" for some pointers)

Download Joomla PHP Component

Joomla PHP Component Installation

  • Download the latest version of Joomla PHP Component from our Joomla PHP Extensions Download.
  • In your Joomla Administration Panel, go to Installers -> Components and upload the Joomla PHP Component Installation package you downloaded.

Creating a custom PHP page

  • In the Joomla Admin Panel visit:
    Components -> PHP Pages -> Manage Files -> New
  • Fill in the File name, and then Click the Next button.
  • Fill in the PHP code for the File and click Save.
  • Now that you have a file, you need to it from the menu.
    Menu -> Main Menu -> New -> Component -> PHP Pages
  • Choose the PHP Pages component and click Apply in order to view the parameters.
  • Choose the PHP file you created and Publish the Menu Item.

Frequently Asked Questions

Do I have to wrap the PHP code in special tags? No, you can use the regular PHP tags directly. eg:

<?php phpinfo(); ?>
will display the PHP information.

Can I use predefined Joomla variables? Yes, but you first have to declare them as globals. eg:

global $mainframe;

Can I include PHP files? Yes, but make sure you use the full path to the PHP files. It's just easier.
Example:

Joomla 1.0
global $mainframe; 
include($mainframe->getCfg('absolute_path').'/components/com_php/files/my_php_file.php');
Joomla 1.5
include(JPATH_ROOT.'/components/com_php/files/my_php_file.php');

Can I use PHP Component with PHP Module? Yes, you can even make them work together if you wanted.

Documentation and Examples:

Here are some examples of PHP code you can use in the Joomla PHP Component.

Example 1: Welcome Message J1.0

Example Snippet: Show a welcome Message to users for Joomla1.0:
<?php

/**
* Custom code for mod_php. 
* copyright: www.fijiwebdesign.com
* Shows a welcome to the logged in user, or vistor, Joomla1.0. 
*/

global $my;

if ($my->id) {
	echo 'Hello, '.$my->username;
} else {
	echo 'Hello, visitor';
}

?>

Example 2: Welcome Message J1.5

Example Snippet: Show a welcome Message to users for Joomla1.5:
<?php

/**
* Custom code for mod_php. 
* copyright: www.fijiwebdesign.com
* Shows a welcome to the logged in user, or vistor, Joomla1.5. 
*/

$User =& JFactory::getUser();

if ($User->id) {
	echo 'Hello, '.$User->username;
} else {
	echo 'Hello, visitor';
}

?>

Example 3: Flickr Photos

Example Snippet: Display Flickr Photos
<?php

/**
* Example of display flickr photos for a tags list
* Requires: allow_url_fopen enabled in php.ini
*/

/**
* Configurations
*/
// the tags to get photos for
$tags = 'fiji';
// number of pics to show
$total = 5;

// main template
$main_template = '
	<!-- photos for: '.$tags.' -->
	<div class="flickr_photos">
		{photo_template}
	</div>
';
// the html template for each photo item/row
$photo_template = '
		<div class="flickr_photo">
			<img src="{img_src}" width="{img_width}" height="{img_height}" alt="{img_alt}" />
			<h4>
				<a href="{url}" target="_blank">{title}</a>
			</h4>
		</div>
';
// css for our photos styling
$css = '
	<style type="text/css">
	
	.flickr_photo {
		background: #cfcfcf;
		text-align: center;
	}
	
	.flickr_photo img {
		border: 1px solid #000;
	}
	.flickr_photo h3 {
		font-size: 100%;
		font-weight: bold;
		margin: 0px;
		padding: 5px;
	}
	
	</style>
';

/**
* End Configurations
* Start Flickr Feed Request and display
*/

$flickr_feed_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags='.rawurlencode($tags).'&format=php';
include($flickr_feed_url);

$photos_html = '';
if (isset($feed['items']) && ($count = count($feed['items']))) {
	$n = $count < $total ? $count : $total;
	for($i = 0; $i < $n; $i++) {
		
		$item = $feed['items'][$i];
		$row_html = $photo_template;
		$repl = $item;
		
		// flickr image is in description, so we have to parse it out
		preg_match("/<img src=\"(.*?)\" width=\"(.*?)\" height=\"(.*?)\" alt=\"(.*?)\" (.*?)\/>/ui", $item['description'], $matches);
		if ($matches) {
			$repl['img_html'] = $matches[0];
			$repl['img_src'] = $matches[1];
			$repl['img_width'] = $matches[2];
			$repl['img_height'] = $matches[3];
			$repl['img_alt'] = $matches[4];
		}
		
		foreach($repl as $name=>$value) {
			$row_html = str_replace('{'.$name.'}', $value, $row_html);
		}
		
		$photos_html .= $row_html;
	}
} else {
	echo 'No photos found for, '.htmlentities($tags);
}

$html = str_replace('{photo_template}', $photos_html, $main_template);

// display
echo $css;
echo $html;


// debug
function dump($obj) {
	echo nl2br(str_replace(' ', ' ', htmlentities(print_r($obj, true))));
}
?>

 

Joomla Downloads

DownloadsDownload our free Joomla! Components, Modules and Plugins.