Once your web application has set a cookie in a user’s browser, it is a simple matter to retrieve that value in subsequent page requests. This recipe describes reading a value from a cookie in PHP.

After a cookie with a name of ‘user’ has been set in a previous page, the value can be accessed with the global array $_COOKIE like this:

$user = $_COOKIE['user'];

Since this is a normal array, anything you can do to an array like iterate through it one value at a time. For debugging purposes, it is often useful to use this quick trick to see the whole contents of an array:

print_r($_COOKIE);

courtesy http://www.tech-recipes.com/rx/1500/php-read-a-browser-cookie-value/

Web applications overcome the lack of session support in the HTTP protocol primarily through the use of cookies. Transparent to the user and simple for the web developer, cookies provide the foundation of keeping up with who a web user is, where they’ve been, and what they had for lunch. Well, who and where, anyway.

The built-in PHP function setcookie() creates or updates a cookie name/value pair in the user’s browser. A cookie contains information sent by a web server to a user’s browser. Whenever a web page is accessed at that server that meets the requirements, cookies associated with that server (that haven’t expired) are sent back without modification to the server.

The basic cookie consists of a name and a value. For example, a cookie with name ‘user’ can be set to the user’s username, possibly encoded for security. To set the cookie user with the value ‘qmchenry’ use this command:

setcookie(‘user’,'qmchenry’);

This cookie has a default expiration time of 0 which means it will persist until the browser is closed.

It is important to note that cookie information is sent in the web page response headers and, like other times PHP needs to change header values, the setcookie function must be called before any output is sent to the user.

courtesy http://www.tech-recipes.com/rx/1499/php-set-or-create-a-simple-browser-cookie-with-setcookie/

Working with server-side files with PHP adds a great deal of flexibility to some applications. A common scenario when working with files involves creating a temporary file through uploading or other means and then renaming this file to a permanent location. This recipe describes changing the name of an existing file using the PHP function rename().

The syntax for the PHP rename function is consistent with that of the UNIX mv function, which always makes things more comfortable. The general syntax is:

rename(‘/path1/old_filename’, ‘/path2/new_filename’);

The rename function returns true if the rename was successful, and false otherwise.

Just like with the unlink function which deletes files, the rename function most likely fails because of file permissions. To rename a file, the directory containing it must be writable by the user trying to rename it. The file’s permissions (and ownership) are irrelevant.

courtesy http://www.tech-recipes.com/rx/1492/php-rename-or-move-a-file-on-the-server/

Preface:

I showed you here how to set up PHP using the CGI executable. Since then I’ve learnt that the ISAPI DLL may be faster and more secure, so this tutorial will show you how to set up the ISAPI DLL instead. Credit and thanks goes to Keith W. McCammon for setting this up on his website, http://mccammon.org/php/iis6_install.php . Made visual with permission from Keith. Something to note is that these directions had in mind default (unmodified) ACLs/Permissions.

Method:

Unzip the latest PHP ZIP file to C:\PHP, and copy php.ini-recommended from that folder to C:\windows\php.ini, then copy php4ts.dll to C:\Windows\System32

Load IIS from the Administrative tools in the Control Panel by clicking Start -> Administrative Tools -> IIS Manager (or loading the Control Panel, entering the Administrative Tools folder, and double clicking IIS Manager).

Click the name of your computer then click “Web Service Extensions”, on the left side of the main frame you will see a green arrow pointing to a link that says “Add a new Web service extension…”, click that link.

Set the extension name to anything you’d like, put C:\PHP\sapi\php4isapi.dll as the Required file, also check “Set status to allowed”

Go to the directory you’d like to configure PHP for in the IIS Manager, right click it, and select properties

Click the Create button, set the Execute permissions to “Scripts only”, then click the Configuration button

Click Add. For the Executable put – C:\PHP\sapi\php4isapi.dll for the Extension put “.php”, set the verbs to all, and make sure the bottom check boxes are checked

Click OK and OK

Gud Luck!

Thanks to http://www.visualwin.com/PHP-ISAPI/

he following things are pre-assumed:

1. You are running Windows Server 2003
2. IIS 6.0
3. You have installed PHP (http://www.php.net) to C:\PHP (installation issues are at the bottom of this page)
4. You are using default (unmodified) ACLs/Permissions

Update: Tom McDermid has brought to my attention that in the PHP 5 line, the EXE name is “php-cgi.exe” instead of “php.exe”, so when installing PHP 5, remember to replace “php.exe” in this tutorial with “php-cgi.exe”

Load IIS from the Administrative tools in the Control Panel by clicking Start -> Administrative Tools -> IIS Manager (or loading the Control Panel, entering the Administrative Tools folder, and double clicking IIS Manager).

Click the name of your computer then click “Web Service Extensions”, on the left side of the main frame you will see a green arrow pointing to a link that says “Add a new Web service extension…”, click that link.

For the Extension name put something like “PHP” in and for the Required Files put “C:\PHP\php.exe”, also check to set it to allowed

Now load a command prompt (Start->Run… type cmd) and type “md c:\inetpub\wwwroot\phpscript”

Back in the IIS Manager double-click “Web Sites”, click “Default Web Site”, right-click the directory “phpscript” and click properties

In the new dialog click Create then Configuration (Configuration will only become enabled after you click Create). If you don’t see .php listed then add it by clicking Add… and setting the following

Click OK and OK and you should be set to run your PHP scripts

Installation issues

Q: I tried installing PHP and got some error about there not being an OCX or something, either way, now I can’t execute my scripts :-(

A: The error you received was stating that an OCX control (ActiveX) that the PHP installer uses wasn’t found, don’t worry, that’s the reason I wrote this tutorial :-)

My reasoning

Q: Why do you use the Command prompt to make directories when you can just load Explorer and make it that way?

A: It’s much simpler to do in Command, that’s why I do it. Also, it makes you look smarter, which is a good thing in general, especially when you’re working on a Server :-)

Thanks to http://www.visualwin.com/PHP/