Categories
webhosting

What is Dedicated Hosting

Dedicated hosting is the most reliable and expensive option in webhosting. In shared web hosting you will be sharing server’s disk space, bandwidth and other system resources with many webmasters. Your 300 GB of hard disk space is just a part of some 5tb or 50tb space available on the servers. The rest of the space is occupied by the websites of others. Your applications shared the memory of the web server along with applications of other webmasters. Of course, the servers have bandwidth limits which your website will be sharing with many other websites. Then why do people buy shared web hosting options? Obvious reason, the costs!!! Dedicated hosting costs about 60$ to 300$ per month with which you can buy a whole years plan of expensive or premium shared hosting.

Then what does this so expensive dedicated hosting include? When they say dedicated hosting then the whole server is reserved for your website. Only your applications use the memory or CPU of the server. Or they are only running on the server. Only you website occupies the hard disk of the server. All the bandwidth of the server is reserved for your website. Obviously this option is very costly. If your website is very large and has lot of multimedia files like videos etc and requires large bandwidth, you have to consider seriously buying these plans. Dedicated hosting is reliable due to redundancy. The response of servers will be fast. You will have wide variety of technologies available to operate or use. Even if one web server is down other web server will point to your website, which is called clustered webhosts. Some of the web hosting companies provides unmetered bandwidth (no measurement of bandwidth usage) and unlimited disk space options. If you are a serious business user then I recommend you to opt for dedicated server option.

Categories
php

How to Execute Php in Html files

To execute php codes <?php ?> in your .html files you need to add the following lines in your .htaccess file

AddType application/x-httpd-php .html

You can make php code in any file executed by replacing the .html with that respective file extension in above code.

Categories
webhosting

Free Webhosting (is it really free?)

There are large number of free web hosting companies, but the number of companies that provide reliable free hosting is low.

Just search for free web hosting and you will get about 22 million search results on Google. The free website hosting is a way to promote own paid hosting. Most of the hosts provide free hosting to attract visitors , impress with their service and convert them to paid hosting. Most of the free hosting packages has severe restrictions on technologies available to use. The disk space and bandwidth are limited. Some provide large space like 5gb but place restriction on multimedia files like video, audio and .exe files. Some free website providers provide database support & some don’t as database applications can cause heavy load on the servers. There are as many as 200 free website hosting providers.

Some of these web hosts offer free website hosting without any banners or pop ups on your website. An some even allow you to put your own ads like Google ads. But most of the free website hosting is unreliable and paid hosting is always recommended due to their reliability.

But in my experience free web hosts are unreliable. In the long run they run out of resources and some even block your account if you are using lots of resources. Some even require you to pay for some basic needs like for FTP account. Some adds banners to your web pages, some add pop ups, some require you to post in their forum to keep your hosting alive. I would suggest spend some money and get paid hosting service. Most of them come for cheap like 3$/month….

Categories
php

Unlimited Bandwidth is it possible?

Many web hosting companies advertise about unlimited bandwidth and unlimited disk space. Is it really possible for these companies who don’t even own their line to be able to provide unlimited bandwidth. Some companies find providing unlimited bandwidth possible as most of the webmasters bandwidth usage is below average hence providing the remaining bandwidth to others who require more (i.e, unlimited bandwidth). If your hosting company provides unlimited hosting bandwidth then first read the unlimited conditions given to provide such service, like your content should not take high CPU usage etc.. Bandwidth is one of the costliest resource. It is not cheap as they show.

Many of these unlimited bandwidth providers restrict video and audio files. These multimedia files consume huge hard disk space and bandwidth. The streaming video also takes heavy load. Unlimited disk space / bandwidth is just a trick to attract customers. I have seen one host saying that unlimited disk space and unlimited bandwidth only for 6$ /month (condition — if you pay for 10 years of service in advance). Are you stupid to tied up for a single webhost for years without knowing their credibility? Their service might go down hill over the span of 10 years and you have to bear with them for 10 years!!! WTF!!
So choose unlimited webhosting if you know your disk space and bandwidth usage. If you want to have a large site with numerous multimedia files unlimited is not an option because you will eventually run into trouble with them. As long as you know your website bandwidth & disk space requirements you are safe….

Categories
php

Basics in Php

Php Basics

Table of Contents.

 

Syntax of php

The php code block starts with <?php and ends with ?>.
In some some servers when shorhand is enables one can start the php code with <? but for compatibility its always recommended
to start a php block of scripts with <?php
[php]

<?php

echo “Hello World”;

?>
[/php]

The php files contains normal html tags like and php code comes in between. Here is an example of php file.

[php]
<html>

<head>

</head>

<body>

<?php

$title = $_GET[“title”];

echo $title;

