<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>SitePoint » Learn CSS &#124; HTML5 &#124; JavaScript &#124; Wordpress &#124; Tutorials-Web Development &#124; Reference &#124; Books and More &#187; PHP</title> <atom:link href="http://www.sitepoint.com/category/tech/php/feed/" rel="self" type="application/rss+xml" /><link>http://www.sitepoint.com</link> <description></description> <lastBuildDate>Sun, 27 May 2012 15:59:16 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /> <item><title>Create a Voting Plugin for WordPress</title><link>http://www.sitepoint.com/create-a-voting-plugin-for-wordpress/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=create-a-voting-plugin-for-wordpress</link> <comments>http://www.sitepoint.com/create-a-voting-plugin-for-wordpress/#comments</comments> <pubDate>Mon, 21 May 2012 15:00:36 +0000</pubDate> <dc:creator>Abbas Suterwala</dc:creator> <category><![CDATA[ajax]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[wordpress]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=54290</guid> <description><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2010/06/wordpress-50x50.jpg" class="attachment-thumbnail wp-post-image" alt="Wordpress Logo" title="Wordpress Logo" />Introduction WordPress, as a platform, has moved from only being a blogging platform, to a platform for a wide variety of websites. One major reason for this, is how easily WordPress can be customized and extended. This enables programmers to create far more functional sites than a normal blog. In the following tutorial we are [...]]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2010/06/wordpress-50x50.jpg" class="attachment-thumbnail wp-post-image" alt="Wordpress Logo" title="Wordpress Logo" /><p></p><p><strong>Introduction</strong></p><p>WordPress, as a platform, has moved from only being a blogging platform, to a platform for a wide variety of websites. One major reason for this, is how easily WordPress can be customized and extended. This enables programmers to create far more functional sites than a normal blog. In the following tutorial we are going to create a plugin which will make wordpress an article voting site and also create a widget to display the top voted posts.</p><h2>Creating the Plugin</h2><p>To create a plugin create a file voteme.php in your wp-content/plugins/voteme folder. To create a plugin we have to add the plugin header as follows</p><pre>&lt;?php
/*
Plugin Name: Vote Me
Plugin URI:
Description: This plugin to add vote in posts
Author: Abbas
Version: 0.1
Author URI:
*/</pre><p>We will also define some named constants for our plugin base url, and the plugin path as follows:</p><pre>define('VOTEMESURL', WP_PLUGIN_URL."/".dirname( plugin_basename( __FILE__ ) ) );
define('VOTEMEPATH', WP_PLUGIN_DIR."/".dirname( plugin_basename( __FILE__ ) ) );</pre><p>Also, create a js folder in your voteme folder, and add a file voteme.js file in it.</p><p>The folder structure of the plugin would be as follows.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><p><a
href="http://www.sitepoint.com/?attachment_id=54291" rel="attachment wp-att-54291"><img
class="alignnone size-medium wp-image-54291" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/1-115x43.png" alt="" width="115" height="43" /></a></p><p>We will now enqueue the scripts by with &#8216;wp_enqueue_scripts&#8217; and enqueue our JS file, and localize it to store the WP Ajax url which we will use for our ajax calls.</p><pre>function voteme_enqueuescripts()
	{
		wp_enqueue_script('voteme', VOTEMESURL.'/js/voteme.js', array('jquery'));
		wp_localize_script( 'voteme', 'votemeajax', array( 'ajaxurl' =&gt; admin_url( 'admin-ajax.php' ) ) );
	}
add_action('wp_enqueue_scripts', voteme_enqueuescripts);</pre><p>After this we should be able to see our plugin in the plugin list and we should activate it.</p><p><a
href="http://www.sitepoint.com/?attachment_id=54292" rel="attachment wp-att-54292"><img
class="alignnone size-full wp-image-54292" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/2.png" alt="" width="600" height="123" /></a></p><h2>Adding the vote link to posts</h2><p>Now we will add a link to all the posts displaying the current votes and a link to add the vote by ajax.<br
/> Following is the code</p><pre>function voteme_getvotelink()
{
$votemelink = "";
$post_ID = get_the_ID();
$votemecount = get_post_meta($post_ID, '_votemecount', true) != '' ? get_post_meta($post_ID, '_votemecount', true) : '0';
$link = $votemecount.' &lt;a onclick="votemeaddvote('.$post_ID.');"&gt;'.'Vote'.'&lt;/a&gt;';
$votemelink = '&lt;div id="voteme-'.$post_ID.'"&gt;';
$votemelink .= '&lt;span&gt;'.$link.'&lt;/span&gt;';
$votemelink .= '&lt;/div&gt;';
return $votemelink;
}
function voteme_printvotelink($content)
{
return $content.voteme_getvotelink();
}
add_filter('the_content', voteme_printvotelink);</pre><p>Here, we create a function <code>voteme_getvote</code> link which first gets the current post id and then reads the post meta <code>_votemecount</code> using <code>get_post_meta</code>. We use the post meta <code>_votemecount</code> to store the votes for a particular post. Then we create a link by adding the JavaScript function <code>votemeaddvote</code> on the click of the link. The function <code>votemeaddvote</code> we will see shortly.</p><p>Next, we use the WordPress filter <code>the_content</code> to hook our function to add this link after each post. You will be able to see the number of votes and vote link below each post now.</p><p><a
href="http://www.sitepoint.com/?attachment_id=54293" rel="attachment wp-att-54293"><img
class="alignnone size-full wp-image-54293" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/3.png" alt="" width="600" height="209" /></a></p><h2>Adding votes using Ajax</h2><p>As we have added the vote link to every posts its time we make it functional to actually add votes. The JavaScript function which does the AJAX vote posting is below</p><pre>function votemeaddvote(postId)
{
	jQuery.ajax({
	type: 'POST',
	url: votemeajax.ajaxurl,
	data: {
	action: 'voteme_addvote',
	postid: postId
},
success:function(data, textStatus, XMLHttpRequest){
	var linkid = '#voteme-' + postId;
	jQuery(linkid).html('');
	jQuery(linkid).append(data);
	},
	error: function(MLHttpRequest, textStatus, errorThrown){
		alert(errorThrown);
		}
	});
}</pre><p>This sends an AJAX request to WordPress, and sends the action as <code>voteme_addvote</code> and the post ID. If the AJAX call is successful it just adds the data in the div for that post. If there is an error it will just display the error.</p><p>To handle the AJAX request we will have to create a function as follows</p><pre>function voteme_addvote()
	{
		$results = '';
		global $wpdb;
		$post_ID = $_POST['postid'];
		$votemecount = get_post_meta($post_ID, '_votemecount', true) != '' ? get_post_meta($post_ID, '_votemecount', true) : '0';
		$votemecountNew = $votemecount + 1;
		update_post_meta($post_ID, '_votemecount', $votemecountNew);
		$results.='&lt;div class="votescore" &gt;'.$votemecountNew.'&lt;/div&gt;';
		// Return the String
		die($results);
	}
		// creating Ajax call for WordPress
		add_action( 'wp_ajax_nopriv_voteme_addvote', 'voteme_addvote' );
		add_action( 'wp_ajax_voteme_addvote', 'voteme_addvote' );</pre><p>In function voteme_addvote we get the post ID from the posted data and then get the current vote count for that post. Then we increment the vote by 1 and update the post meta again. Then we create a div with the new vote details and sent that back by using die($results);</p><p>To register this function to handle AJAX request for action: &#8216;voteme_addvote&#8217; using the following wordpress hooks</p><pre>		// creating Ajax call for WordPress
		add_action( 'wp_ajax_nopriv_voteme_addvote', 'voteme_addvote' );
		add_action( 'wp_ajax_voteme_addvote', 'voteme_addvote' );</pre><p>Now we&#8217;ll be able to click the vote link to add the vote on the post with AJAX.</p><p><a
