Canonicalization
The easiest htaccess trick is to make sure that your site doesn’t have any canonicalization issues on the homepage.
A lot of websites suffer from poor search engine rankings by having a number of different versions of the homepage, for example:
http://www.yoursite.com
http://yoursite.com
http://www.yoursite.com/index.html
http://yoursite.com/index.html
These pages are all seen as different urls, despite them having exactly the same content in most cases. Google has got better at deciding which version to use over the past 12 months but you can still run into problems.
To solve this issue simply add the following to your htaccess file: Read more…
mkdir() php function enables you to create a directory. mkdir() requires a string representing the path to the directory you want to create and an integer that should be an octal number representing the mode you want to set for the directory. You specify an octal (base
number with a leading 0. The mode argument has an effect only on Unix systems.
mkdir( "testdir", 0777 ); // global read/write/execute permissions
mkdir( "testdir", 0755 ); // world and group: read/execute only
// owner: read/write/execute
The strtotime php function is used to parse any English textual datetime description into a Unix timestamp. This function will use the TZ environment variable (if available) to calculate the timestamp. It returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.
$date1 = date(‘Y-m-d’);
$date2 = ‘2005-03-01′;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo “Number of days since ‘2005-03-01′: $days”;
The unset() function is used to unset or free a session variable that has been set. A session can be completely destroyed by using the session_destroy() function.
Example code:
<?php
unset($_SESSION['views']);
?>
All the stored data of the session will be deleted on calling the session_destroy() function.
Example code:
Session_start();
session_destroy();
?>
Arrays can be passed from a html web form to a php script. The ‘name’ attribute of the input type should be specified as an array.
example :
<form method="post" action="arrayformdata.php">
<label>Tags</label>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="text" name="tags[]"/>
<input type="submit" value="submit">
</form>
</html>
To receive the array in a php script, we use the $_POST as
<pre lang="php">
<?php
$postedtags = $_POST['tags'];
foreach ($postedtags as $tag){
echo "<br />$tag";
}
?>
The localtime function is used to get the current date and time from the operating system as a C style associative array or list.
Syntax:
array localtime ()
array localtime (integer $Time)
array localtime (integer $Time, boolean $Associative)
Read more…
The php function rmdir() enables developers to remove a directory from the file system. The process trying to delete the directory must have enough permissions and the directory must be empty. The rmdir() function requires a string representing the path to the directory to be deleted. It returns TRUE on success or FALSE on failure.
Example code:
<?php
if (!is_dir('exampledir')) {
mkdir('exampledir');
}
rmdir('exampledir');
?>
Why Windows code does not working in Linux and Unix or Linux code does not working in Windows and Unix.
This is the most frequently asked question in PHP. While running a PHP document in Windows we get the form variable by either GET or POST method. For which we use the following code:
$name=$_POST["txtName"]; or $name=$_GET["txtName"];
While using the same code in Linux and Unix you will get a error message. To solve this problem or to run a PHP page in a different operating system without any errors, first declare the GET variables and POST variables globally using the following code. Read more…
If you have ever wondered how to include another PHP file into a PHP script, this simple one line code sample will show you how.
<?php
// Place this into your PHP page
// and edit the file name
include "some_other_file.php";
?>
Ever wonder how to easily change your IP address without having to go through the daunting task of going through the system menu? If you can open a Linux Shell and type on a keyboard, then you can change your IP Address with one command line.
- Turn on the computer in which you are running a Linux distribution. Once started, open a Shell, which is similar to a command prompt screen in Windows.
- To change the IP address you will need to use the “ifconfig” command. Also, you should have an IP address in mind that is different than your current IP address.
- With an IP address in mind, type: “ifconfig eth0 192.168.X.XXX up” without the quotation marks and placing your numbers in for the Xs. Keep in mind that a normal IP address will begin 192.168 and then you should normally have one number then two to three numbers for the last section of the address
- Press “Enter” to run the command and change your IP address. Once it is completed you should check the change by simply typing “ifconfig” without the quotation marks, and pressing “Enter.” This will display your current IP address so you can verify that is was changed to the one you entered in Step 3.