?>

</body>

</html>

[/php]
Each of the php statement ends with a semicolon ; . It indicates the end of an instruction.

Return To Top

 

Echo and Print

The two commands “echo” and “print” are used to print or output strings. Both echo and print are used to output
strings but they have some basic differences. It is convinient to out put html codes using ‘print’ since the string is enclosed in single quotes ‘. as shown below

[php]
print ‘Hello World’;
[/php]
But if you use echo to print html code you need to escape the double quotes since the strings are enclosed by ” or double quotes.

[php]
echo “<a href=\”http://www.google.com\”>Google</a>”;
[/php]

the same code can be printed using print as

[php]
print ‘<a href=”http://google.com”>Google</>’;
[/php]

But if you are calling and printing values of variables you need to use echo which is more convenient.
The following example illustrates how easy it is to print values from variables using echo. You can to concatenate strings in case of print statement using ‘.’
[php]

<?php

$title = “Hello. THis is a php text”;

echo “Value of  variable title = $title”;

print ‘Value of  variable title =’.$title;

?php>

[/php]

Return To Top

Variables in Php

You can store data,strings,numbers and arrays in variables.

You can access these values again and again over all your script and
change the values.

variables in php starts with $ sign.

You declare a varialble like

[php]
$variable = values;
[/php]
There is no need to declare the type of variables in php.

It converts the data according to how it is declared.

The below example describes how variables are declared in php

[php]
<?php

$string-a = “how are you?”;

$numbers = 80;

?>
[/php]

Rules for Naming the Variables

  • The variable name can only contain alphabets,numbers and
    underscore. It can contain a-z,A-Z,0-9 and _.
  • The variable name must start with an alphabet or _
  • The variable name cannot contain any spaces and if there
    are two words in string one must use _ to connect them like $my_variable

Return To Top

Operators in Php

Operators in php are used to perform arithmetic and logical operations
on variables.

Here are the operators listed by groups

Arithmetic Operators

Operator Description Example Output
+ Addition $x=2

$x+3

5
Subraction $x=5

$x-3

2
* Multiplication $x=5

$x*2

10
/ division $x=10

$x/2

5
% Remainder in Division or Modulu $x=15

$x%14

1
Decrement $x=5

$x–

x = 4
++ Increment $x=1

$x++

x = 2

Logical Operators

Operator Description Example Output
&& and x=5

y=8

x<6&&y>7

returns True

|| or x=5 , y =8 (x<6||y<6)

Returns true

(x==6||y==9)

Returns False

! Not x=5

y=5

!(x==y)

Returns false

Comparision Operators

Operator Description Example Output
> Greater than x=5

y=6

x>y Returns false
< less than x=6

y=5

x<y Returns false
== is equal to x= 6

y = 6

(x==y) Returns true
>= greater than or equal to x=5

y=6

x>=y returns false
<= Less Than or equal to x=6

y=9

x<=y returns true
!= is not equal to x=5

y=6

x!=y returns true

Assignment Operators

These operators are used to assing values or change values of a
variable.

Operator Description Example
+= x+=y   increments x value by y x+=5. Increses x by 5
-= x-= y decreases x value by y x-=5 decreases x by 5
*= x*=y multiplies x with y x*=5 now x value is 5x
/= x/=y divides x by y x/=5 now x values is x/5
%= x%=y x value is remainder of division x/y x%=5 x values is remainder of division x/5
= x=y x values is same as y x=5 x values is 5
.= Concatenates strings.

x.=y

Return To Top

Categories
php

A primer on Strings in Php

Strings in Php

Table of Contents.

Declaring Strings

String are variables in which we can store text and manipulate text.
Here is an example of how string is declared in php.

[php]
<?php
$txt = “Hello World!”;
echo $txt;
?>
[/php]
Output is
[php]
Hello World!
[/php]

The text string is always enclosed in double quotes (“). There is no need to specify the data type. There are many functions to manipulate strings in php. Only some of the important are discussed here.

Return to Top

Concatenating Strings

In php we concatenate strings using dot (.) .It is the operator for joining two texts.

Example how to concatenate strings.

[php]
<?php

$txt1 = “php tutorials”;

$txt2 = ” best site”;

echo $txt1.”hello world<br>”;

echo “This is to join”.” strings<br>”;

echo $txt1.$txt2;

?>
[/php]

Output
[php]
php tutorialshello world

This is to join strings

php tutorials best site
[/php]
Return to Top

Splitting Strings

Function explode is used to split strings in php. It takes two inputs one is with criteria the string must be split and the input string.
Example
[php]

<?php

$txt = “Programming is fun”;

$pieces = explode(” “,$txt);

echo $pieces[0].”<br>”;