href="http://www.sitepoint.com/?attachment_id=54295" rel="attachment wp-att-54295"><img
class="alignnone size-full wp-image-54295" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/4.png" alt="" width="600" height="220" /></a></p><h2>Customizing WordPress admin to show post votes</h2><p>It would be very convenient for the admin to be able to see the votes on the post edit page. Then from there he would be able to see the post details, and also the vote details on that page.</p><p>To add the vote details we need to add a hook on the filter &#8216;manage_edit-post_columns&#8217; to add the Votes as a column on the post edit page as follows.</p><pre>add_filter( 'manage_edit-post_columns', 'voteme_extra_post_columns' );
function voteme_extra_post_columns( $columns ) {
$columns[ 'votemecount' ] = __( 'Votes' );
return $columns;
}</pre><p>Now we need to provide the value to display for this column. To do this we need to hook into the filter <code>manage_posts_custom_column</code>. When we hook into this filter our function <code>voteme_post_column_row</code> is called and with the post column name. Here we only process out column <code>votemecount</code> and give the value for it. We read the value from our custom column <code>_votemecount</code> and echo it. The complete code for this is as follows.</p><pre>function voteme_post_column_row( $column ) {
	if ( $column != 'votemecount' )
	return;
	global $post;
	$post_id = $post-&gt;ID;
	$votemecount = get_post_meta($post_id, '_votemecount', true) != '' ? get_post_meta($post_id, '_votemecount', true) : '0';
	echo $votemecount;
}
add_action( 'manage_posts_custom_column', 'voteme_post_column_row', 10, 2 );</pre><p>On the post edit page you should be able to see the vote details column.</p><p><a
href="http://www.sitepoint.com/?attachment_id=54296" rel="attachment wp-att-54296"><img
class="alignnone size-full wp-image-54296" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/5.png" alt="" width="600" height="274" /></a></p><h2>Sorting post on basics of votes in WordPress admin</h2><p>It would be convenient for the admin if we make the vote column sortable. He would be able to see the most voted posts and also the least voted posts. To do this first we must make the Vote column clickable for sorting. To do this we hook into the filter <code>manage_edit-post_sortable_columns</code> and add the vote column to it as follows.</p><pre>add_filter( 'manage_edit-post_sortable_columns', 'voteme_post_sortable_columns' );
function voteme_post_sortable_columns( $columns )
{
	$columns[ 'votemecount' ] = votemecount;
	return $columns;
}</pre><p>Then we add a hook onto the <code>load-edit.php</code> hook when we have the order by request for <code>votemecount</code> we merge the sort parameters with</p><pre>'meta_key' =&gt; '_votemecount',
'orderby' =&gt; 'meta_value_num'</pre><p>So that it sorts on the basics of custom column and considers that column as numeric rather than as a string. The code for it is as follows.</p><pre>add_action( 'load-edit.php', 'voteme_post_edit' );
function voteme_post_edit()
{
	add_filter( 'request', 'voteme_sort_posts' );
}
	function voteme_sort_posts( $vars )
{
	if ( isset( $vars['post_type'] ) &amp;&amp; 'post' == $vars['post_type'] )
	{
		if ( isset( $vars['orderby'] ) &amp;&amp; 'votemecount' == $vars['orderby'] )
		{
			$vars = array_merge(
			$vars,
			array(
			'meta_key' =&gt; '_votemecount',
			'orderby' =&gt; 'meta_value_num'
			)
			);
		}
	}
return $vars;
}</pre><p>Now in the admin page the vote column will be clickable and clicking on it will sort the post on the basics of votes.</p><p><a
href="http://www.sitepoint.com/?attachment_id=54297" rel="attachment wp-att-54297"><img
class="alignnone size-full wp-image-54297" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/6.png" alt="" width="600" height="269" /></a></p><h2>Allowing only Registered users to vote</h2><p>We might want that not anyone can vote on the post. We might want to check that only users who are registered on our site will be able to vote. We&#8217;ll control this via creating a setting page for our plugin as follows</p><pre>// Settings
add_action('admin_menu', 'voteme_create_menu');
function voteme_create_menu() {
add_submenu_page('options-general.php','Vote Me','Vote Me','manage_options', __FILE__.'voteme_settings_page','voteme_settings_page');
}
function voteme_settings_page() {
?&gt;
&lt;div class="wrap"&gt;
&lt;?php
global $blog_id;
if( isset( $_POST['votemeoptionssubmit'] ) )
{
update_option( 'votemelogincompulsory' , $_POST[ 'votemelogincompulsory' ] );
}
?&gt;
&lt;div id="settingsform"&gt;
&lt;form id='votemesettingform' method="post" action=""&gt;
&lt;h1&gt;&lt;?php echo 'Vote Me Settings'; ?&gt;&lt;/h1&gt;
&lt;Input type = 'Radio' Name ='votemelogincompulsory' value= 'yes' &lt;?php if( get_option('votemelogincompulsory') == 'yes' ) echo 'checked';?&gt; &gt;User Must be logged in for voting
&lt;br/&gt;
&lt;Input type = 'Radio' Name ='votemelogincompulsory' value= 'no' &lt;?php if( get_option('votemelogincompulsory') != 'yes' ) echo 'checked';?&gt; &gt;User might not be logged in for voting
&lt;br/&gt;&lt;br/&gt;
&lt;p class="submit"&gt;
&lt;input type="submit" id="votemeoptionssubmit" name="votemeoptionssubmit" class="button-primary" value="&lt;?php echo 'Save'; ?&gt;" /&gt;
&lt;/p&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;?php }</pre><p>Here we hook onto <code>admin_menu</code> and create our setting page to show radio buttons for whether to allow voting for registered users only. Then based on the option selected by the admin we update the option <code>votemelogincompulsory</code>. The settings page will look as follows.</p><p><a
href="http://www.sitepoint.com/?attachment_id=54299" rel="attachment wp-att-54299"><img
class="alignnone size-full wp-image-54299" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/7.png" alt="" width="383" height="517" /></a></p><p>Then, update the <code>voteme_getvotelink</code> function to read the option <code>votemelogincompulsory</code> and to show the votelink or the login link depending on the option selected by the user and wthere the user is logged in or no. The code for it is as follows</p><pre>function voteme_getvotelink()
{
	$votemelink = "";
	if( get_option('votemelogincompulsory') != 'yes' || is_user_logged_in() )
	{
		$post_ID = get_the_ID();
		$votemecount = get_post_meta($post_ID, '_votemecount', true) != '' ? get_post_meta($post_ID, '_votemecount', true) : '0';
		$link = $votemecount.' &lt;a onclick="votemeaddvote('.$post_ID.');"&gt;'.'Vote'.'&lt;/a&gt;';
		$votemelink = '&lt;div id="voteme-'.$post_ID.'"&gt;';
		$votemelink .= '&lt;span&gt;'.$link.'&lt;/span&gt;';
		$votemelink .= '&lt;/div&gt;';
	}
else
{
	$register_link = site_url('wp-login.php', 'login') ;
	$votemelink = '&lt;div class="votelink" &gt;'." &lt;a href=".$register_link."&gt;"."Vote"."&lt;/a&gt;".'&lt;/div&gt;';
}
return $votemelink;
}</pre><h2>Creating a widget to display Top voted posts.</h2><p>Now we will create a widget to display the top voted posts. First we create a function called <code>voteme_get_highest_voted_posts</code> which takes the number of posts and then displays those many post in order of the highest voted posts. It also displays the number of vote for each post.</p><pre>function voteme_get_highest_voted_posts($numberofpost)
{
	$output = '';
	$the_query = new WP_Query( 'meta_key=_votemecount&amp;orderby=meta_value_num&amp;order=DESC&amp;posts_per_page='.$numberofpost );
	// The Loop
	while ( $the_query-&gt;have_posts() ) : $the_query-&gt;the_post();
	$output .= '&lt;li&gt;';
	$output .= '&lt;a href="'.get_permalink(). '" rel="bookmark"&gt;'.get_the_title().'('.get_post_meta(get_the_ID(), '_votemecount', true).')'.'&lt;/a&gt; ';
	$output .= '&lt;/li&gt;';
	endwhile;
	wp_reset_postdata();
	return $output;
}</pre><p>Then we create a widget which takes the number of post and the title from the user and uses the abpve function to display the top voted posts.</p><pre>class VoteMeTopVotedWidget extends WP_Widget {
	function VoteMeTopVotedWidget() {
	// widget actual processes
	$widget_ops = array('classname' =&gt; 'VoteMeTopVotedWidget', 'description' =&gt; 'Widget for top voted Posts.' );
	$this-&gt;WP_Widget('VoteMeTopVotedWidget','VoteMeTopVotedWidget', $widget_ops);
}
function form($instance) {
	// outputs the options form on admin
	$defaults = array( 'title' =&gt; 'Top Voted Posts', 'numberofposts' =&gt; '5' );
	$instance = wp_parse_args( (array) $instance, $defaults );
	?&gt;
	&lt;p&gt;
	&lt;label for="&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;"&gt;&lt;?php echo 'Title:'; ?&gt;&lt;/label&gt;
	&lt;input id="&lt;?php echo $this-&gt;get_field_id( 'title' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'title' ); ?&gt;" value="&lt;?php echo $instance['title']; ?&gt;" class="widefat" /&gt;
	&lt;/p&gt;
	&lt;p&gt;
	&lt;label for="&lt;?php echo $this-&gt;get_field_id( 'numberofposts' ); ?&gt;"&gt;&lt;?php echo 'Number of Posts'; ?&gt;&lt;/label&gt;
	&lt;input id="&lt;?php echo $this-&gt;get_field_id( 'numberofposts' ); ?&gt;" name="&lt;?php echo $this-&gt;get_field_name( 'numberofposts' ); ?&gt;" value="&lt;?php echo $instance['numberofposts']; ?&gt;" class="widefat" /&gt;
	&lt;/p&gt;
	&lt;?php
}
function update($new_instance, $old_instance) {
	// processes widget options to be saved
	$instance = $old_instance;
	$instance['title'] = strip_tags( $new_instance['title'] );
	$instance['numberofposts'] = $new_instance['numberofposts'];
	return $instance;
}
function widget($args, $instance) {
	// outputs the content of the widget
	extract( $args );
	$title = apply_filters('widget_title', $instance['title'] );
	echo $before_widget;
	if ( $title )
	echo $before_title . $title . $after_title;
	echo '&lt;ul&gt;';
	echo voteme_get_highest_voted_posts($instance['numberofposts']);
	echo '&lt;/ul&gt;';
	echo $after_widget;
}
}
function voteme_widget_init() {
	// Check for the required API functions
	if ( !function_exists('register_widget') )
	return;
	register_widget('VoteMeTopVotedWidget');
}
add_action('widgets_init', 'voteme_widget_init');</pre><p>The widget will look as follows</p><p><a
href="http://www.sitepoint.com/?attachment_id=54300" rel="attachment wp-att-54300"><img
class="alignnone size-full wp-image-54300" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/8.png" alt="" width="295" height="277" /></a></p><p>On the front, the widget will look as follows</p><p><a
href="http://www.sitepoint.com/?attachment_id=54301" rel="attachment wp-att-54301"><img
class="alignnone size-full wp-image-54301" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/9.png" alt="" width="585" height="239" /></a></p><h2>Conclusion.</h2><p>With custom fields, WordPress makes it easy for us to extend it to use for different purposes. WordPress has good support for AJAX as we have seen in this tutorial. So, happy WordPress development!</p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/create-a-voting-plugin-for-wordpress/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>XSS Attacks, Redis DB, REST, and More</title><link>http://www.sitepoint.com/xss-attacks-redis-db-rest-and-more/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=xss-attacks-redis-db-rest-and-more</link> <comments>http://www.sitepoint.com/xss-attacks-redis-db-rest-and-more/#comments</comments> <pubDate>Wed, 09 May 2012 05:25:33 +0000</pubDate> <dc:creator>Timothy Boronczyk</dc:creator> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=54470</guid> <description><![CDATA[<img
width="50" height="15" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/03/phpmaster-50x15.png" class="attachment-thumbnail wp-post-image" alt="phpmaster" title="phpmaster" />on PHPMaster, we present tutorials on protecting yourself from cross-site scripting attacks, using Redis with the Predis library, understanding REST, using an Access database with PHP, and working with text and CSV files. Be sure to visit phpmaster.com for more great articles!]]></description> <content:encoded><![CDATA[<img
width="50" height="15" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/03/phpmaster-50x15.png" class="attachment-thumbnail wp-post-image" alt="phpmaster" title="phpmaster" /><p></p><h2><a
href="http://phpmaster.com/php-security-cross-site-scripting-attacks-xss/">PHP Security: Cross-site Scripting Attacks (XSS)</a></h2><p>Every PHP programmer has the responsibility to understand how attacks can be carried out against their code to exploit possible security vulnerabilities. Learn about cross-site scripting (XSS) attacks and how you can prevent them in your PHP scripts.</p><hr
/><h2><a
href="http://phpmaster.com/an-introduction-to-redis-in-php-using-predis/">An Introduction to Redis in PHP Using Predis</a></h2><p>Redis is an open-source data structure server with an in-memory data set that does much more than simple key/value storage. This article introduces you to some of the basic yet powerful commands that Redis has to offer using the Predis library.</p><hr
/><h2><a
href="http://phpmaster.com/rest-can-you-do-more-than-spell-it-1/">REST: Can you do more than spell it?</a></h2><p>Though you&#8217;ll often see the words &#8220;REST&#8221; and &#8220;architecture&#8221; together, REST is not a specific architecture. This four-part series introduces you to REST, a set of principles that define how a server and client can communicate with each other (and external resources) in a straightforward and robust manner.</p><hr
/><h2><a
href="http://phpmaster.com/using-an-access-database-with-php/">Using an Access database with PHP</a></h2><p>Sometimes a client will already have a database and ask that we make it available on the Web, and sometimes that database is in Access. Never fear, for PHP can easily work with Access databases using an ODBC driver. Learn the essential elements you&#8217;ll need to put an existing Access database online.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><hr
/><h2><a
href="http://phpmaster.com/working-with-files-in-php/">Working with Files in PHP</a></h2><p>You&#8217;re familiar with databases such as MySQL and Access, but data can also be stored in files. This article gives you an introduction into working with text and CSV files, as well as find out information about the files (such as permissions and the last time it was modified).</p><hr
/> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/xss-attacks-redis-db-rest-and-more/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Watch Kevin Yank Introduce his NEW book &#8220;PHP &amp; MYSQL: Novice to Ninja&#8221;</title><link>http://www.sitepoint.com/watch-kevin-yank-introduce-his-new-book-php-mysql-novice-to-ninja/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=watch-kevin-yank-introduce-his-new-book-php-mysql-novice-to-ninja</link> <comments>http://www.sitepoint.com/watch-kevin-yank-introduce-his-new-book-php-mysql-novice-to-ninja/#comments</comments> <pubDate>Thu, 03 May 2012 05:42:39 +0000</pubDate> <dc:creator>Mick Gibson</dc:creator> <category><![CDATA[Open Source]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[PHP & MySQL News & Interviews]]></category> <category><![CDATA[PHP & MySQL Reviews and Apps]]></category> <category><![CDATA[PHP & MySQL Tutorials]]></category> <category><![CDATA[Server Side Coding]]></category> <category><![CDATA[Server Side Essentials]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=54224</guid> <description><![CDATA[<img
width="50" height="30" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/Screen-shot-2012-05-03-at-3.37.51-PM-50x30.png" class="attachment-thumbnail wp-post-image" alt="Screen shot 2012-05-03 at 3.37.51 PM" title="Screen shot 2012-05-03 at 3.37.51 PM" />&#8221; &#8230; Just as PHP and MySQL have grown from the young upstarts of the web development world into mature, stable platforms for billion-dollar businesses, this book that I’ve been writing again and again for over a decade has grown up &#8230; It’s time to write PHP like the big kids do…&#8221;  This is how Kevin Yank [...]]]></description> <content:encoded><![CDATA[<img
width="50" height="30" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/05/Screen-shot-2012-05-03-at-3.37.51-PM-50x30.png" class="attachment-thumbnail wp-post-image" alt="Screen shot 2012-05-03 at 3.37.51 PM" title="Screen shot 2012-05-03 at 3.37.51 PM" /><p></p><p><em>&#8221; &#8230; Just as PHP and MySQL have grown from the young upstarts of the web development world into mature, stable platforms for billion-dollar businesses, this book that I’ve been writing again and again for over a decade has grown up &#8230; It’s time to write PHP like the big kids do…&#8221; </em></p><p>This is how Kevin Yank describes the 5th edition of his just-released book &#8220;<a
href="http://www.sitepoint.com/launch/d724a6">PHP &amp; MYSQL: Novice to Ninja</a>&#8220;</p><p>Watch Kevin as he introduces you to his NEW book!</p><p><iframe
src="http://player.vimeo.com/video/41422400?byline=0&amp;portrait=0" frameborder="0" width="600" height="338"></iframe></p><p><strong>As part of the launch of Kevin&#8217;s book, it&#8217;s now on special with &#8211; <a
href="http://www.sitepoint.com/launch/d724a6 ">SAVINGS of up to 50%</a></strong></p><p>&nbsp;</p><p>&nbsp;</p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/watch-kevin-yank-introduce-his-new-book-php-mysql-novice-to-ninja/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>Sneak Peek at Kevin Yank&#8217;s New Book &#8216;PHP &amp; MYSQL: Novice to Ninja&#8217;</title><link>http://www.sitepoint.com/sneak-peek-of-kevin-yanks-new-php-mysql-book/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sneak-peek-of-kevin-yanks-new-php-mysql-book</link> <comments>http://www.sitepoint.com/sneak-peek-of-kevin-yanks-new-php-mysql-book/#comments</comments> <pubDate>Thu, 26 Apr 2012 06:01:19 +0000</pubDate> <dc:creator>Mick Gibson</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[PHP & MySQL News & Interviews]]></category> <category><![CDATA[PHP & MySQL Reviews and Apps]]></category> <category><![CDATA[PHP & MySQL Tutorials]]></category> <category><![CDATA[Server Side Coding]]></category> <category><![CDATA[Server Side Essentials]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[Web Tech]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=53890</guid> <description><![CDATA[<img
width="50" height="43" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/04/php-mysql-50x43.png" class="attachment-thumbnail wp-post-image" alt="php-mysql" title="php-mysql" />Kevin Yank&#8217;s done it again! He&#8217;s just completed a new 2012 edition of his best-selling book (Build Your Own Database Driven Web Site, 4th Edition) which is now titled - PHP &#38; MySQL: Novice to Ninja. And, today you can: Take a sneak peek inside the book (with an excerpt from the Chapter 3 -Introducing PHP) Order the [...]]]></description> <content:encoded><![CDATA[<img
width="50" height="43" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/04/php-mysql-50x43.png" class="attachment-thumbnail wp-post-image" alt="php-mysql" title="php-mysql" /><p></p><p><a
href="http://www.sitepoint.com/?attachment_id=53906" rel="attachment wp-att-53906"><img
class="alignright size-full wp-image-53906" title="phpmysql5-cover" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/04/phpmysql5-cover.jpg" alt="phpmysql5-cover" width="200" height="267" /></a>Kevin Yank&#8217;s done it again! He&#8217;s just completed a new 2012 edition of his best-selling book (<em>Build Your Own Database Driven Web Site, 4th Edition</em>) which is now titled - <em>PHP &amp; MySQL: Novice to Ninja. </em>And, today you can:</p><ul><li><strong>Take a sneak peek inside the book</strong> (with an excerpt from the Chapter 3 -<em>Introducing PHP</em>)</li><li><strong><a
href="#pre-order">Order the book</a></strong>, and SAVE up to 50%</li></ul><div>Now let&#8217;s jump into the excerpt from the book. Over to you Kev &#8230;</div><div></div><h2>Introducing PHP</h2><p>PHP is a <strong>server-side language</strong>. This concept may be a little difficult to grasp, especially if you’ve only ever designed websites using client-side languages like HTML, CSS, and JavaScript.</p><p>A server-side language is similar to JavaScript in that it allows you to embed little</p><p>programs (scripts) into the HTML code of a web page. When executed, these programs give you greater control over what appears in the browser window than HTML alone can provide. The key difference between JavaScript and PHP is the stage of loading the web page at which these embedded programs are executed.</p><p>Client-side languages like JavaScript are read and executed by the web browser after downloading the web page (embedded programs and all) from the web server. In contrast, server-side languages like PHP are run by the web <em>server</em>, before sending the web page to the browser. Whereas client-side languages give you control over how a page behaves once it’s displayed by the browser, server-side languages let you generate customized pages on the fly before they’re even sent to the browser.</p><p>Once the web server has executed the PHP code embedded in a web page, the result takes the place of the PHP code in the page. All the browser sees is standard HTML code when it receives the page, hence the name “server-side language.” Let’s look back at the today.php example presented in Chapter 1:</p><pre>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Today&amp;rsquo;s Date&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;Today&amp;rsquo;s date (according to this web server) is
<strong>&lt;?php </strong>
<strong>echo date('l, F jS Y.'); </strong>
<strong>?&gt; </strong>
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>Most of this is plain HTML except the line between &lt;?php and ?&gt; is PHP code. &lt;?php marks the start of an embedded PHP script and ?&gt; marks its end. The web server is asked to interpret everything between these two delimiters and convert it to regular HTML code before it sends the web page to the requesting browser. The browser is presented with the following:</p><p>Notice that all signs of the PHP code have disappeared. In its place the output of the script has appeared, and it looks just like standard HTML. This example demonstrates several advantages of server-side scripting:</p><pre>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Today&amp;rsquo;s Date&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;Today&amp;rsquo;s date (according to this web server) is
<strong>Sunday, April 1st 2012. </strong>&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>Notice that all signs of the PHP code have disappeared. In its place the output of the script has appeared, and it looks just like standard HTML. This example demonstrates several advantages of server-side scripting:</p><h3>No browser compatibility issues</h3><p>PHP scripts are interpreted by the web server alone, so there’s no need to worry about whether the language features you’re using are supported by the visitor’s browser.</p><h3>Access to server-side resources</h3><p>In the above example, we placed the date according to the web server into the web page. If we had inserted the date using JavaScript, we’d only be able to display the date according to the computer on which the web browser was running. Granted, there are more impressive examples of the exploitation of server-side resources, such as inserting content pulled out of a MySQL database (<em>hint, hint …</em>).</p><h3>Reduced load on the client</h3><p>JavaScript can delay the display of a web page significantly (especially on mobile devices!), as the browser must run the script before it can display the web page. With server-side code this burden is passed to the web server, which you can make as beefy as your application requires (and your wallet can afford).</p><h2>Basic Syntax and Statements</h2><p>PHP syntax will be very familiar to anyone with an understanding of JavaScript, C, C++, C#, Objective-C, Java, Perl, or any other C-derived language. But if these languages are unfamiliar to you, or if you’re new to programming in general, there’s no need to worry about it.</p><p>A PHP script consists of a series of commands, or <strong>statements</strong>. Each statement is an instruction that must be followed by the web server before it can proceed to the next instruction. PHP statements, like those in the aforementioned languages, are always terminated by a semicolon (;).</p><p>This is a typical PHP statement:</p><pre>echo 'This is a &lt;strong&gt;test&lt;/strong&gt;!';</pre><p>This is an echo statement, which is used to generate content (usually HTML code) to send to the browser. An echo statement simply takes the text it’s given and inserts it into the page’s HTML code at the position of the PHP script where it was contained.</p><p>In this case, we’ve supplied a string of text to be output: &#8216;This is a &lt;strong&gt;test&lt;/strong&gt;!&#8217;. Notice that the string of text contains HTML tags (&lt;strong&gt; and &lt;/strong&gt;), which is perfectly acceptable. So, if we take this statement and put it into a complete web page, here’s the resulting code:</p><pre>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Today&amp;rsquo;s Date&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;<strong>&lt;?php echo 'This is a &lt;strong&gt;test&lt;/strong&gt;!'; ?&gt;</strong>&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>If you place this file on your web server and then request it using a web browser, your browser will receive this HTML code:</p><pre>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Today&amp;rsquo;s Date&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;<strong>This is a &lt;strong&gt;test&lt;/strong&gt;!</strong>&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>The today.php example we looked at earlier contained a slightly more complex echo statement:</p><pre>echo date('l, F jS Y.');</pre><p>Instead of giving echo a simple string of text to output, this statement invokes a <strong>built-in function </strong>called date and passes <em>it </em>a string of text: &#8216;l, F jS Y.&#8217;. You can think of built-in functions as tasks that PHP knows how to do without you needing to spell out the details. PHP has many built-in functions that let you do everything, from sending email to working with information stored in various types of databases.</p><p>When you invoke a function in PHP—that is, ask it to do its job—you’re said to be <strong>calling </strong>that function. Most functions <strong>return </strong>a value when they’re called; PHP then behaves as if you’d actually just typed that returned value instead in your code. In this case, our echo statement contains a call to the date function, which returns the current date as a string of text (the format of which is specified by the text string in the function call). The echo statement therefore outputs the value returned by the function call.</p><p>You may wonder why we need to surround the string of text with both parentheses ((…)) and single quotes (&#8216;…&#8217;). As in SQL, quotes are used in PHP to mark the beginning and end of strings of text, so it makes sense for them to be there. The parentheses serve two purposes. First, they indicate that date is a function that you want to call. Second, they mark the beginning and end of a list of <strong>arguments </strong>that you wish to provide, in order to tell the function what you want it to do.</p><p>In the case of the date function, you need to provide a string of text that describes the format in which you want the date to appear. Later on, we’ll look at functions that take more than one argument, and we’ll separate those arguments with commas. We’ll also consider functions that take no arguments at all. These functions will still need the parentheses, even though there will be nothing to type between them.</p><p>&#8212;</p><p>Fantastic, thanks Kevin for sharing that!<a
href="http://www.sitepoint.com/?attachment_id=53914" rel="attachment wp-att-53914"><img
class="alignright size-full wp-image-53914" title="phpmysql5-whats-inside" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/04/phpmysql5-whats-inside.jpg" alt="phpmysql5-whats-inside" width="165" height="450" /></a></p><p>The good news is there&#8217;s loads more practical and hands-on examples just like this in the 500+ pages of the book. Which covers:</p><ul><li><strong>Tutorials</strong>: Easy-to-follow tutorials with downloadable code examples</li><li><strong>Installation:</strong> Instructions for PHP &amp; MySQL on Windows, Mac OS X, and Linux</li><li><strong>PHP coding</strong>: Learning the correct PHP syntax</li><li><strong>Database design</strong>: Mastering SQL database design</li><li><strong>Object Oriented Programming</strong> (OOP): Crash course in OOP principles.</li><li><strong>Building a CMS</strong>: Step-by-step guide to creating a CMS.</li><li><strong>Shopping Carts</strong>: Developing an e-commerce cart from scratch.<a
name="pre-order"></a></li><li><strong>Latest technologies</strong>: Updated for Windows 7, Mac OS X Lion, and the latest versions of PHP, MySQL, phpMyAdmin, XAMPP, MAMP, and HTML5.</li></ul><p>Order your copy now:</p><ul><li><strong><a
href="http://www.sitepoint.com/launch/d724a6 " target="_blank">PRINT Book + Digital EPACK Bundle &#8211; for $34</a></strong>  <strong>(SAVE 50%)</strong></li><li><a
style="font-weight: bold;" href="http://www.sitepoint.com/launch/d724a6 " target="_blank">Digital EPACK (pdf, epub, mobi) &#8211; for $17</a>  <strong>(SAVE 42%)</strong></li></ul><p>That&#8217;s it. Enjoy, and as always, we&#8217;d love to hear all your thoughts and comments.</p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/sneak-peek-of-kevin-yanks-new-php-mysql-book/feed/</wfw:commentRss> <slash:comments>14</slash:comments> </item><div><div
class="post_box two_ads" style="float:left;padding-left:2px;"><div
id='div-gpt-ad-1328645237920-0' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328645237920-0'); });</script> </div></div></div><div
class="clear">&nbsp;</div> <item><title>Deploying Apps with Phing, PHP Presentations, Virtual Proxies, and More</title><link>http://www.sitepoint.com/deploying-apps-with-phing-php-presentations-virtual-proxies-and-more/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=deploying-apps-with-phing-php-presentations-virtual-proxies-and-more</link> <comments>http://www.sitepoint.com/deploying-apps-with-phing-php-presentations-virtual-proxies-and-more/#comments</comments> <pubDate>Tue, 24 Apr 2012 17:00:38 +0000</pubDate> <dc:creator>Timothy Boronczyk</dc:creator> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=53935</guid> <description><![CDATA[<img
width="50" height="15" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/03/phpmaster-50x15.png" class="attachment-thumbnail wp-post-image" alt="phpmaster" title="phpmaster" />Over on PHPMaster we've covered tutorials on deploying your apps with Phing, how to give your first PHP presentation,  maintaining your server from the command line, and plenty more.]]></description> <content:encoded><![CDATA[<img
width="50" height="15" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/03/phpmaster-50x15.png" class="attachment-thumbnail wp-post-image" alt="phpmaster" title="phpmaster" /><p></p><h2><a
href="http://phpmaster.com/deploy-and-release-your-applications-with-phing/">Deploy and Release your Applications with Phing</a></h2><p>In a previous article on PHPMaster, you gained a basic understanding of Phing. In this article, you&#8217;ll use that knowledge to write your own boilerplate build file, which can be customized and reused in your real-world applications.</p><hr
/><h2><a
href="http://phpmaster.com/giving-your-first-php-presentation/">Giving Your First PHP Presentation</a></h2><p>It&#8217;s public speaking time and you&#8217;re the next one up! In this article, you&#8217;ll learn why presenting PHP can be beneficial, who can present  PHP-related topics (hint: it&#8217;s not just the experts!), and what you can do to make your presentation stand out when you deliver.</p><hr
/><h2><a
href="http://phpmaster.com/maintaining-your-server-with-command-line-php/">Maintaining your Server with Command Line PHP</a></h2><p>Maintaining your Server with Command Line PHP<br
/> When maintaining a server, you need to know how to write scripts and small programs to automate tasks. Two of the biggest advantages of using PHP to write scripts are: you&#8217;re already familiar with the language, and you gain the ability to reuse any code from your previous PHP projects.</p><hr
/><h2><a
href="http://phpmaster.com/intro-to-virtual-proxies-1/">An Intro to Virtual Proxies, Part 1</a></h2><p>One of the most appealing facets of polymorphism is that it&#8217;s applicable in a wide variety of situations. Moreover, while the ability to switch out concrete implementations is a fundamental object-oriented pillar, its use is limited when involving domain objects. In this first piece of a two-part series on virtual proxies, I&#8217;ll be showcasing their use case, and later digging deeper into their complexities.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><hr
/><h2><a
href="http://phpmaster.com/in-my-language-please/">Translating WordPress Themes and Plugins</a></h2><p>WordPress itself is translated into many languages, but this is not the case with themes, plugins, and other front-end customizations. All theme and plugin developers are responsible for adding translation support for their work.. This article will show you how to translate any WordPress theme or plugin by using internationalization and localization methods.</p><hr
/> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/deploying-apps-with-phing-php-presentations-virtual-proxies-and-more/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>6 Skills Every PHP Freelancer Needs, Pragmatic Testing, MySQL, and More</title><link>http://www.sitepoint.com/6-skills-every-php-freelancer-needs-pragmatic-testing-mysql-and-more/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=6-skills-every-php-freelancer-needs-pragmatic-testing-mysql-and-more</link> <comments>http://www.sitepoint.com/6-skills-every-php-freelancer-needs-pragmatic-testing-mysql-and-more/#comments</comments> <pubDate>Tue, 10 Apr 2012 09:09:06 +0000</pubDate> <dc:creator>Timothy Boronczyk</dc:creator> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=53440</guid> <description><![CDATA[It's time to read all the great articles we've just published at PHPMaster, on topics as diverse as testing, software application services, and freelancing, as well as an explanation on how to pump up your SQL.]]></description> <content:encoded><![CDATA[<p></p><h2><a
href="http://phpmaster.com/thoughts-of-a-pragmatic-tester/">Thoughts of a Pragmatic Tester</a></h2><p>Some of us write unit tests, while others choose not to. Indeed, it’s important to test common usage, situations of improper usage, and rare events. But it’s also vital that you write your tests pragmatically, using functional (acceptance) tests for application’s behavior, and unit tests for internal APIs.</p><hr
/><h2><a
href="http://phpmaster.com/an-introduction-to-services/">An Introduction to Services</a></h2><p>Most software applications behave like whimsical babies with an unavoidable &#8220;tendency&#8221; to grow in size and complexity over time. You&#8217;re probably wondering how to tackle the problem without hitting your head against a brick wall. This article managing this, in particular, Services, because it plays nicely with Domain Models, and therefore with Domain-Driven Design.</p><hr
/><h2><a
href="http://phpmaster.com/using-explain-to-write-better-mysql-queries/">Using EXPLAIN to Write Better MySQL Queries</a></h2><p>The EXPLAIN keyword is one of the most powerful tools at your disposal for understanding and optimizing troublesome MySQL queries, but it&#8217;s a sad fact that many developers rarely make use of it. In this article, you&#8217;ll learn what the output of EXPLAIN can be and how to use it to optimize your schema and queries.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><hr
/><h2><a
href="http://phpmaster.com/6-extra-skills-every-php-developer-should-have/">6 Skills Every PHP Freelancer Should Have</a></h2><p>PHP development is hot right now, but there’s also a lot of competition among developers. If you want to make it as an independent PHP developer, you&#8217;ve got to know more than just PHP. These six skills are essential for most freelancers, even more so for PHP developers.</p><hr
/><h2><a
href="http://phpmaster.com/bulletproofing-database-interactions/">Bulletproofing Database Interactions with PHPUnit&#8217;s Database Extension</a></h2><p>If your application is data-intensive, subjecting your CRUD code to a battery of tests is good practice that helps ensure that your application is working correctly. This article will help you get started using PHPUnit&#8217;s Database extension to automate tests for your code that interacts with your database.</p><hr
/> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/6-skills-every-php-freelancer-needs-pragmatic-testing-mysql-and-more/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Validating WordPress Comment Forms with jQuery and a Custom Plugin</title><link>http://www.sitepoint.com/validating-wordpress-comment-forms-with-jquery-and-a-custom-plugin/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=validating-wordpress-comment-forms-with-jquery-and-a-custom-plugin</link> <comments>http://www.sitepoint.com/validating-wordpress-comment-forms-with-jquery-and-a-custom-plugin/#comments</comments> <pubDate>Wed, 04 Apr 2012 21:18:20 +0000</pubDate> <dc:creator>Vladislav Davidzon</dc:creator> <category><![CDATA[jQuery]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[wordpress]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=53078</guid> <description><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2009/09/wordpresslogo-150x150.png" class="attachment-thumbnail wp-post-image" alt="wordpresslogo.png" title="wordpresslogo.png" />In this tutorial Vladislav walks us through how to validate forms in WordPress by creating a simple plugin.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2009/09/wordpresslogo-150x150.png" class="attachment-thumbnail wp-post-image" alt="wordpresslogo.png" title="wordpresslogo.png" /><p></p><p>One of the newest ways that web designers are increasing the usability and accessibility of their websites is by employing a combination of PHP, XHTML, and jQuery programming to validate forms &#8220;on the fly&#8221; as users fill them out. With WordPress, several pieces of information are almost always required in order to post a comment. A user must provide their name, their email address, and the comment itself. Some websites even require that users supply their website information when they post a comment. That&#8217;s a lot to remember, a lot to fill out, and the room for error is pretty big. A standard WordPress installation does not validate forms until a user has already clicked the submit button, meaning they don&#8217;t see any errors until the posting process has been completed. This leads to plenty of frustration and it simply isn&#8217;t usable in the modern era of blogging and interacting.</p><p>To replace this old-fashioned way of validating forms and replying with a user error, developers have begun employing jQuery to validate forms as users fill them out. Users will see a message displayed under each form as they proceed through the commenting process, and that message will either inform them that they&#8217;ve filled out the information successfully or it will alert them to an error and advise them to make a correction. This all happens before the &#8220;submit&#8221; button is clicked, and it saves users a page load and a few minutes of frustration in the process. It&#8217;s easy to do, and the library for form validation is already written. The only thing that&#8217;s holding most users back is developing the custom plugin to make this possible in WordPress, and that&#8217;s not nearly as taxing as most might think it is.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><h2>Step 1: Create a Plugin Directory and Get the Files in Order</h2><p>The process used to validate a form requires that a custom plugin be generated within WordPress. This might intimidate some users, but rest assured that this plugin is just a more extensive series of additional &#8220;functions&#8221; like those that would typically be placed within a site-specific &#8220;functions.php&#8221; file. The validation function is added to a plugin so that it can be used across themes, rather than theme-specific functions files, which would require placing this code within every single one in order to make sure it works thoughout each user-installed theme in the Dashboard.</p><p>First and foremost, navigate to <code>/public_html/wp-content/plugins/</code> and create a new folder named &#8220;validation-plugin.&#8221; This will contain all of the relevant files and subfolders needed for proper operation. Open that folder and create two new subfolders for the plugin:</p><ul><li>js</li><li>css</li></ul><p>These folders are pretty self-explanatory. Inside the &#8220;js&#8221; folder, a jQuery library will be stored. Inside the &#8220;css&#8221; folder, a stylesheet will be placed, which will determine the appearance of the error or approval messages that are displayed to the commenting user.</p><p>The jQuery library needed for this process is known as the <a
href="http://bassistance.de/">Bassistance.de Library</a>. Once it has been downloaded, it should be placed into the &#8220;js&#8221; folder. Then create a new file called &#8220;validation.css&#8221; and place that (blank) stylesheet into the &#8220;css&#8221; folder. Finally, it&#8217;s time to create the plugin PHP file that will control the validation functions.</p><p>The PHP plugin file should be named &#8220;form-validation.php&#8221; and it should be placed outside the subfolders in the main plugin directory. This file can be left blank for now, as it will be edited directly on the server and filled with content and functions as the process continues.</p><h2>Step 2: Give the Plugin a Name and Describe its Functions</h2><p>Every WordPress plugin is required to contain a few lines of code which give it a name, a version, and some descriptive tags and blocks of text. This is much like the content placed in a &#8220;style.css&#8221; file, and it&#8217;s just as important. A plugin which lacks these lines of text won&#8217;t display in the WordPress Dashboard. That means it cannot be activated after completion, so be sure that each line of text is filled in completely with the proper information. These lines of text look like the following:</p><pre>
/**
* Plugin Name: Comment Form Validation Custom Plugin
* Plugin URI: http://your-site.com
* Description: This plugin enhances the WordPress comment form by using a jQuery library to validate the content of each text area and text box as the user types their information into them. This plugin can be used across themes and is compatible with all major browsers and even screen readers.
* Version: 1.0
* Author: Your Name (You're the Author!)
* Author URI: http://your-site-again.com
* License: GPL
*/
</pre><p>Each line in the above code is pretty self-explanatory. The only one which might throw some developers off is the &#8220;license&#8221; line. For novice users, this simply refers to the license under which the code is written and distributed. In this case, it has been defined as GPL, for GNU Public License. This pretty much means that anyone can use this code on their own website, or modify the code to their needs, so long as they give credit to the original author. Because WordPress is an open-source content management solution based on PHP, a GPL or GPL version 2.0 license is the most appropriate way to create, share, and minimally restrict your work.</p><h2>Step 3: Bringing the jQuery Library to Life Using Plugin Functions</h2><p>The next step of the process will add specific functions to the plugin&#8217;s PHP file, which will load the script and activate its functions on the comment submission website. This is done relatively simply and it looks exactly like something that would appear in a theme-specific &#8220;functions.php&#8221; file. Remember that this information and coding is based on using the appropriate plugin file directories, which were described in an earlier step of this process. The code, when completed, looks like this:</p><pre>
function form_validation_js() {
  if(is_single() ) {
    wp_enqueue_script(
      'jquery-validate',
      plugin_dir_url( __FILE__ ) . '/js/bassistance.js',
      array('jquery'),
      '1.8.1',
      true
    );
    form_validation_style(
      'jquery-validate',
      plugin_dir_url( __FILE__ ) . '/css/validation.css',
      array(),
     '1.0'
    );
  }
}
add_action('template_redirect', 'form_validation_script');
function print_validation_script() { ?>
< ?php } add_action('form_validation_script'); ? >
</pre><p>These can be customized to a user&#8217;s wishes and they can contain any punctuation or uppercase letters that a designer wants to include. Try to keep them brief and descriptive, however, as most people don&#8217;t read between the lines even when it&#8217;s well-styled using CSS code. The PHP programming part of this operation is now complete.</p><h2>Step 4: Styling Error Messages with Some CSS</h2><p>Now we&#8217;re going to use the stylesheet file that was created in the first step of this process. Navigate to the &#8220;css&#8221; folder and, in the &#8220;validation.css&#8221; file, add the following lines:</p><pre>
label.error {
  display: block;
  color: #000;
  background-color: yellow;
  padding: 10px;
}
</pre><p>Every error message is defined as a form label with the class &#8220;error.&#8221; This element simply styles these errors with black text, a yellow background, and design-friendly padding that keeps text from meeting the edge of the color. It can, of course, be customized according to your taste and your website&#8217;s design specifications.</p><p>Also worth noting is that this stylesheet information does not need to be placed into the plugin&#8217;s stylesheet at all. Because WordPress naturally draws its look and feel from the theme&#8217;s &#8220;style.css&#8221; file, it could be placed in that stylesheet instead. If your site uses multiple themes and switches them very often, or if you allow users to switch between your site&#8217;s installed WordPress themes, this is a great way to ensure that the comment form&#8217;s error messages blend in with each theme individually rather than inheriting a universal style from the plugin folder itself.</p><p>Be sure to test each form element and try to make it produce an error. Check out the styling, and the error message, and check for any bugs or glitches. If none exist, the process is complete and your website is now much more usable and accessible.</p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/validating-wordpress-comment-forms-with-jquery-and-a-custom-plugin/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>PHPMaster: Role Based Access Control, pChart, CI with Jenkins, and More</title><link>http://www.sitepoint.com/phpmaster-role-based-access-control-pchart-ci-with-jenkins-and-more/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=phpmaster-role-based-access-control-pchart-ci-with-jenkins-and-more</link> <comments>http://www.sitepoint.com/phpmaster-role-based-access-control-pchart-ci-with-jenkins-and-more/#comments</comments> <pubDate>Tue, 27 Mar 2012 18:00:08 +0000</pubDate> <dc:creator>Timothy Boronczyk</dc:creator> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=53021</guid> <description><![CDATA[Over at PHPMaster, we're looking into Role Based Access Control, using pChart with Google Analytics, integrating data mappers into a domain model, error logging with MongoDB and Analog, and more.]]></description> <content:encoded><![CDATA[<p></p><h2><a
href="http://phpmaster.com/role-based-access-control-in-php/">Role Based Access Control in PHP</a></h2><p>Role Based Access Control is a model in which roles are created for various job functions and permissions to perform operations that are then tied to them. Users can be assigned one or multiple roles, which restrict their system access to the permissions they&#8217;ve been authorized for. In this article, you&#8217;ll learn more about RBAC and how to enhance your existing authentication system with it.</p><hr
/><h2><a
href="http://phpmaster.com/pchart-revisited-with-google-analytics/">pChart Revisited with Google Analytics</a></h2><p>Back in December, PHPMaster published an introductory article written by J Armando Jeronymo on pChart, a PHP library that creates eye-catching anti-aliased charts. A reader asked for more articles with further examples, so he has written this follow-up. It features a handy device for visually checking website statistics using Google Analytics&#8217; GAPI.</p><hr
/><h2><a
href="http://phpmaster.com/integrating-the-data-mappers/">Building a Domain Model: Integrating Data Mappers</a></h2><p>You&#8217;ve seen how to write data models, now learn how to put them to work in synchrony with a &#8220;real&#8221; persistence layer. In this follow-up to Alejandro&#8217;s article on persistence agnosticism, you&#8217;ll develop a basic mapping module which will allow you to move data easily between a model and a MySQL database, all while keeping them neatly isolated from each other.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><hr
/><h2><a
href="http://phpmaster.com/error-logging-with-mongodb-and-analog/">Error Logging with MongoDB and Analog</a></h2><p>With the hype around document databases continuing to grow, and around MongoDB in particular, there are a lot of questions about how to migrate your applications to begin using it. The advice is usually the same – especially for existing applications: take one step at a time. This article will show how you can add logging to your existing code using MongDB and Analog.</p><hr
/><h2><a
href="http://phpmaster.com/continuous-integration-with-jenkins-1/">Continuous Integration with Jenkins, Part 1</a></h2><p>Continuous integration is a software quality-control technique that checks code integrity whenever small changes are made, rather than waiting for all the code to be finished before testing and debugging. This is the first in a two-part series that introduces Jenkins. It presents a big-picture overview of the sort of programming problems CI can solve.</p><hr
/> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/phpmaster-role-based-access-control-pchart-ci-with-jenkins-and-more/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item><div><div
class="post_box two_ads" style="float:left;padding-left:2px;"><div
id='div-gpt-ad-1328645237920-1' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328645237920-1'); });</script> </div></div></div><div
class="clear">&nbsp;</div> <item><title>PHP 5.4 is Released &#8212; What&#8217;s New?</title><link>http://www.sitepoint.com/whats-new-in-php-54/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=whats-new-in-php-54</link> <comments>http://www.sitepoint.com/whats-new-in-php-54/#comments</comments> <pubDate>Mon, 05 Mar 2012 17:14:23 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[PHP & MySQL News & Interviews]]></category> <category><![CDATA[PHP & MySQL Tutorials]]></category> <category><![CDATA[php 5.4]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=52336</guid> <description><![CDATA[<img
width="50" height="26" src="http://www.sitepoint.com/wp-content/uploads/1/files/2008/06/phpframework1.jpeg" class="attachment-thumbnail wp-post-image" alt="Powered by the PHP framework" title="Powered by the PHP framework" />PHP 5.4 has finally been released. Craig looks at the what's new, improved and removed.]]></description> <content:encoded><![CDATA[<img
width="50" height="26" src="http://www.sitepoint.com/wp-content/uploads/1/files/2008/06/phpframework1.jpeg" class="attachment-thumbnail wp-post-image" alt="Powered by the PHP framework" title="Powered by the PHP framework" /><p></p><p>It&#8217;s difficult to believe almost three years have elapsed since PHP 5.3.0. The next version should have been PHP 6.0 but unicode problems have delayed development. This latest version provides many of the features planned for version 6.0.</p><p><a
href="http://docs.php.net/downloads.php" class="broken_link"><strong>PHP 5.4 is available to download from the php.net website</strong></a>. There&#8217;s a <a
href="http://uk.php.net/migration54">PHP 5.3 migration guide</a> if you want to keep your old settings. While it&#8217;s stable, you&#8217;d be advised to test your sites and applications before installing it on live servers. The PHP team often release a bug-fix version a few weeks after the initial release.</p><p>So let&#8217;s look at the best new features and improvements&hellip;</p><h2>Short Array Syntax</h2><p>It&#8217;s now possible to use finger-saving JavaScript-like square brackets rather than using the old <code>array(&hellip;)</code> construct, e.g.</p><pre><code>
$array1 = [1, 2, 3];
$array2 = [
	&quot;one&quot; =&gt; &quot;first&quot;,
	&quot;two&quot; =&gt; &quot;second&quot;,
	&quot;three&quot; =&gt; &quot;third&quot;
];
</code></pre><h2>Traits</h2><p>Traits reduce some limitations of single inheritance. In essence, traits are similar to abstract classes and can contain any number of properties and methods. A class can then <code>use</code> any number of traits, e.g.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><pre><code>
trait Hello
{
    function sayHello() {
        return &quot;Hello&quot;;
    }
}
trait World
{
    function sayWorld() {
        return &quot;World&quot;;
    }
}
class MyWorld
{
    use Hello, World;
}
$world = new MyWorld();
echo $world-&gt;sayHello() . ' ' . $world-&gt;sayWorld();
</code></pre><p>For more information, refer to <a
href="http://phpmaster.com/using-traits-in-php-5-4/">Using Traits in PHP 5.4 on PHPmaster.com</a>.</p><h2>Built-in Web Server</h2><p>PHP 5.4 offers a built-in web server which runs from the Windows, Mac or Linux command line. While it&#8217;s not Apache or IIS, it&#8217;s fine for simple testing. I suspect many of the better PHP IDEs will implement support shortly.</p><p>For more information, refer to <a
href="http://www.sitepoint.com/php-54-web-server/">PHP 5.4&#8242;s New Built-in Web Server</a>.</p><h2>New Commands</h2><p>A number of useful commands have been implemented:</p><ol><li><a
href="http://uk.php.net/manual/en/function.hex2bin.php">hextobin(string $hex)</a>: coverts a hex representation of data to binary.</li><li><a
href="http://uk.php.net/manual/en/function.http-response-code.php">http_response_code(int $code)</a>: allows you to set or get the HTTP response code, e.g. <code>http_response_code(404);</code></li><li><a
href="http://uk.php.net/manual/en/function.header-register-callback.php">header_register_callback(string $function)</a>: allows you to register a function which is called when PHP starts sending output.</li><li><a
href="http://uk.php.net/manual/en/function.trait-exists.php">trait_exists(string $name [,bool $autoload])</a>: determines whether a trait exists and, optionally, whether it should be autoloaded.</li></ol><h2>Miscellaneous Updates</h2><p>If that&#8217;s not enough&hellip;</p><ul><li>Class members can be accessed on instantiation, e.g. <code>(new MyClass)-&gt;MyMethod()</code></li><li><code>&lt;?=$variable?&gt;</code> is always available regardless of how your short_open_tag ini option is set.</li><li>Binary numbers can be declared, e.g. <code>0b11110000</code></li><li><a
href="http://docs.php.net/manual/en/session.upload-progress.php" class="broken_link">Session upload progress</a> has been implemented so PHP can track the state of file uploads.</li><li>Some users are reporting speed increases of up to 25% with a memory reduction of 35%.</li></ul><h2>Compatibility Issues</h2><p>Most older PHP code <em>should</em> run without modification but there are a few gotchas to look out for:</p><ul><li><a
href="http://uk.php.net/manual/en/features.safe-mode.php">Safe mode</a>, <a
href="http://uk.php.net/manual/en/ini.core.php#ini.register-globals">register_globals</a> and <a
href="http://uk.php.net/manual/en/security.magicquotes.php">magic quotes</a> have been removed. <a
href="http://uk.php.net/manual/en/function.get-magic-quotes-gpc.php">get_magic_quotes_gpc()</a> will always return FALSE.</li><li><a
href="http://uk.php.net/manual/en/language.oop5.traits.php">trait</a>, callable and <a
href="http://uk.php.net/manual/en/language.oop5.traits.php">insteadof</a> have become reserved words.</li><li>Several mysqli aliases have been removed.</li></ul><p>You should also note that PHP 5.4.x will be the last edition to support Windows XP and Windows 2003.</p><p>PHP 5.4 isn&#8217;t quite as radical has 5.3, but there are enough new features to keep developers happy for a while. Let us know if you have any positive or negative experiences with the latest version.</p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/whats-new-in-php-54/feed/</wfw:commentRss> <slash:comments>26</slash:comments> </item> <item><title>WordPress Plugin Development, PHP and SOAP, Building a Domain Model, and More</title><link>http://www.sitepoint.com/wordpress-plugin-development-php-and-soap-building-a-domain-model-and-more/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-plugin-development-php-and-soap-building-a-domain-model-and-more</link> <comments>http://www.sitepoint.com/wordpress-plugin-development-php-and-soap-building-a-domain-model-and-more/#comments</comments> <pubDate>Fri, 02 Mar 2012 11:20:54 +0000</pubDate> <dc:creator>Timothy Boronczyk</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[PHP & MySQL Tutorials]]></category> <category><![CDATA[phpmaster]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=51954</guid> <description><![CDATA[<img
width="50" height="15" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/03/phpmaster-50x15.png" class="attachment-thumbnail wp-post-image" alt="phpmaster" title="phpmaster" />Are you up to speed with Phar, WordPress plugin debelopment, building web services using PHP and SOAP, the Observer Pattern, and persistence agnosticism?]]></description> <content:encoded><![CDATA[<img
width="50" height="15" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/03/phpmaster-50x15.png" class="attachment-thumbnail wp-post-image" alt="phpmaster" title="phpmaster" /><p></p><h2><a
href="http://phpmaster.com/packaging-your-apps-with-phar/">Packaging Your Apps with Phar</a></h2><p>Deployment of web applications can be difficult and cumbersome without the right tools. This article will introduce you to PHAR, PHP&#8217;s package format which can help you have a better deployment experience.</p><hr
/><h2><a
href="http://phpmaster.com/wordpress-plugin-development/">WordPress Plugin Development</a></h2><p>If you&#8217;ve ever used WordPress to build a site quickly, chances are you&#8217;ve used one of the many plugins that are offered to extend the functionality of this popular blogging software. There are times, however, when you can struggle to find what you need from existing plugins. This article shows you how to create your own WordPress plugins.</p><hr
/><h2><a
href="http://phpmaster.com/web-services-with-php-and-soap-1/">Creating Web Services with PHP and SOAP, Part 1</a></h2><p>The ability to develop software and services for a wide range of platforms is a necessary skill for programmers, and SOAP, an XML-based protocol, will help ease the burden. Learn about SOAP and make your own SOAP client and server using the NuSOAP library in the first of this two-part series.</p><hr
/><h2><a
href="http://phpmaster.com/understanding-the-observer-pattern/">Understanding the Observer Pattern</a></h2><p>In this article, you&#8217;ll learn how to implement the Observer Pattern, a behavioral design pattern that defines a one-to-many relationship between objects. Therefore, when one object changes its state, all dependent objects are notified and updated automatically.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><hr
/><h2><a
href="http://phpmaster.com/building-a-domain-model/">Building a Domain Model: An Introduction to Persistence Agnosticism</a></h2><p>With tons of MVC-based frameworks proliferating like hungry ants, the &#8220;model&#8221; part continues to suffer from the symptoms of an ad hoc Database Model layer. This article will teach you another way, one that will help you focus more on keeping access code out of your domain logic, as well as maintain a clear boundary of responsibility.</p><hr
/> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/wordpress-plugin-development-php-and-soap-building-a-domain-model-and-more/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Is Your PHP Behind the Curve?</title><link>http://www.sitepoint.com/is-your-php-behind-the-curve/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=is-your-php-behind-the-curve</link> <comments>http://www.sitepoint.com/is-your-php-behind-the-curve/#comments</comments> <pubDate>Wed, 15 Feb 2012 05:56:54 +0000</pubDate> <dc:creator>Timothy Boronczyk</dc:creator> <category><![CDATA[PHP]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=51498</guid> <description><![CDATA[<img
width="50" height="21" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/phpmaster.-50x21.png" class="attachment-thumbnail wp-post-image" alt="phpmaster." title="phpmaster." />Stay ahead of the crowd by checking out the latest and greatest in the world of PHP]]></description> <content:encoded><![CDATA[<img
width="50" height="21" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/phpmaster.-50x21.png" class="attachment-thumbnail wp-post-image" alt="phpmaster." title="phpmaster." /><p></p><h2><a
href="http://phpmaster.com/using-traits-in-php-5-4/">Using Traits in PHP 5.4</a></h2><p>Less code duplication, more code reuse is a goal of OOP, but sometimes it can be difficult with PHP’s single inheritance model. Traits offer a workaround to horizontally reuse code across different class hierarchies. They’re new in PHP 5.4 so learn about them today!</p><hr
/><h2><a
href="http://phpmaster.com/tracking-upload-progress-with-php-and-javascript/">Tracking Upload Progress with PHP and JavaScript</a></h2><p>A problem that has plagued web developers for years is how to add real-time information to their applications, such as a progress bar for file uploads. Learn how a new feature in PHP 5.4 can be used to create a dynamic upload progress bar without any external libraries or browser dependencies.</p><hr
/><h2><a
href="http://phpmaster.com/where-on-earth-are-you/">Where on Earth are you?</a></h2><p>Modern geolocation applications use latitude and longitude to identify the location of people and places to within a few meters – but it’s highly unlikely you’ll answer the question &#8220;Where on Earth are you?&#8221;. Learn how to use the Yahoo! Placemaker server and write a simple program to ask users where they are before identifying their location in concrete terms.<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><hr
/><h2><a
href="http://phpmaster.com/autoloading-and-the-psr-0-standard/">Autoloading in PHP and the PSR-0 Standard</a></h2><p>Including a slew of extra files at the top of your scripts can be a drag! Learn about the “history of autoloading” and the current PSR-0 standard used in many PHP frameworks such as Lithium, Symfony, and Zend, that makes lengthy include lists a thing of the past.</p><hr
/><h2><a
href="http://phpmaster.com/yii-under-the-hood-2/">Under the Hood of Yii’s Component Architecture Part 2</a></h2><p>This is Part 2 of the 3-part series that shows you some of the inner-workings of the Yii Framework&#8217;s component architecture. In this installment you&#8217;ll learn how you can do event-based programming in PHP and how Yii&#8217;s CComponent class helps facilitate it.</p><hr
/> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/is-your-php-behind-the-curve/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How to Create Your Own Random Number Generator in PHP</title><link>http://www.sitepoint.com/php-random-number-generator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=php-random-number-generator</link> <comments>http://www.sitepoint.com/php-random-number-generator/#comments</comments> <pubDate>Wed, 08 Feb 2012 15:50:17 +0000</pubDate> <dc:creator>Craig Buckler</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[PHP & MySQL Tutorials]]></category> <category><![CDATA[Technology]]></category> <category><![CDATA[random]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=50865</guid> <description><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/631-psuedo-random-php-50x50.png" class="attachment-thumbnail wp-post-image" alt="631-psuedo-random-php" title="631-psuedo-random-php" />Craig explains how you can write your own random number generator in PHP - and why you'd want to do that given that PHP has its own random generation functions.]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/631-psuedo-random-php-50x50.png" class="attachment-thumbnail wp-post-image" alt="631-psuedo-random-php" title="631-psuedo-random-php" /><p></p><p>Computers cannot generate random numbers. A machine which works in ones and zeros is unable to magically invent its own stream of random data. However, computers can implement mathematical algorithms which produce pseudo-random numbers. They look like random numbers. They feel like random distributions. But they&#8217;re fake; the same sequence of digits is generated if you run the algorithm twice.</p><h2>Planting Random Seeds</h2><p>To increase the apparent randomness, most algorithms can be passed a seed &#8212; an initialization number for the random sequence. Passing the same seed twice will still generate the same set of random numbers but you can set the seed based on external input factors. The easiest option is the current time but it can be anything; the last keypress, a mouse movement, the temperature, the number of hours wasted on YouTube, or any other factor.</p><h2>Random PHP Functions</h2><p>PHP offers a number of random number functions. The main ones are:</p><ol><li><p><a
href="http://php.net/manual/en/function.rand.php">rand()</a> and the more efficient <a
href="http://www.php.net/manual/en/function.mt-rand.php">mt_rand()</a> function. Both return a random number between zero and <a
href="http://www.php.net/manual/en/function.getrandmax.php">getrandmax()</a>/<a
href="http://www.php.net/manual/en/function.mt-getrandmax.php">mt_getrandmax()</a>. Alternatively, you can pass minimum and maximum parameters:<div
id='div-gpt-ad-1328644474660-10' style='width:728px; height:90px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1328644474660-10'); });</script> </div></p><pre><code>
// random number between 0 and 10 (inclusive)
echo mt_rand(0, 10);
</code></pre></li><li><p><a
href="http://www.php.net/manual/en/function.srand.php">srand($seed)</a> and <a
href="http://www.php.net/manual/en/function.mt-srand.php">mt_srand($seed)</a> to set a random number seed. This has been done automatically since PHP 4.2.0.</p></li></ol><h2>PHP is Too Random!</h2><p>There are instances when creating a repeatable list of pseudo-random numbers is useful. It&#8217;s often used for security or verification purposes, e.g. encrypting a password before it&#8217;s transmitted or generating a hash code for a set of data. Unfortunately, PHP can be a little <em>too</em> random. A generated sequence will depend on your hosting platform and version of PHP. In other words, you can&#8217;t guarantee the same &#8216;random&#8217; sequence will be generated twice on two different machines even if the same seed is used.</p><h2>Rolling Your Own Random Class</h2><p>Fortunately, we can write our own random number generator. You&#8217;ll find many algorithms on the web, but this is one of the shortest and fastest. First, we initialize our class and a random seed variable:</p><pre><code>
class Random {
	// random seed
	private static $RSeed = 0;
</code></pre><p>Next we have a seed() function for setting a new seed value. For the algorithm to work correctly, the seed should always be a positive number greater than zero but not large enough to cause mathematical overflows. The seed function takes any value but converts it to a number between 1 and 9,999,999:</p><pre><code>
	// set seed
	public static function seed($s = 0) {
		self::$RSeed = abs(intval($s)) % 9999999 + 1;
		self::num();
	}
</code></pre><p>Finally, we have our num() function for generating a random number between $min and $max. If no seed has been set it&#8217;s initialized with PHP&#8217;s own random number generator:</p><pre><code>
	// generate random number
	public static function num($min = 0, $max = 9999999) {
		if (self::$RSeed == 0) self::seed(mt_rand());
		self::$RSeed = (self::$RSeed * 125) % 2796203;
		return self::$RSeed % ($max - $min + 1) + $min;
	}
}
</code></pre><p>We can now set a seed and output a sequence of numbers:</p><pre><code>
// set seed
Random::seed(42);
// echo 10 numbers between 1 and 100
for ($i = 0; $i &lt; 10; $i++) {
	echo Random::num(1, 100) . '&lt;br /&gt;';
}
</code></pre><p>If you&#8217;ve copied this code exactly, you should see the following values no matter what OS or version of PHP you&#8217;re running:</p><pre>
76
86
14
79
73
2
87
43
62
7
</pre><p>Admittedly, repeatable <em>&#8220;random&#8221;</em> numbers isn&#8217;t something you&#8217;ll need every day &#8212; you&#8217;re more likely to require something closer to real randomness and PHP&#8217;s functions will serve you better. But there may be occasions when you find this useful.</p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://www.sitepoint.com/php-random-number-generator/feed/</wfw:commentRss> <slash:comments>10</slash:comments> </item> <item><title>PHPMaster: How I Chose My Programming Editor</title><link>http://feedproxy.google.com/~r/PHPMaster_feed/~3/y6hnYOzYB8U/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=phpmaster-how-i-chose-my-programming-editor</link> <comments>http://feedproxy.google.com/~r/PHPMaster_feed/~3/y6hnYOzYB8U/#comments</comments> <pubDate>Fri, 13 Jan 2012 23:32:42 +0000</pubDate> <dc:creator>J Armando Jeronymo</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[Color]]></category> <category><![CDATA[Community]]></category> <category><![CDATA[debug]]></category> <category><![CDATA[Design]]></category> <category><![CDATA[DR]]></category> <category><![CDATA[frameworks]]></category> <category><![CDATA[HTML5]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Open Source]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[plugins]]></category> <category><![CDATA[S3]]></category> <category><![CDATA[UX]]></category> <category><![CDATA[Web Tech]]></category> <category><![CDATA[Windows]]></category> <category><![CDATA[netbeans]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=50239</guid> <description><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/aebc63699691-150x150-50x50.jpg" class="attachment-thumbnail wp-post-image" alt="Thumbnail" title="Thumbnail" /> For many years I used a code editor that is now discontinued by its developers, and the introduction of HTML5 and CSS3 led me to look for an editor that supports the new tags and properties. In this article I’ll share the criteria and process I used to find an editor suitable for making quick fixes and a development environment for large-scale projects. My initial candidate list contained over 30 popular Linux, Java, Windows and XUL software packages which had at least one stable release after January 1, 2010: Arachnophilia, Bluefish, Bluegriffon, CoffeeCup HTML Editor, Dreamweaver, Eclipse PDT, Emacs, Expression Web, Geany, gedit, HTML-Kit, jEdit, Kate, KDevelop, Komodo Edit, KWrite, Netbeans, Notepad++, Notepad2, OpenBEXI, PHPEdit, PHPEd Pro, PHPStorm, Programmer’s Notepad, PSPad, RadPHP, Scite, SeaMonkey, Vim, WebDev, WebMatrix, and Zend Studio. You can google each program for their specific details]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/aebc63699691-150x150-50x50.jpg" class="attachment-thumbnail wp-post-image" alt="Thumbnail" title="Thumbnail" /><p></p><p><img
src="http://www.sitepoint.com/wp-content/uploads/2012/01/aebc63699691-150x150-50x50.jpg" alt="" /> For many years I used a code editor that is now discontinued by its developers, and the introduction of HTML5 and CSS3 led me to look for an editor that supports the new tags and properties. In this article I’ll share the criteria and process I used to find an editor suitable for making quick fixes and a development environment for large-scale projects. My initial candidate list contained over 30 popular Linux, Java, Windows and XUL software packages which had at least one stable release after January 1, 2010: Arachnophilia, Bluefish, Bluegriffon, CoffeeCup HTML Editor, Dreamweaver, Eclipse PDT, Emacs, Expression Web, Geany, gedit, HTML-Kit, jEdit, Kate, KDevelop, Komodo Edit, KWrite, Netbeans, Notepad++, Notepad2, OpenBEXI, PHPEdit, PHPEd Pro, PHPStorm, Programmer’s Notepad, PSPad, RadPHP, Scite, SeaMonkey, Vim, WebDev, WebMatrix, and Zend Studio. You can google each program for their specific details</p><p>Read More:<br
/> <a
title="PHPMaster: How I Chose My Programming Editor" href="http://feedproxy.google.com/~r/PHPMaster_feed/~3/y6hnYOzYB8U/" target="_blank">PHPMaster: How I Chose My Programming Editor</a></p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://feedproxy.google.com/~r/PHPMaster_feed/~3/y6hnYOzYB8U/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>PHPMaster: Zend Job Queue</title><link>http://feedproxy.google.com/~r/PHPMaster_feed/~3/geE_wnRVORE/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=phpmaster-zend-job-queue</link> <comments>http://feedproxy.google.com/~r/PHPMaster_feed/~3/geE_wnRVORE/#comments</comments> <pubDate>Wed, 11 Jan 2012 23:48:32 +0000</pubDate> <dc:creator>Alex Stetsenko</dc:creator> <category><![CDATA[.NET]]></category> <category><![CDATA[Cloud]]></category> <category><![CDATA[Community]]></category> <category><![CDATA[cron]]></category> <category><![CDATA[DR]]></category> <category><![CDATA[headers]]></category> <category><![CDATA[Java]]></category> <category><![CDATA[Mobile]]></category> <category><![CDATA[node]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[PHP & MySQL Tutorials]]></category> <category><![CDATA[queues]]></category> <category><![CDATA[RoR]]></category> <category><![CDATA[Tutorial]]></category> <category><![CDATA[Web Tech]]></category> <category><![CDATA[tutorial]]></category> <guid
isPermaLink="false">http://www.sitepoint.com/?p=50119</guid> <description><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/b938zendqueue_600007-150x150-50x50.jpg" class="attachment-thumbnail wp-post-image" alt="Thumbnail" title="Thumbnail" /> Web applications usually follow a synchronous communication model. However, non-interactive and long-running tasks (such as report generation) are better suited for asynchronous execution. One way to off-load tasks to run at a later time, or even on a different server, is use the Job Queue module available as a part of Zend Server 5 (though not as part of the Community Edition). Job Queue allows job scheduling based on time, priority, and even dependencies. ]]></description> <content:encoded><![CDATA[<img
width="50" height="50" src="http://www.sitepoint.com/wp-content/uploads/1/files/2012/01/b938zendqueue_600007-150x150-50x50.jpg" class="attachment-thumbnail wp-post-image" alt="Thumbnail" title="Thumbnail" /><p></p><p><img
src="http://www.sitepoint.com/wp-content/uploads/2012/01/b938zendqueue_600007-150x150-50x50.jpg" /> Web applications usually follow a synchronous communication model. However, non-interactive and long-running tasks (such as report generation) are better suited for asynchronous execution. One way to off-load tasks to run at a later time, or even on a different server, is use the Job Queue module available as a part of Zend Server 5 (though not as part of the Community Edition). Job Queue allows job scheduling based on time, priority, and even dependencies.</p><p>See the article here:<br
/> <a
target="_blank" href="http://feedproxy.google.com/~r/PHPMaster_feed/~3/geE_wnRVORE/" title="PHPMaster: Zend Job Queue">PHPMaster: Zend Job Queue</a></p> <span
id="pty_trigger"></span><div
style='padding:20px 0px 50px 0px;'><div
style='float:left;padding-left:40px;'><div
id='div-gpt-ad-1335489406190-0' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-0'); });</script> </div></div><div
style='float:right;padding-right:40px;'><div
id='div-gpt-ad-1335489406190-1' style='width:300px; height:100px;'> <script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1335489406190-1'); });</script> </div></div><div
style='clear:both'></div></div><div
style='clear:both'></div>]]></content:encoded> <wfw:commentRss>http://feedproxy.google.com/~r/PHPMaster_feed/~3/geE_wnRVORE/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 47/156 queries in 0.197 seconds using memcached
Object Caching 2974/3210 objects using memcached

Served from: www.sitepoint.com @ 2012-05-27 10:14:55 -->
