The most simplest example of PHP

Example 1 – Hello World in PHP

Following a long tradition of introductory programming and scripting tutorials, our first example will print “Hello World” in the browser window.

<HTML>
<HEAD>
<TITLE> Hello World in PHP </TITLE>
</HEAD>
<BODY>
<?
// Hello world in PHP
 print("Hello World");
?>
</BODY>
</HTML>

The PHP statement:

<? print("Hello World"); ?>

displays the message “Hello World” in the browser window. As was mentioned earlier, PHP statements are embedded into HTML documents and they appear between <? and ?> symbols.

The PHP print function displays the value or string within parentheses in the browser window.

Several important things to note about PHP scripts:

  • PHP is case sensitive, print is different from PRINT
  • PHP statements appear between <? ?>
  • PHP statements end with a semi-colon
  • You can include comments in your PHP code by beginning the line or lines with // characters
  • Your PHP files should have a .php extension rather than a .html extension. If scripts have a .html extension the server will not know that they are PHP files and will not parse and execute the PHP commands.
  • Share/Bookmark
Tagged with:
 

What is PHP?

What is PHP?

From the PHP Web site (www.php.net):

“PHP is a server-side, cross-platform, HTML embedded scripting language.”

That’s a mouthful, but if we break the definition down into smaller pieces, it is easier to understand.

  • server-side: This means that PHP scripts execute on the Web server, not within the browser on your local machine.
  • cross-platform: Cross-platform means that PHP scripts can run on many different operating systems and Web servers. PHP is available for the two most popular Web server configurations (IIS running on Windows NT and Apache running on UNIX).
  • HTML embedded scripting language: This means that PHP statements and commands are actually embedded in your HTML documents. When the Web server sees the PHP statements in the Web page, the server executes the statements and sends the resulting output along with the rest of the HTML. PHP commands are parsed by the server much like Active Server Pages or Cold Fusion tags.
  • Share/Bookmark
Tagged with:
 

API Key – What is that?

Key

Key

Firstly API stands for Application Programing Interface. An API Key key is a code generated by a website that allows users to access their Application Programming Interface.

Web API’s

When used in the context of web development, an API is typically a defined set of Hypertext Transfer Protocol (HTTP) request messages along with a definition of the structure of response messages, usually expressed in an Extensible Markup Language (XML) or JavaScript Object Notation (JSON) format. While “Web API” is virtually a synonym for web service, the recent trend has been away from Simple Object Access Protocol (SOAP) based services towards more direct Representational State Transfer (REST) style communications. Web APIs allow the combination of multiple services into new applications known as mashups.

API’s are used from Credit Card processing to collecting visitor stats.

Twitter’s API

In Twitter’s case, they provide an API method for just about every feature you can see on their website. Programmers use the Twitter API to make applications, websites, widgets, and other projects that interact with Twitter. Programs talk to the Twitter API over HTTP, the same protocol that your browser uses to visit and interact with web pages.

  • Share/Bookmark
Tagged with:
 

.htaccess

301 Redirect

301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. It’s not that hard to implement and it shouldpreserve your search engine rankings for that particular page. If you have to change file names or move pages around, it’s the safest option. The code “301″ is interpreted as “moved permanently”.

Below are a Couple of methods to implement URL Redirection

ASP Redirect

< %@ Language=VBScript %>
< %
Response.Status=”301 Moved Permanently”
Response.AddHeader “Location”,”http://www.new-url.com/”
%>

CGI PERL Redirect

$q = new CGI;
print $q->redirect(”http://www.new-url.com/”);

ColdFusion Redirect

< .cfheader statuscode=”301″ statustext=”Moved permanently”>
< .cfheader name=”Location” value=”http://www.new-url.com”>

IIS Redirect

In internet services manager, right click on the file or folder you wish to redirectSelect the radio titled “a redirection to a URL”.Enter the redirection pageCheck “The exact url entered above” and the “A permanent redirection for this resource”Click on ‘Apply’

JSP (Java) Redirect

< %
response.setStatus(301);
response.setHeader( “Location”, “http://www.new-url.com/” );response.setHeader( “Connection”, “close” );
%>

PHP Redirect

< ?
Header( “HTTP/1.1 301 Moved Permanently” );Header( “Location: http://www.new-url.com” );
?>

Ruby on Rails Redirect

def old_action
headers["Status"] = “301 Moved Permanently”
redirect_to “http://www.new-url.com/”
end

Redirect Old domain to New domain (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected toyour new domain.

The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Please REPLACE www.newdomain.com in the above code with your actual domain name.

In addition to the redirect I would suggest that you contact every backlinking site to modify their backlink to point to your new website.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Redirect to www (htaccess redirect)

Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.comThe .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Please REPLACE domain.com and www.newdomain.com with your actual domain name.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

How to Redirect HTML

Please refer to section titled ‘How to Redirect with htaccess’, if your site is hosted on a Linux Server and ‘IIS Redirect’, if your site is hosted ona Windows Server.

  • Share/Bookmark
Tagged with:
 
Positions by Seo-Watcher