Archive for the ‘PHP’ Category

Web development

Wednesday, April 2nd, 2008

Web development is a broad term for any activities related to developing a web site for the World Wide Web or an intranet. This can include e-commerce business development, web design, web content development, client-side/server-side coding, and web server configuration. However, among web professionals, “web development” usually refers only to the non-design aspects of building web sites, e.g. writing markup and coding. Web development can range from developing the simplest static single page of plain text to the most complex web-based internet applications, electronic businesses, or social network services.

For larger businesses and organizations, web development teams can consist of hundreds of people (web developers). Smaller organizations may only require a single permanent or contracting webmaster, or secondary assignment to related job positions such as a graphic designer and/or Information systems technician. Web development may be a collaborative effort between departments rather than the domain of a designated department.
(more…)

Welcome to CodeIgniter

Monday, March 17th, 2008

Code igniter

CodeIgniter is a powerful PHP framework with a very small footprint, built for PHP coders who need a simple and elegant toolkit to create full-featured web applications. If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks
CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

JavaScript and Other Client-Side Technologies

Sunday, March 16th, 2008

The various client-side technologies differ in many ways, starting with the way they get loaded and executed by the web client. JavaScript is a scripting language, whose code is written in plain text and can be embedded into HTML pages to empower them. When a client requests an HTML page, that HTML page can contain JavaScript. JavaScript is supported by all modern web browsers without requiring users to install new components on the system.
JavaScript is a language in its own right (theoretically it isn’t tied to web development), it’s supported by most web clients under any platform, and it has some object-oriented capabilities. JavaScript is not a compiled language so it’s not suited for intensive calculations or writing device drivers and it must arrive in one piece at the client browser to be interpreted so it is not secure either, but it does a good job when used in web pages.
(more…)

PHP and Other Server-Side Technologies

Saturday, March 15th, 2008

Server-side web technologies enable the web server to do much more than simply returning the requested HTML files, such as performing complex calculations, doing object-oriented programming, working with databases, and much more.
Just imagine how much data processing Amazon must do to calculate personalized product recommendations for each visitor, or Google when it searches its enormous database to serve your request. Yes, server-side processing is the engine that caused the web revolution, and the reason for which Internet is so useful nowadays.
(more…)

Redirecting to a Different Location

Friday, March 14th, 2008

Problem
You want to automatically send a user to a new URL. For example,after successfully
saving form data, you want to redirect a user to a page that confirms the data.

Solution
Before any output is printed,use header() to send a Location header with the new
URL:
header('Location: http://www.example.com/');

Discussion
If you want to pass variables to the new page,you can include them in the query
string of the URL:
header('Location: http://www.example.com/?monkey=turtle');
The URL that you are redirecting a user to is retrieved with GET. You can’t redirect
someone to retrieve a URL via POST. You can,however,send other headers along
with the Location header. This is especially useful with the Window-target header,
which indicates a particular named frame or window in which to load the new URL:
header('Window-target: main');
header('Location: http://www.example.com/');
The redirect URL must include the protocol and hostname; it can’t just be a pathname:
// Good Redirect
header('Location: http://www.example.com/catalog/food/pemmican.php');
// Bad Redirect
header('Location: /catalog/food/pemmican.php');

Deleting Cookies

Thursday, March 13th, 2008

Problem
You want to delete a cookie so a browser doesn’t send it back to the server.

Solution
Call setcookie() with no value for the cookie and an expiration time in the past:

setcookie('flavor','',time()-86400);

Discussion
It’s a good idea to make the expiration time a few hours or an entire day in the past,
in case your server and the user’s computer have unsynchronized clocks. For example,
if your server thinks it’s 3:06 P.M. and a user’s computer thinks it’s 3:02 P.M.,a
cookie with an expiration time of 3:05 P.M. isn’t deleted by that user’s computer
even though the time is in the past for the server.
The call to setcookie() that deletes a cookie has to have the same arguments (except
for value and time) that the call to setcookie() that set the cookie did,so include the
path, domain, and secure flag if necessary.

Reading Cookie Values

Wednesday, March 12th, 2008

Problem
You want to read the value of a cookie that’s been previously set.
Solution
Look in the $_COOKIE superglobal array:

if (isset($_COOKIE['flavor'])) {
print "You ate a $_COOKIE[flavor] cookie.";
}

Discussion
A cookie’s value isn’t available in $_COOKIE during the request in which the cookie is
set. In other words,the setcookie() function doesn’t alter the value of $_COOKIE. On
subsequent requests,however,each cookie is stored in $_COOKIE. If register_globals
is on, cookie values are also assigned to global variables.
When a browser sends a cookie back to the server,it sends only the value. You can’t
access the cookie’s domain,path,expiration time,or secure status through $_COOKIE
because the browser doesn’t send that to the server.
To print the names and values of all cookies sent in a particular request,loop
through the $_COOKIE array:

foreach ($_COOKIE as $cookie_name => $cookie_value) {
print "$cookie_name = $cookie_value<br>";
}

Setting Cookies

Tuesday, March 11th, 2008

Problem
You want to set a cookie.
Solution
Use setcookie():

setcookie('flavor','chocolate chip');

Discussion
Cookies are sent with the HTTP headers,so setcookie() must be called before any
output is generated. You can pass additional arguments to setcookie() to control cookie behavior. The
third argument to setcookie() is an expiration time,expressed as an epoch timestamp.
(more…)

Program: Abusive User Checker

Monday, March 10th, 2008

Shared memory’s speed makes it an ideal way to store data different web server processes need to access frequently when a file or database would be too slow. Example shows the pc_Web_Abuse_Check class,which uses shared memory to track accesses to web pages in order to cut off users that abuse a site by bombarding it with requests.

(more…)

Using HTTP Basic Authentication

Saturday, March 8th, 2008

You want to use PHP to protect parts of your web site with passwords. Instead of
storing the passwords in an external file and letting the web server handle the
authentication, you want the password verification logic to be in a PHP program.

Solution
The $_SERVER[’PHP_AUTH_USER’] and $_SERVER[’PHP_AUTH_PW’] global variables contain
the username and password supplied by the user,if any. To deny access to a
page,send a WWW-Authenticate header identifying the authentication realm as part of
a response with status code 401:

header('WWW-Authenticate: Basic realm="My Website"');
header('HTTP/1.0 401 Unauthorized');
echo "You need to enter a valid username and password.";
exit;

(more…)