Thursday, December 13, 2007

How can I execute a PHP script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

Tuesday, December 11, 2007

difference between get and post?

A GET request is a request to get a resource from the server. Choosing GET as the "method" will append all of the data to the URL and it will show up in the URL bar of your browser. The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters.

A POST request is a request to post (to send) form data to a resource on the server.

A POST on the other hand will (typically) send the information through a socket back to the webserver and it won't show up in the URL bar. You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects!

The GET method appends name/value pairs to the URL. Unfortunately, the length of a URL is limited, so this method only works if there are only a few parameters. The URL could be truncated if the form uses a large number of parameters, or if the parameters contain large amounts of data. Also, parameters passed on the URL are visible in the address field of the browser not the best place for a password to be displayed.

The POST method packages the name/value pairs inside the body of the HTTP request, which makes for a cleaner URL and imposes no size limitations on the forms output. It is also more secure.

Sunday, December 9, 2007

What is the difference between session and cookie?

1. The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not.

2.A cookie can keep information in the user's browser until deleted. But Session work instead like a token allowing access and passing information while the user has their browser open.

3.The difference between sessions and cookies is that a session can hold multiple variables, and you don’t have to set cookies for every variable. By default, the session data is stored in a cookie with an expiry date of zero, which means that the session only remains active as long as the browser. When you close the browser, all the stored information is lost. You can modify this behavior by changing the “session.cookie_lifetime” setting in “php.ini” from zero to whatever you want the cookie lifetime to be.

In PHP:

session_start(); //starts or resumes a function
session_destroy(); //ends the session; comment this line and the browser will output the same session ID as before
If you want to remove the registered variables, you need to use the session_unset() function.