In this small and short post i will be showing you how to place comments in your php coding for others to see which does not get shown when the file is executed only viewable in the source code.

First i will show you how to use a single line comment. Which is used just for one line comment.

<?php
// Copyright php2k.com
echo 'Hello world';
?>

The above code will only display “Hello World” not the comment made above it. To make a single line comment you must place “//” in the begining of the line and then make a comment after it.

To make a multiple line comment it is a bit diffrent, example shown below;

<?php
/* Copyright php2k.com
Thank you for using our site
Multiline comment
*/
echo 'Hello World';
?>

The above code will only display “Hello World” when executed in the web browser, but when viewing the source code, the user will see the comment made by the creator. To make a multiple line comment you must place “/*” in the begining of the comment, and when finished place “*/” placing your comment in between.

Hope this post has helped you, if you need any help please make a comment and i will get back to you as soon as possible.

The include() function is used to include another file in the current file. If you have set variables in one file i.e. config.php and you would like to include it in another file i.e. index.php you would use the include() function.
I will show you a example of this. The following file is config.php where i will set the $vars;

<?php
$name = 'John';
$location = 'London';
$age = '26';
?>

Now save that file as config.php and create a file called index.php. The code follows for index.php;

<?php
include(config.php); // use of including config.php
echo ‘My name is:’ . $name . ‘Location:’ . $location . ‘Age:’ . $age;
?>

Save that as index.php. As you can see i have displayed the variables from config.php in the index.php file, this is done using the include() function which will include everything in config.php in the index.php file.

You can use the include() function to neaten your coding by placing codes in diffrent files and only including them when you need to use a function or variable from it.

09
Sep

At some point you will want a random number string but dont have the time to create new ones all the time, this is where the rand() function comes in. rand() Function creates random numbers from the numbers you set.

<?php

echo rand(0, 10);

?>

The code above will create and display a random number anything from 0 to 10. If you would like a longer number you can change it, for example if i want a random number from 105 to 1043 the code will look like this.

<?php

echo rand(105, 1043);

?>

Very simple and easy, if you have any questions please post a comment and i will get back to you as soon as possible.

The function file_get_contents() reads a file into a string. Using the function doesnt always work or sometimes uses more server memory. Another way of grabbing content from a url is using cUrl. cUrl allows you to grab/retrieve content from another server/url.

I have written a simple function which will retrieve content from the given url using cUrl.

<?php

function getPage($url, $referer, $timeout, $header){
if(!isset($timeout))
$timeout=30;
$curl = curl_init();
if(strstr($referer,"://")){
curl_setopt ($curl, CURLOPT_REFERER, $referer);
}
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt ($curl, CURLOPT_HEADER, (int)$header);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec ($curl);
curl_close ($curl);
return $html;
}

?>

To use the function you will need to define 3 things.

“url” - The url you want to retreve

“refer” - Where would you like the website to think you came from, i.e. http://google.com

“timeout” - How long before you want your server to quit if the site doesnt respond. (30 seconds should be fine).

Now you understand the 3 main points you need to define, i will show you how to use the function.

<?php

getPage(’http://YourDomain.Com’, ‘http://google.com’, ‘30′);

?>

Making sure you have included the function in the top of the page which was shown earlier in the post. This will now grab the targeting page and display it in your browser.

Hope you have learnt something from this tutorial. Any questions please post a comment and i will get back to you as soon as possible.

08
Sep

htmlentities function converts all applicable characters to HTML entities. For example “<b>Hello World</b>” is converted to ” &lt;b&gt;Hello World&lt;/b&gt;

Using this function is simple and easy. I have coded a example below;

<?php

$text = ‘<b>Hello World</b>’;

echo htmlentities($text);

?>

If you have any questions please post a comment and i will contact you as soon as possible.

Not everyone can afford a encoder or trust them, so why not create your own basic encoder! In this tutorial i will show you how to encode letters into another letter of your choice. For example the letter “a” will be known as letter “f” and so on.

First of all i wrote out all the letters on paper and then wrote another letter above it which will be the replacement letter for it.

Now what this script will do is encode the word you submit in the form. For example i submitted my name “Shabbir” which was encoded to “ocettyl”. Let me explain it a little more. The letters are mixed around to make a completely different word. Using this method you could send encoded messages & decode it.

In the same method i used to encode the letters i used it to create the function to decode it as well. So you can send a message or password’s/urls ect to family/friends/clients and just tell them to use your decoder to decode it ;)

Now for the main course the code!

