Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Wednesday, August 6, 2014

D.2 Hypertext Transfer Protocol




As discussed in Chapter 1, HTTP is the standard that allows documents to be communicated and shared over the Web. From a network perspective, HTTP is an application-layer protocol that is built on top of TCP/IP. Since the original version, HTTP/0.9, there have only been two revisions of the HTTP standard. HTTP/1.0 was released as RFC-1945[1] in May 1996 and HTTP/1.1 as RFC-2616 in June 1999.
[1] Request for Comments, or RFCs, are submitted to the RFC editor (http://www.rfc-editor.org) usually by authors attached to organizations such as the Internet Engineering Task Force (IETF at http://www.ietf.org). RFCs date back to the early ARPAnet days and are used to present networking protocols, procedures, programs, and concepts. They also include meeting notes, opinions, bad poems, and other humor: RFC-2324 describes the Hypertext Coffee Pot Control Protocol.
In Chapter 1, we told you that HTTP is very simple: a client—most conspicuously a web browser—sends a request for some resource to a web (HTTP) server, and the server sends back a response. The HTTP response carries the resource—the HTML document or image or whatever—as its payload back to the client.
Continuing our analogy from the previous section, HTTP is a kind of cover letter—like a fax cover sheet—that is stored in an envelope and tells the receiver what language the document is in, instructions on how to read the letter, and how to reply.

D.2.1 Uniform Resource Locators

Uniform resource locators—more commonly known as URLs—are used as the primary naming and addressing method of the Web. URLs belong to the larger class of uniform resource identifiers ; both identify resources, but URLs include specific host details that allow connection to a server that holds the resource.
A URL can be broken into three basic parts: first, the protocol identifier; second, the host and service identifier; and, last, a resource identifier that contains a path with optional parameters and an optional query that identifies the resource. The following example shows a URL that identifies an HTTP resource:
http://host_domain_name:8080/absolute_path?query

The HTTP standard doesn't place any limit on the length of a URL, but some older browsers and proxy servers do. The structure of a URL is formally described by RFC-2396: Uniform Resource Identifiers (URI): Generic Syntax.
D.2.1.1 Protocol
The first part of the URL identifies the application protocol. HTTP URLs start with the familiar http://. Other applications that use URLs to locate resources identify different protocols; for example, URLs used with the File Transfer Protocol (FTP) begin with ftp://. URLs that identify HTTP resources served over connections that are encrypted using the Secure Sockets Layer start with https://. We discuss the use of the Secure Sockets Layer to protect data transmitted over the Internet in Chapter 11.
D.2.1.2 Host and service identification
The next part of the HTTP URL identifies the host on which the web server is running, and the port on which the server listens for HTTP requests. The domain name or the IP address can identify the host component. Using the domain name allows user-friendly web addresses such as:
http://www.w3.org/Protocols/

The equivalent URL using the IP address is:
http://18.29.1.35/Protocols/

Domain names are not case sensitive.
D.2.1.3 Nonstandard TCP ports
By default, a HTTP server listens for requests on port 80. So, for example, requests for the URL http://www.oreilly.com are made to the host machine www.oreilly.com on port 80. When a nonstandard port is used, the URL must include the port number so the browser can successfully connect to the service. For example, the URL http://example.com:8080 connects to the web server running on port 8080 on the host example.com.
D.2.1.4 Resource identification
The remaining URL components help locate a specific resource. The path, with optional parameters, and an optional query are processed by the web server to locate or compute a response.
The path often corresponds to an actual file path on the host's filesystem. For example, an Apache web server running on a Unix machine that hosts example.com may store all the web content under the directory /usr/local/apache2/htdocs and be configured to use the path component of the URL relative to that directory. In this case, the HTTP response to the URL http://example.com/marketing/home.html contains the file /usr/local/apache2/htdocs/marketing/home.html.
In contrast to domain names, the resource identification component is usually case sensitive. This is because it refers to a directory or file on the web server, and Unix servers (which host the majority of web sites) are case sensitive.
D.2.1.5 Parameters and queries
The path component of a URL can include parameters and queries that are used by the web server. A common example is to include a query as part of the URL that runs a search script. The following example shows the string q=red as a query that the script search.php can use:
http://example.com/search.php?q=red

Multiple query terms can be encoded using the & character as a separator:
http://example.com/search.php?q=red&r=victoria

Parameters allow other information not related to a query to be encoded. For example, consider the parameter lines=10 in the URL:
http://example.com/search.php;lines=10?q=red

This can be used by the search.php script to modify the number of lines to display in a result screen.
HTTP provides the distinction between parameters and queries, but parameters are more complex than described here and are not commonly used in practice. We discussed how PHP can use query variables encoded into URLs in Chapter 6.
D.2.1.6 Fragment identifiers
A URL can include a fragment identifier that is interpreted by the client once a requested resource has been received. A fragment identifier is included at the end of a URL separated from the path by the # character. The meaning of the fragment identifier depends on the type of the resource. For example, the following URL includes the fragment identifier tannin for a HTML document:
http://example.com/documents/glossary.html#tannin

When a web browser receives the HTML resource, it then positions the rendered document in the display to start at the anchor element if the named anchor exists.
D.2.1.7 Absolute and relative URLs
The URL general syntax allows a resource to be specified as an absolute or a relative URL. Absolute URLs identify the protocol http://, the host, and the path of the resource, and can be used alone to locate a resource. Here's an example absolute URL:
http://example.com/documents/glossary.html

Relative URLs don't contain all the components and are always considered with respect to a base URL. A relative URL is resolved to an absolute URL, with respect to the base URL. Typically, a relative URL contains the path components of a resource and allows related sets of resources to reference each other in a relative way. This allows path hierarchies to be readily changed without the need to change every URL embedded in a set of documents.
A web browser has two ways to set base URLs when resolving relative URLs. The first method allows a base URL to be encoded into the HTML using the element. The second method sets the base URL to that of the current document; this is done in the absence of a element. For example, the following HTML document contains three relative URLs embedded into elements:
  Read my Curriculum Vitae

  Read my employment history

  Visit Fred's home page

Consider what happens if the page that contains the example is requested with the following URL:
http://example.com/development/dave/home.html

The three relative URLs are resolved to the following absolute URLs by the browser:
http://example.com/development/dave/cv.html

http://example.com/development/dave/work/emp.html

http://example.com/admin/fred.html

Table D-1 shows several relative URLs and how they are resolved to the corresponding absolute URLs given the base URL http://example.com/a/b/c.html?foo=bar.
Table D-1. Example relative URLs resolved to absolute URLs
Relative URL
Absolute URL with respect to http://example.com/a/b/c.html?foo=bar
d.html
http://example.com/a/b/d.html
e/d.html
http://example.com/a/b/e/d.html
/d.html
http://example.com/d.html
../d.html
http://example.com/a/d.html
#xyz
http://example.com/a/b/c.html?foo=bar#xyz
/
http://example.com/a/b/
../
http://example.com/a/

D.2.1.8 URL encoding
The characters used in resource names, query strings, and parameters must not conflict with the characters that have special meanings or aren't allowed in a URL. For example, a question mark character identifies the beginning of a query, and an ampersand (&) character separates multiple terms in a query.
The meanings of these characters can be escaped using a hexadecimal encoding consisting of the percent character (%) followed by the two hexadecimal digits representing the ASCII encoded of the character. For example, an ampersand (&) character is encoded as %26.
The characters that need to be escape-encoded are the control, space, and reserved characters:
; / ? : @ & = + $ ,

Delimiter characters must also be encoded:
< > # % "

The following characters can cause problems with gateways and network agents, and should also be encoded:
{} | \ ^ [ ] `

PHP provides the rawurlencode( ) function to encode special characters. For example, rawurlencode( ) can build the href attribute of an embedded link:
echo '';

The result is an element with an embedded URL correctly encoded:

D.2.2 HTTP Requests

The model used for HTTP requests is to apply methods to identified resources. A HTTP request message contains a method name, a URL to which the method is to be applied, and header fields. Some requests can include a body—for example, the data collected in a form—that is referred to in the HTTP standard as the entity-body.
The following is the example HTTP request we showed you in Chapter 1:
GET /~hugh/index.html HTTP/1.1

Host: goanna.cs.rmit.edu.au

From: hugh@hughwilliams.com (Hugh Williams)

User-agent: Hugh-fake-browser/version-1.0

Accept: text/plain, text/html

The request applies the GET method to the /~hugh/index.html resource. The action is to retrieve the HTML document stored in the file index.html.
The first line of the message is the request and contains the method name GET, the request URL /~hugh/index.html, and the HTTP version HTTP/1.1, each separated by a space character. The request is followed by a list of header fields. Each field is represented as a name and value pair separated with a colon character, and each field is on a separate line.
The header fields are followed by a blank line and then by the optional body of the message. A POST method request usually contains a body of text, as we discuss in the next section.
D.2.2.1 Request methods
There are six request methods, but only three are used in practice:

GET
Retrieves a resource. A query can be used to add extra information to the GET request and, as we discussed in our introduction to URLs, these are appended to the URL itself. A database search is a good example of an application of the GET request: the resource is likely to be a web script, and the query component of the URL is the search conditions.

POST
Sends data to a server. Rather than appending data to the URL, the data is sent in the body of the HTTP request.

HEAD
Requests only the header fields as a response, not the resource itself. This can be used for lightweight retrieval, so that the modification date of a resource can be checked before the full resource is retrieved with GET.

DELETE
Allows a resource identified by the URL to be deleted from a server. This is the counterpart to the PUT method discussed next and it allows an author to remove a resource from the specified URL. It's usually not implemented by web servers.

PUT
Similar to the POST method, this method is designed to put a resource onto a server. Some HTML editors and web servers support the PUT methods allowing authors to put resources onto a web site at the specified URL. However, it's usually not implemented by web servers.

TRACE
Produces diagnostic information.
The HTTP standard divides these methods into those that are safe and those that aren't. The safe methods—GET and HEAD—don't have any persistent side effects on the server. The unsafe methods—POST, PUT, and DELETE—are designed to have persistent effects on the server. The standard allows for clients to warn users that a request may be unsafe and, for example, most browsers won't resend a request with the POST method without user confirmation.
The HTTP standard further classifies methods as idempotent when a request can be repeated many times and have the same effect as if the method was called once. The GET, HEAD, PUT, and DELETE methods are classified as idempotent. The POST method isn't.
D.2.2.2 GET versus POST
Both the GET and POST methods send data to the server, but which method should you use?
The HTTP standard includes the two methods to achieve different goals. The POST method was intended to create a resource. The contents of the resource would be encoded into the body of the HTTP request. For example, an order form might be processed and a new row in a database created.
The GET method is used when a request has no side effects (such as performing a search) and the POST method is used when a request has side effects (such as adding a new row to a database). A more practical issue is that the GET method may result in long URLs, and may even exceed some browser and server limits on URL length.
Use the POST method if any of the following are true:
  • The result of the request has persistent side effects such as adding a new database row.
  • The data collected on the form is likely to result in a long URL if you used the GET method.
  • The data to be sent is in any encoding other than seven-bit ASCII.
Use the GET method if all the following are true:
  • The request is to find a resource, and HTML form data is used to help that search.
  • The result of the request has no persistent side effects.
  • The data collected and the input field names in a HTML form are in total less than 1,024 characters in size.

D.2.3 HTTP Responses

When a web server processes a request from a browser, it attempts to apply the method to the identified resource and create a response. The action of the request may succeed or fail, but the web server always sends a response message back to the browser.
A HTTP response message contains a status line, header fields, and (usually) the requested entity as the body of the message. For example, the following is the result of a GET method request for a small HTML file:
HTTP/1.1 200 OK

Date: Sun, 19 Dec 2004 02:54:37 GMT

Server: Apache/2.0.48

Last-Modified: Fri, 19 Dec 2003 02:53:08 GMT

ETag: "4445f-bf-39f4f994"

Content-Length: 321

Accept-Ranges: bytes

Connection: close

Content-Type: text/html

 





Grapes and Glass





Welcome to my simple page 






The first, status line begins with the protocol version of the message, followed by a status code and a reason phrase, each separated by a space character. The status code is a number and the reason phrase describes its meaning; these are discussed in the next section. The status line is then followed by the header fields. As with the request, each field is represented as a name and value pair separated with a colon character. A blank line separates the header fields from the body of the response, in this case an HTML document.
D.2.3.1 Status codes
HTTP status codes are used to classify responses to requests. The HTTP status code system is extensible, with a set of codes described in the standard that are "generally recognized in current practice". HTTP defines a status code as a three-digit number, where the first digit is the class of response. The following list shows the five classes of codes defined by HTTP:

1xx
Informational. HTTP 1.1 uses codes in this class to indicate the request has been received by the server and that processing is continuing.

2xx
Success. The request was successfully received, and the action successfully performed.

3xx
Redirection. When a response has a redirection code, the client needs to make a further request to get the specified resource. The URL of the actual resource is included in the response header field Location. When the status code is set to 301, the browser automatically makes the request for the URL specified in the Location header field. The use of the Location header field is discussed further in Chapter 6, and used in many examples throughout this book.

4xx
Client error. The request can't be processed because of bad syntax of the message, the sender is unauthorized or forbidden to access the resource, or the resource can't be found.

5xx
Server error. The server failed to fulfill a valid request.

D.2.4 Caching

Most user agents, such as web browsers, allow HTTP responses to be cached. HTTP responses are cached by saving a response to a request in memory. When a browser considers a request, it first looks to its local cache to see if it has an up-to-date copy of the response before sending the request to the web server. This can significantly reduce the number of requests sent to a web server, improving the performance of the web application and responsiveness to users.
Consider a web site that includes a company logo on the top of each HTML page:

When the browser requests a page that contains the image, a separate request is sent to retrieve the image /images/logo.gif. If the image resource is cacheable, and browser caching is enabled, the browser saves the response. A subsequent request for the image is recognized, and the local copy from the cache is used rather than sending another request to the web server.
A browser uses a cached response until the response becomes stale, or the cache becomes full and the response is displaced by the resources from other requests. The primary mechanism for determining if a response is stale is comparing the date and time set in the Expires header field with the date and time of the machine running the browser. If the date and time are incorrectly set on the machine, a cached response may expire immediately or be cached longer than intended.
HTTP describes the conditions that allow a user agent to cache a response. However, there are many situations in which an application may wish to prevent a page from being cached, particularly when the content of a response is dynamically generated, such as in a web database application.
HTTP/1.1 uses the Cache-Control header field as its basic caching control mechanism. For example, setting the Cache-Control header field to no-cache in a HTTP response prevents the response from being cached by a HTTP/1.1 user agent. The header can be used in requests and responses, but we consider only responses here.
Some HTTP/1.1 Cache-Control settings are directed to user agents that maintain caches for more that one user, such as proxy servers. Proxy servers are used to achieve several goals, the most important of which is to provide caching of responses for a group of users. A local network, such as that found in a university department, can be configured to send all HTTP requests to a proxy server. The proxy server forwards requests to the destination web server and passes back the responses to the originating client.
Proxy servers can cache responses and thus reduce requests sent outside the local network. Setting the Cache-Control header field to public allows a user agent to make the cached response available to any request. Setting the Cache-Control header field to private allows a user agent to make the cached response available only to the client who made the initial request.
Setting the Cache-Control header to no-store prevents a user agent from storing the response on disk. This prevents sensitive information from being inadvertently saved beyond the life of a browser session. HTTP/1.1 defines several other Cache-Control header fields not described here.
 Day Up > 


news sources from :

Sunday, September 15, 2013

Modularity

A good programming large programs should be broken down into small programprogram hereinafter called modules . Small modules that can be invoked at any time required . In PHP also supports the concept of modularity , hereinafter named . We can insert the contents of a file / another module to the file / module specific . There are 2 command / function for that in PHP is using include and require .
Include ( )For ease of understanding , the following example is given . Suppose we are going to make a menu link index number is 4 pieces , about , links , and contact on every web page that we created . The technique used is to create a menu link in a separate module and then the module is invoked at any desired web page there is a menu link in it .menu.php


Home < / a> About Us < / a> Links < / a> Contact Us < / a>index.php< ? phpinclude (" menu.php " ) ;? > This is the index page < / p >< / body>< / html >about.php< ? phpinclude (" menu.php " ) ;? > This is a page about < / p >< / body>< / html >
From the above it appears the technique easily create web pages . In this case , we do not need to create a menu link on any existing web page . Imagine if we had a total of 100 pieces of web pages who all want to be tanpan menu link using the above technique , of course it is very troublesome . Although technically , web builder code broken into modules , but when dibrowser be seen together . Here is the HTML code generated by the browser when it opens a web page index.php


Home < / a> About Us < / a> Links < / a> Contact Us < / a> This is the index page < / p >< / body>
< / html >
Require ( )How to use and function of require ( ) together with include ( ) . So what's the difference ?Which should we use ? Consider the following example

< ? phpinclude (" noFileExistsHere.php " ) ;echo " Hello World ! " ;? >
 assuming that no noFileExistxHere.php file .Then by using the include ( ) will be generated display :Warning : main ( noFileExistsHere.php ) : failed to open stream: No such file or directory in include.php on line 2Warning : main ( ) : Failed opening ' noFileExistsHere.php ' for inclusion 
( include_path = ' . :/ usr / lib / php :/ usr / local / lib / php ' ) in include.php online 2Hello WorldNext we will use require ( ) .

< ? phprequire ( " noFileExistsHere.php " ) ;echo " Hello World ! " ;? >and resultsWarning : main ( noFileExistsHere.php ) : failed to open stream: No suchfile or directory in require.php on line 2Fatal error : main ( ) : Failed opening required ' noFileExistsHere.php '( include_path = ' . :/ usr / lib / php :/ usr / local / lib / php ' ) in require.php online 2
Compare the two results above , especially those printed in red . In the include () , errorWarning alone produced only in the form and still be able to run the next statement . it isseen that the text Hello World ! Still displayed in the browser . While the require ( ) ,error that produced a Fatal Error . Thus the next statement will not beexecuted .It is recommended that you use require ( ) in the hope that the PHP code that youmake will not be processed if there are files missing or do not exist.
 

news sources from :Rosihan Ari Yuana

Taking data from MySQL

Retrieving data here related to the use of the SELECT query. Here is an example for
displays the first record of the table example.

<? php
mysql_connect ("localhost", "admin", "1admin") or die (mysql_error ());
mysql_select_db ("test") or die (mysql_error ());
$ result = mysql_query ("SELECT * FROM example")
or die (mysql_error ());
/ / Save the record to the variable $ data
$ record = mysql_fetch_array ($ result);
/ / Display the data from the $ record for each field
echo "name:". $ record ['name']. "
";
echo "He:". $ record ['age'];
?>
 
Output script above is:
His name: sapient
Age: 20
The above command will only display the first record of the table example. then,
how to display more than one record?
To display more than one record, we use looping. Consider the following example
Here you are.
 
<? php
mysql_connect ("localhost", "admin", "1admin") or die (mysql_error ());
mysql_select_db ("test") or die (mysql_error ());
$ result = mysql_query ("SELECT * FROM example")
or die (mysql_error ());
while ($ record = mysql_fetch_array ($ result))
{
echo "name:". $ record ['name']. "
";
echo "He:". $ record ['age']. "
";
}
?>

Looping while above will continue to run as long as the record is still there to be read. Results from script
above is
His name: sapient
Age: 20
His name: Surti
Age: 30
 
Note:
To make it easier for you in the administration and manage the MySQL database,
highly recommended to install phpMyAdmin which can be downloaded via the official website at http://phpmyadmin.sourceforge.net/
news sources from :Rosihan Ari Yuana

Giving to the MySQL Query

Once we select the database in which we will work, then we can give
query commands such as SELECT, DELETE, CREATE, UPDATE. Here's an example PHP script
for example create a table in the test database.
<? php
mysql_connect ("localhost", "admin", "1admin") or die (mysql_error ());
mysql_select_db ("test") or die (mysql_error ());
mysql_query ("CREATE TABLE example (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR (30),
age INT)
PRIMARY KEY (id) ")
or die (mysql_error ());
echo "The table has been created";
?>

In the example above, it can be seen that the PHP command to write the query to MySQL
is
mysql_query ("query");
While the following sample script to insert 2 pieces of records / data to the table example.
<? php
mysql_connect ("localhost", "admin", "1admin") or die (mysql_error ());
mysql_select_db ("test") or die (mysql_error ());
mysql_query ("INSERT INTO example (name, age)
VALUES ('dear', 20) ");
mysql_query ("INSERT INTO example (name, age)
VALUES ('Surti', 30) ");
echo "Data has been entered";
?>

news sources from :Rosihan Ari Yuana

choosing a Database

Once the connection is successful, then we can choose the database that we want. The
command using mysql_select_db ().
example:
 
<? php
mysql_connect ("localhost", "admin", "1admin") or die (mysql_error ());
echo "Connected to MySQL
/>";
mysql_select_db ("test") or die (mysql_error ());
echo "Connected to Database";
?>
 
The above example illustrates how to connect to MySQL with name
server is localhost, username: admin, and password: 1admin. Furthermore choose
test database.



news sources from : Rosihan Ari Yuana

PHP Connection to MySQL


Before we connect to MySQL there are some parameters that we need to know
first. To make the connection, it takes:
- Server name, the name of the server or no. Where the MySQL server IP
installed
- Username, a user name that is authorized to access the database
in MySQL
- Password, a password in order to authenticate usernames owned.
- Database name, the name of the database in MySQL that we want to access.
To obtain information on the parameters above, please contact the server administrator.
While PHP commands to connect to MySQL is



mysql_connect ("name server", "username", "password") or
die (mysql_error ());
echo "Connection to MySQL Success";
?>;



The above command will display the connection to MySQL successfully if the connection has been successful,
whereas if it fails to display an error message

news source : Rosihan Ari Yuana

Friday, May 6, 2011

PHP Tutorial Part 2 - Displaying Information & Variables

Introduction

In the last part of the tutorial I explained some of the advantages of PHP as a scripting language and showed you how to test your server for PHP. In this part I will show you the basics of showing information in the browser and how you can use variables to hold information.

Printing Text

To output text in your PHP script is actually very simple. As with most other things in PHP, you can do it in a variety of different ways. The main one you will be using, though, is print. Print will allow you to output text, variables or a combination of the two so that they display on the screen.

The print statement is used in the following way:

print("Hello world!");

I will explain the above line:

print is the command and tells the script what to do. This is followed by the information to be printed, which is contained in the brackets. Because you are outputting text, the text is also enclosed instide quotation marks. Finally, as with nearly every line in a PHP script, it must end in a semicolon. You would, of course, have to enclose this in your standard PHP tags, making the following code:


print("Hello word");


Which will display:

Hello world!

on the screen.

Variables

As with other programming languages, PHP allows you to define variables. In PHP there are several variable types, but the most common is called a String. It can hold text and numbers. All strings begin with a $ sign. To assign some text to a string you would use the following code:

$welcome_text = "Hello and welcome to my website.";

This is quite a simple line to understand, everything inside the quotation marks will be assigned to the string. You must remember a few rules about strings though:

Strings are case sensetive so $Welcome_Text is not the same as $welcome_text
String names can contain letters, numbers and underscores but cannot begin with a number or underscore
When assigning numbers to strings you do not need to include the quotes so:

$user_id = 987

would be allowed.

Outputting Variables

To display a variable on the screen uses exactly the same code as to display text but in a slightly different form. The following code would display your welcome text:





As you can see, the only major difference is that you do not need the quotation marks if you are printing a variable.

Formatting Your Text

Unfortunately, the output from your PHP programs is quite boring. Everything is just output in the browser's default font. It is very easy, though, to format your text using HTML. This is because, as PHP is a server side language, the code is executed before the page is sent to the browser. This means that only the resulting information from the script is sent, so in the example above the browser would just be sent the text:

Hello and welcome to my website.

This means, though, that you can include standard HTML markup in your scripts and strings. The only problem with this is that many HTML tags require the " sign. You may notice that this will clash with the quotation marks used to print your text. This means that you must tell the script which quotes should be used (the ones at the beginning and end of the output) and which ones should be ignored (the ones in the HTML code).

For this example I will change the text to the Arial font in red. The normal code for this would be:




As you can see this code contains 4 quotation marks so would confuse the script. Because of this you must add a backslash before each quotation mark to make the PHP script ignore it. The code would chang
e to:




You can now include this in your print statement:

print("Hello and welcome to my website.");

which will make the browser display:

Hello and welcome to my website.

because it has only been sent the code:

Hello and welcome to my website.

This does make it quite difficult to output HTML code into the browser but later in this tutorial I will show you another way of doing this which can make it a bit easier.

Part 3

In part 3 I will introduce If statements.

news sources from : www.freewebmasterhelp.com

PHP Tutorial Part 1 - Introduction

Introduction

Up until recently, scripting on the internet was something which very few people even attempted, let alone mastered. Recently though, more and more people have been building their own websites and scripting languages have become more important. Because of this, scripting languages are becomming easier to learn and PHP is one of the easiest and most powerful yet.

What Is PHP?

PHP stands for Hypertext Preprocessor and is a server-side language. This means that the script is run on your web server, not on the user's browser, so you do not need to worry about compatibility issues. PHP is relatively new (compared to languages such as Perl (CGI) and Java) but is quickly becomming one of the most popular scripting languages on the internet.

Why PHP?

You may be wondering why you should choose PHP over other languages such as Perl or even why you should learn a scripting language at all. I will deal with learning scripting languages first. Learning a scripting language, or even understanding one, can open up huge new possibilities for your website. Although you can download pre-made scripts from sites like Hotscripts, these will often contain advertising for the author or will not do exactly what you want. With an understanding of a scripting language you can easily edit these scripts to do what you want, or even create your own scripts.

Using scripts on your website allows you to add many new 'interactive' features like feedback forms, guestbooks, message boards, counters and even more advanced features like portal systems, content management, advertising managers etc. With these sort of things on your website you will find that it gives a more professional image. As well as this, anyone wanting to work in the site development industry will find that it is much easier to get a job if they know a scripting language.

What Do I Need?

As mentioned earlier, PHP is a server-side scripting language. This means that, although your users will not need to install new software, you web host will need to have PHP set up on their server. It should be listed as part of your package but if you don't know if it is installed you can find out using the first script in this tutorial. If you server does not support PHP you can ask your web host to install it for you as it is free to download and install. If you need a low cost web host which supports PHP I would recommmend HostRocket.





Writing PHP

Writing PHP on your computer is actually very simple. You don't need any specail software, except for a text editor (like Notepad in Windows). Run this and you are ready to write your first PHP script.

Declaring PHP

PHP scripts are always enclosed in between two PHP tags. This tells your server to parse the information between them as PHP. The three different forms are as follows:








All of these work in exactly the same way but in this tutorial I will be using the first option (). There is no particular reason for this, though, and you can use either of the options. You must remember, though, to start and end your code with the same tag (you can't start with for example).

Your First Script

The first PHP script you will be writing is very basic. All it will do is print out all the information about PHP on your server. Type the following code into your text editor:



As you can see this actually just one line of code. It is a standard PHP function called phpinfo which will tell the server to print out a standard table of information giving you information on the setup of the server.

One other thing you should notice in this example is th
at the line ends in a semicolon. This is very important. As with many other scripting and programming languages nearly all lines are ended with a semicolon and if you miss it out you will get an error.

Finishing and Testing Your Script

Now you have finished your script save it as phpinfo.php and upload it to your server in the normal way. Now, using your browser, go the the URL of the script. If it has worked (and if PHP is installed on your server) you should get a huge page full of the information about PHP on your server.

If your script doesn't work and a blank page displays, you have either mistyped your code or your server does not support this function (although I have not yet found a server that does not). If, instead of a page being displayed, you are prompted to download the file, PHP is not installed on your server and you should either serach for a new web host or ask your current host to install PHP.

It is a good idea to keep this script for future reference.

Part 2

In this part I have introduced you to the basics of writing and running PHP. By this time you should now know if your host supports PHP and should have a basic understanding of how PHP scripts are structured. In part 2 I will show you how to print out information to the browser

news sources from : www.freewebmasterhelp.com

Wednesday, December 9, 2009

Preventing Home Website Published In the Inline Frame

Have you use inline frames to display other web pages? Exciting is not it? However, this fact becomes unpleasant for the owner of the website pages are pages that appear in the frame. For an admin who understand this is certainly very bad, because the use of frames to display other websites without the consent of the parties involved with the theft of data, and of course the other impact is sucked bandwidth would be greater, and others, is bad in the search engine, the black list, because it is considered cheating in SEO path.

So what's the solution?
Actually something like this could be prevented with a simple javascript.
Put the script below on every page you want to protectionism. Very easy.

Script on the duty to detect:
if the url of the page accessed is not the actual url where the page is, then do redirect to the original url.
Okay, so. Good try.

Tutorial files can be downloaded here::
http://ilmuwebsite.com/file_tutorial/inlineframe.zip

Making Tricks with Image Submit Button

Okay, maybe in the beginning most of the web developer has ever wondered how to make an image a submit button of a form. And these functions are found have been used in some of your favorite Content Management System, joomla for example, when you make a save item, whether it's article, or a product in VirtueMart component utilizing backendnya, there seemed an image that has a function as a submit button. There are 2 tricks that are usually used, first use html tags, and the latter using a simple javascript function.

Yes, we try to advance to the first trick ...
Create a file, call up to you, I call it imgbtn.html, then the contents therein:

name="formulir" action="kirim.php"

Name:



Which has its core functions:
line
make an input with type image.

then, kirim.php file, this file is used to capture what has been sent by imgbtn.html, of course, you must have a web server that has been installed in your pc to try it. But at the end of this article the author provides html demo files from this article.

File kirim.php

You can not use features like hover buttons in this first trick, tag input type = 'image' does not allow you to change the image when the mouse over, or when the mouse out. Recommended changes in image / image when mouse over or mouse out obtained by using the next trick.

Then the final trick, this trick before the development of the tricks. If the first trick that allows only a static image, then the second trick you can install this feature as an image change mouseover or mouseout.

Provide a imgtbn2.html file, containing:


name="formulir" action="kirim.php"

Name:

Submit this form

This last trick, using the tag
and utilize diembedkan javascript function.
Core statement:
onclick = "return val_form_this_page ()">
when image is clicked then the return value of the filled in form in the document for later action sent to the target, ie kirim.php.
With this trick

and kirim.php file php file that is to capture the variable that is sent.

So, you can use this trick to use in doing your website development. Thank you.
By: Dwiartara Loka.

This tutorial files can be downloaded here:
http://www.ilmuwebsite.com/file_tutorial/trikimagebutton.zip

Wednesday, November 25, 2009

Creating Admin with 1 IP Access

Each website must have an admin page. Page admin here means the web pages that are used by webmasters to manage content and web interface. Surely we would not want if the admin page is known by other parties. Using your username and password fine. But did not rule out another user will try mecoba login security that you created.

In addition to using the username and password, there are other ways to secure the admin page. Namely by limiting the IP Address. So only certain IP address that can open the pages of this admin. Ah, after a long story, of course you can not wait to find out how to create a secure admin page.

First of all, you need to know your IP address. To find out, you can use the following command:


print? IP you:?. $ HTTP_SERVER_VARS [ 'REMOTE_ADDR'];
?>

If so, then in the admin section, for example you put in the folder? Administrator / index.php?, You type the following command at the beginning of the script:


$ ip =? 127.0.0.1? / / Ip which has been noted previously
if ($ HTTP_SERVER_VARS [ 'REMOTE_ADDR']! = $ ip) (
header (? location: .. / index.php);
) Else (
Setcookie (? Ip?, $ Ip);)
?>

Then for every other web page, (which is also found in the administrator folder) you add the following command:


$ ip =? $ _COOKIE [? ip?];? / / Call cookies ip
if ($ HTTP_SERVER_VARS [ 'REMOTE_ADDR']! = $ ip) (
print? You do not have rights to access this page .....!!!!?;
) Else (
/ / Display your menu
)
?>

Do not forget to do the call or session cookies for the username and password you created. The above examples are only for calling cookies to IP Address. You can also create more than 1 IP Address that can access your admin. Of course by using the database.

CREATE TABLE `web_saya`. Tb_admin `` (
`id` BIGINT (20) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`ip` VARCHAR (30) NOT NULL
) ENGINE = MyISAM

INSERT INTO `web_saya`. Tb_admin `` (
`id`,
`ip`
)
VALUES (
NULL, '127 .0.0.1 '
);

Config.php

$ host =? localhost?;
$ user =? root?;
$ pass =??;
$ conn = mysql_connect ($ host, $ user, $ pass) or die (? Check the host name, user, or pass ..?);
$ pilih_db = mysql_select_db (? web_saya?);
?>

Then in the index.php located in the folder administrator, you type the following script:

Index.php


Include (? Config.php?);
$ ip = $ HTTP_SERVER_VARS [ 'REMOTE_ADDR'];
$ valid_ip = mysql_query (? tb_admin SELECT * FROM WHERE ip =? $ ip??);
if (! = $ valid_ip) (
print? You do not have rights to access this page!?;
) Else (
/ / Display your admin menu
)
?>

With the above script, you can enter more than 1 IP address that can access your admin page ..

Good luck ....

Lethal right-click function

()
message = "Copyright - ilmuwebsite.com Team 2007";
function click (e) (
if (document.all) (
if (event.button == 2) (
alert (message);
return false;
)
)
if (document.layers) (
if (e.which == 3) (

alert (message);
return false;
)
)
)
if (document.layers) (
document.captureEvents (Event.MOUSEDOWN);
)
document.onmousedown = click;
/ / ->