echo $pieces[1].”<br>”;

echo $pieces[2].”<br>”;

?>

[/php]
Output
[php]
Programming

is

fun

[/php]
Return to Top

How to find Length of String

Function strlen() gives you the Length of string.

[php]

<?php

$txt =”Hello”;

echo strlen($txt);

?>

[/php]

Output
[php]
5
[/php]

Return to Top

How to Get Substring of String

The function substr() is used to get the substring of a string in php.
Usage is substr($sourcetext,start,length).

You have to give three arguments to the substr function.

1)$sourcetext — the text from which you want to get the substring

2)start — integer.. the no of character from which you want the string

3)length — how many character you want to pickup (this argument is optional).

Example
[php]

<?php

$txt = “Hello World”;

$string = substr($txt,7,4);

echo $string;

?>

[/php]
Output
[php]
Worl
[/php]

Second type of usage.

substr($sourcetext,start-index)
.
If you donot specify the legnth of substring to be selected the function automatically selects the substring starting from the start index to the end of the string.
Example
[php]
<?php

$text = “what are you doing”;

echo substr($text,6);

?>
[/php]

Output
[php]
re you doing
[/php]
Return to Top

Comparing two Strings in php

Use function strcmp to compare two strings in php.
Usage

[php]

strcmp($string1,$string2).

[/php]
Here we are comparting two texts $string1 and $string2.
The function returns zero if both of them are equal and non zero if both of them are not equal. This function is case sensitive.
If you are looking for case insensitive comparision you have to use function strcasecmp. The usage is same as that of strcmp function and it returns zero (0) if both strings are equal and non-zero values if they are not.

Return to Top

Search for a string in another string.

We use strpos for searching for one string in another string.
Usage

[php]
strpos($sourcestring,$texttobefound)

[/php]
Here $sourcestring is the string in which we are searching and $textobefound is the text for which we are searching for.
This function returns the postion of the first occurance of the string or text we are searching for. If the text is not found it returns boolean value FALSE.

Example
[php]

<?php

$source = “I am an Indian”;

$search1 = “am”;

$search2 = “noid”;

echo strpos($source,$search1);

echo “<br>”;

if(!strpos($source,$search2)){

echo “string is not present”;

}

echo strpos($source,”India”);

?>
[/php]
Output
[php]
2

string is not present
8
[/php]

Return to Top

Replacing Characters in a String

We use function str_replace to replace a sequence of characters in a string.

Usage is

[php]

str_replace($search,$replace,$string)

[/php]

Here $search is the sequence of characters for which we want to replace in the string. $replace is the sequence of characters with which we want to replace the $search. $string is the text in which we want to make the changes.

Example
[php]

<?php

echo str_replace(“i”,”x”,”Aerospace is one of growing industries”);

?>

[/php]
Output is
[php]
Aerospace xs one of growxng xndustrxes
[/php]
Here we are replacing ‘i’ with ‘x’. This replacement is case sensitive. If you are looking for case insensitive function use str_ireplace.

Return to Top

Functions to change Case

The following functions are genreally used to convert strings from one case to other.

All of the below functions returns the string after making appropriate changes. You must rewrite the original string value with the changed one like $stringtoconvert = ucwords($stringtoconvert)
[php]
ucwords($stringtoconvert)— Capitalizes first alphabet of every word in the string or text

ucfirst($stringtoconvert)— Capitalizes only first alphabet of string
strtolower($stringtoconvert)— Converts all alphabets to small.

strtoupper($stringtoconvert)— Capitalizes every alphabet in the string.

[/php]

Return to Top

Categories
webhosting

Ways to Save website bandwidth

What is the most efficient way to save bandwidth?
Outsourcing!!!!

Thing you can outsource

  1. video
  2. audio
  3. documents
  4. pictures

Dude that includes all!!
Nope you cannot outsource  web pages (obviously!)

Video
Serving large sized video files like movies or video tutorials can really mess up your bandwidth. If that video tutorial is popular it will consume a lot of bandwidth. Let say you video is of 50MB in size. About 10 visitors download / view this video every day. Then total bandwidth utilization only for that file is 15000MB/month (50x10x30). OMG! thats a lot.15GB of bandwidth for only one single video file. Just imagine how much bandwidhth you have to buy if a single video file takes 15 gb of bandwidth.

There are large websites like YouTube  where you can upload your videos and they provide you with code to embed that video in your blog or website.  YouTube allows only 100MB & limits the length of video to 10 min. Uploading to these popular video hosts also has other benefits like, free traffic. Many of these popular video sites bring large traffice to your website. Most of the visitors who are visiting youtube finds your video then comes to your homepage for more information (given you have lfet a link to your website there.)

