Constants

Constants define (“MY_ROOT_PATH”, “/usr/local/httpdocs/”); Then to use $PathToUse = MY_ROOT_PATH; PHP Magic Constants __LINE__ The current line number of the file. __FILE__ The full path and filename of the file. If used inside an include, the name of the included file is returned. Since PHP 4.0.2, __FILE__ always contains an absolute path with symlinks resolved […]

Read More

.Array General

Creating Arrays Use array(); Arrays in PHP can contain a mix of values if you wish (e.g. strings, integers, null, arrays). Create an empty array Create an array of values Calling a function with an array of values Key & Value Arrays See here. Two Dimension Arrays See here. Array Length Is Array? Is Array […]

Read More

Nofollow

Example nofollow in a link <a href=”http://www.someurl.co.uk” target=”_blank” rel=”nofollow”>Some Text</a>

Read More

Getting URL Arguments

Get an argument GET only using $_GET POST only using $POST GET or POST using $_REQUEST Did GET or POST occur Example GET URL Start with an ‘?’, then separate other values with an ‘&’ To read: Example For POST Parameters Sanitise Them!!! htmlentities() converts things like < > ” \ etc into HTML strings like […]

Read More

Variables

Variables General Variable names must start with a ‘$’ character (to allow the php parser to work as fast as possible by instantly know it is a variable). A variable name must start with a letter of the alphabet or and underscore ‘_’. Variable names may only contain: ‘a’ – ‘z’, ‘A’ – ‘Z’ and […]

Read More

Redirect and Reload

Before outputting page content Note this must be before any html headers are sent (i.e. in php code before html output) Redirect to a new page Reload the current page The php header function Redirect with check you’re not already on target page If you’ve outputted some page content Using a META tag is the […]

Read More

Reading content from other web pages

Use CURL Do this $curl_connection= curl_init(‘http://mysite.com/index.php’); curl_setopt ($curl_connection, CURLOPT_POST, 1); curl_setopt ($curl_connection, CURLOPT_POSTFIELDS, “option=com_content&task=blogcategory&id=24&Itemid=55″); or do this $post_data[‘cmd’] = ‘_xclick’; $post_data[”] = ”; $post_data[”] = ”; $post_data[”] = ; $post_data[”] = ; $post_data[”] = ; $post_data[”] = ; foreach ( $post_data as $key => $value) { $post_items[] = $key . ‘=’ . $value; } $post_string […]

Read More

If

Logical OR Logical AND Not Equal When return value can be boolean or an integer Use if ($ReturnValue === false) or $ReturnValue !== false) If with load of a return value into a variable Ensure you enclose the assignment in brackets or it won’t work correctly

Read More

Sending Email

To send an email in php use the mail function Working example PHPMailer Great when you want to send email via a SMTP server (e.g. googlemail), attach files to emails, etcDownload from http://phpmailer.worxware.com/Copy class.phpmailer.php, class.pop3.php and class.smtp.php into your site (e.g. in a folder called phpmailer) and use one of their example files as the […]

Read More

Echo

Abbreviated way of inserting an echo in HTML “<?=” can be used in place of “<?php echo” Calling a function that can return an optional string within HTML Multiple Lines Note the END marker must appear at the start of the line with no whitespace Echo the contents of an array

Read More