<?php
// Copyright PHP2k.com
// Get the message from the url and change it to lowercasing
$x = strtolower($_REQUEST['x']);
//Change the letters to something else, “a” is now “e”, “b” is now “t” ect….
Function Encode($x) {
$rand = array(”a” => “e”, “b” => “t”, “c” => “w”, “d” => “p”, “e” => “m”, “f” => “a”, “g” => “s”, “h” => “c”,
“i” => “y”, “j” => “v”, “k” => “r”, “l” => “q”, “m” => “u”, “n” => “d”, “o” => “h”, “p” => “g”, “q” => “j”,
“r” => “l”, “s” => “o”, “t” => “n”, “v” => “f”, “u” => “b”, “w” => “i”, “x” => “k”, “y” => “z”, “z” => “x”);
$encode = strtr($x, $rand);
echo $encode;
}
//Decode the lettering again so you get the orignal message, so “e” is changed back to “a” ect..
Function Decode($x) {
$rand = array(”e” => “a”, “t” => “b”, “w” => “c”, “p” => “d”, “m” => “e”, “a” => “f”, “s” => “g”, “c” => “h”,
“y” => “i”, “v” => “j”, “r” => “k”, “q” => “l”, “u” => “m”, “d” => “n”, “h” => “o”, “g” => “p”, “j” => “q”,
“l” => “r”, “o” => “s”, “n” => “t”, “f” => “v”, “b” => “u”, “i” => “w”, “k” => “x”, “z” => “y”, “x” => “z”);
$decode = strtr($x, $rand);
echo $decode;
}
?>
<p>
Encode: <br />
<form action=”./” method=”get”>
<textarea col=”2″ rows=”2″ name=”x”></textarea><br />
<input type=”hidden” name=”do” value=”e”>
<input type=”submit” value=”submit”>
</form>
</p>
<p>
Decode: <br />
<form action=”./” method=”get”>
<textarea col=”2″ rows=”2″ name=”x”></textarea><br />
<input type=”hidden” name=”do” value=”d”>
<input type=”submit”>
</form>
</p>
<p>
<?php
if($_GET['do'] == e) {
Encode($x);
} elseif($_GET['do'] == d) {
Decode($x);
}
?>
</p>

If you would like help with this, please leave a message and i will contact you back as soon as possible.
Hope you like the tutorial and learnt something.

07
Sep
stored in: PHP/MYSQL

Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive.

<?php

$name = ‘John’;
$age = ‘23′;
$location = ‘London’;

echo ‘My name is: $name and i am $age years old, currently living in $location’;

?>

This is output the following:

My name is: John and i am 23 years old, currently living in London

Simple and Easy, try it your self ;)

07
Sep

The $_GET variable is used to gather values/data from a form or url.
Information sent using the $_GET varible is visible in the users web browser, for example http://yourdomain.com/?url=http://google.com which has defined http://google.com as the url.

So for example if i was to use the following php code:

<?php

print $_GET['url'];

?>

It will display the domain http://google.com.

You can change this to anything else, you may change the url to name and then add john after = which when requesting for $_GET['name'] will display john.

You may have seen functions or you may not.  Function() is a defined chunck of code set which can be executed when ever it is needed. A function() consists of a few simple steps.

  • All functions start with the word “function” followed by a related name for the function with “()” after it.
  • Insert { in the second line, after this bracket is where you set what the function will do.
  • Insert } at the end of the function to close it off.

For this example i will be creating a function that will echo the message i have set.

<?php

function Name()
{
echo ‘John’;
}

?>

Thats all and that will display the name John on the page, the function i have made is not very useful but allows you to learn the basic understanding the use function().

If you have any questions please comment below and i will reply as soon as possible.

07
Sep

From: http://www.php.net/index.php#id2008-08-07-1 

PHP 4.4.9 released!

The PHP development team would like to announce the immediate

        availability of PHP 4.4.9. It continues to improve the security and the

        stability of the 4.4 branch and all users are strongly encouraged to

        upgrade to it as soon as possible. This release wraps up all the

        outstanding patches for the PHP 4.4 series, and is therefore the

        last PHP 4.4 release.

          Security Enhancements and Fixes in PHP 4.4.9:       

  • Updated PCRE to version 7.7.
  • Fixed overflow in memnstr().
  • Fixed crash in imageloadfont when an invalid font is given.
  • Fixed open_basedir handling issue in the curl extension.
  • Fixed mbstring.func_overload set in .htaccess becomes global.
  • For a full list of changes in PHP 4.4.9, see the Changelog