If you don’t want to stream vidoe files you have to upload these huge video files to free file hosting websites. There are really some good free file hosting websites. They have been popular these days. There is a seperate post on free file hosts( the topic is too large to discuss here).

Returrn to top
Audio Files
Most of the time you can upload all audio files to free file hosting websites but there are some services that stream audio for you. Supload is also one of these hosts that provide you embed code to put in your website to play these audio files.

Documents
Can documents occupy large space. Yes and no. Depends on size of the document. IF the document is of 1 mb just keep it in your website. If it is more than 10 mb share in free file hosting websites. There are some good & popular document hosts like SCRIBD where you can upload almost all types of documents and embed them in your website. The visitor doesn’t need to have any special software (expcept ADOBE flash player) to view that document. These document hosting sites are popular so you can get some free traffic from these site to your blog or website. Just don’t forget to leave a link to your website in the documents you have uploaded and your profile in that site.
Returrn to top

Picture:-
Yes pictures cost a lot of bandwidth for you. IF you are a template builder or a designer who caters free templates then i highly recommend uploading the pictures you use in templates to either photbucket or imageshack. Don’t upload pictures used in your website to these file hosts. You images are loaded every time a person opens you website so its better to keep in a place where large bandwidth is available (your webhost). But imageshack does allow about 300 megabytes of transfer per hour for each hotlinked file. So you might consider using it.
Returrn to top

Categories
webhosting

How much Bandwidth is Needed for my website

Many webmasters check for bandwidth before buying hosting package. They are in a misconception that the more the better. It is not a body building competition to buy more and more bandwidth. If you are planning to setup and information website that contains only text then 10Gb would more than enough for a month. Also bandwidth utilization depends on number of page views you get per month. One of my website has about 240,000 page views per month and it has flash games, pictures etc.. but the bandwidth utilization barely crosses 100GB mark… You can calculate the bandwidth required like this.. assume each page is about 100kb size..

Average Size of Page (in KB) 100
No of Page Views/month 100000
Bandwidth Required /month 9.536743

As you can see a site with 100000 pageviews per month needs 10GB /month… 100000 are for really large websites… and if you are planning to setup 10 such sites 100GB or 200GB/month plan would be ideal. and far more than enough. If you are planning for a personal website even 1GB is redundant… :) . But if you have lots of pictures, videos and other rich media you might have to buy a larger package or you can manage with free file hosting sites like mediafire. But now a days the rich media are consuming a lot of data. Text itself represent a low percentage of your bandwidth consumption.

Categories
php

Php Function To Count No of Rows In a Table

Occasionally you bump into a situation where you have to count the no of rows in a table in database.

There is one quick n dirty method to do that..

$noofrows = mysql_num_rows(mysql_query("select * from table"));

This method is inefficient and wont show errors while executing.

Alternatively you can use a  function which returns the no of rows in the table.. it takes table name and db connection handle as input and returns the row count or number of rows present in that table. Most of the time i use this function in pagination scripts.

function getnoofrows($table,$con){
  if($result = mysql_query("select count(*) as rowcount from table",$con)){
    $row = mysql_fetch_array($result);
    return $row['rowcount'];
  } else {
    //show MySQL error
    die(mysql_error());
  }
}

usage:

$noofrows = getnoofrows($table,$con);
Categories
php

Singleton Database Class for Beginners

What is A Singleton Class?

Singleton class is a class for which there exists only one object instance during the run time of the script (in php).

What is the use of singleton class?

It prevents the wastage of resources, if you have already established a connection to the database it retrieves that instance which already exists and reuses it. So there is no need to open a new connection.

How singleton class works?
First it searches for any object instance in the the run time of the script and returns it. If there is no object instance of this class it creates a new one…

Here is the database class which i normally use in my projects..
[php]
class Database{
// Store the single instance of Database
private static $instance;
private static $con;
private function __construct() {
//setup database.
//echo “constructor called”;

// use your server name , sql username and password db name here

$this->con=mysql_connect (“host”, “user”, “password”);
mysql_select_db (“database”,$this->con);
}
public static function getInstance()
{
if (!self::$instance)
{
self::$instance = new Database();
}

return self::$instance;
}
public static function closeInstance()
{
if (!(!self::$instance))
{
$inst = self::$instance;
mysql_close($inst->con);
}
}
// Function to run query
public function query($sql)
{
//echo “query run”;
return mysql_query($sql,$this->con);
}
}

[/php]
Usage:
Call a class using

[php]$db = Database::getInstance();[/php]

Query database

[php]$result = $db->query(‘sql statement here’);[/php]

Close Db Connection

[php]Database::closeInstance();[/php]

Thats all for now about the database class.. you no need to know how it works to use it but you need to study if you want to develop this.