Archive for the 'PHP' Category

Using Cookies in PHP

Wednesday, March 10th, 2010

What is a Cookie?Cookies are small bits of information that can be stored on a client computer. Once a cookie is created, it will expire after a specified time period. All the information stored in a cookie exist until it expires or deleted by the user.

Why do we need Cookies? Now-a-days most of the websites use cookies to store small amounts of information. Websites can read the values from the cookies and use the information as desired. The browser is capable of keeping track of the websites and their corresponding cookies and is capable of reading the information from relevant cookies. Some common use of cookies include:

  • User’s aesthetic preference for a specific site.
  • User keys to link them with their personal data – as used by many Shopping Cart Applications.
  • Allowing a user to remain ‘logged on’ until he explicitly logs out or the browser window is closed.

-Source

Creating Your Own “Function”

Wednesday, February 10th, 2010

A function is a block of code that can be executed whenever we need it.

Creating PHP functions:

* All functions start with the word “function()”
* Name the function – It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number)
* Add a “{” – The function code starts after the opening curly brace
* Insert the function code
* Add a “}” – The function is finished by a closing curly brace

Example

A simple function that writes my name when it is called:

<html>
<body>

<?php
function writeMyName()
{
echo “Michelle”;
}

writeMyName();
?>

</body>
</html>

Use a PHP Function

Now we will use the function in a PHP script:

<html>
<body>

<?php
function writeMyName()
{
echo “Michelle”;
}

echo “Hello world!<br />”;
echo “My name is “;
writeMyName();
echo “.<br />That’s right, “;
writeMyName();
echo ” is my name.”;
?>

</body>
</html>

The output of the code above will be:

Hello world!
My name is Michelle.
That’s right, Michelle is my name.

PHP + MySQL

Sunday, January 10th, 2010

PHP stands for PHP: Hypertext Preprocessor. It is a server-side scripting language wherein the scripts are executed on the server itself. PHP is an open source software and is free to download and use. MySQL is a database server that is ideal for both small and large applications. MySQL can compile on a number of platforms and just like PHP, it is free to download and use. Both are open to everybody who wants to learn more on this.

PHP combined with MySQL can create a cross-platform which means that you can freely develop in Windows and serve on a Unix platform.

User Validation

Wednesday, December 9th, 2009

The golden rule on the world wide web is that one should “never-ever-ever trust user input”. Given this, it would be wise to spend quite some time to make sure that all of the inputs from the users in able to make sure it is safe and what was expected..

There are several things to should watch out for when validating input:

Mistaken input.
For example the user types 99.7 rather than 9.97
Bad input
The user provides incorrect input in on purpose for whatever reason.
Dangerous input
User innocently enters information that would harm the system
Missing input
User provides no input.

ASP vs PHP: Security

Friday, October 30th, 2009

In PHP, common tasks like ftp, encrypt passwords in MD5, or send email from a web page all are built in hidden code, and as PHP is Open source there is a lot
of free code available for PHP.

Unlike PHP there is no hidden code with ASP. If you need to upload files, then you would need a third party component like ASP upload, also if you need to send mail you need another component and so on.

Although PHP is better in many aspects, ASP offers more security than PHP.

ASP vs PHP: Price and Versatility

Monday, September 28th, 2009

Price Compared to ASP, PHP installations are absolutely cheaper to install. PHP perfectly runs on Linux (which is a free OS) and programmers use MySQL .(which also comes FREE) ASP runs on the IIS Server (Internet Information Server) which requires Windows N.T/2000/2003 Servers or better. Aside from that ASP mostly uses MS-SQL Server as the back end which is really expensive. PHP obviously is cheaper than ASP.

Cross Platform compatibility
PHP programs run on a wide variety of Operating Systems Unix, Linux, Solaris and Window’s.ASP on the other hand only works flawlessly with Windows and not with other platforms. PHP offers more versatility than ASP.

Smarty – the right stuff?

Monday, June 22nd, 2009

Smarty is categorized as a “Template engine”, though developers describe it more detailed as a “Template/Presentation Framework”, that offers developers and programmers ample tools to make extensive coding tasks easier by replacing tags with their appropriate counterparts. Smarty is aimed to hasten and make the development process simpler for all who aim to develop pages for the internet. (more…)

Cross-Site Scripting Tips

Friday, May 22nd, 2009

There are several platforms on which web pages are deployed and with thousands of people using different versions of software, scripting languages should be endowed with the proper set of tools that determines the proper set of scripts. Scripts for one platform may differ in form in another so a conversion method should be deployed to allow them to properly interface with each other. Though done behind the scenes, it is of utmost importance making the web experience more enjoyable with an example of the script below for reference. (more…)

PHP – Wide Gaping Security Risk?

Wednesday, April 22nd, 2009

With many of the internet’s web pages and applications based on PHP, many questions are being raised by the security and robustness of the system so to speak as we go through years of rapid development. Now the scripting language that is PHP isn;t meant to be weak security-wise and the problem lies with the sloppy work programmer have done all through the years that have left quite large and gaping security holes in something we so rely on. One event that greatly tripped the panic meters of developers the world over is the departure of one of the world’s leading authority on PHP, Stephan Esser, one of the founders of the language and a foundation of the web with him stating as an explanation that the security issues that are currently coming out are happening without his knowledge. (more…)

Separating Roles

Sunday, March 22nd, 2009

In web development, it is quite necessary to separate the roles of the page designer and the programmer which handles more of the logical or program side of the whole page. Designing a page is the task of making it interesting and quite pleasing to the prospective users who want something that is easy on the eyes yet loaded with functions that performs their needs. The template designer handles the framework onto which the logic is presented visually which is the norm of the internet which relies on graphics and other nifty trinkets to make their users happy customers. (more…)