PHP SetCookie with Localhost and Apache
PHP SetCookie with Localhost and Apache
by FrosT
Introduction
As some developers may not know working with a localhost Apache and PHP server requires different setups than working with an actual domain name on a remote server. This article will discuss how to setup your script correctly to store localhost cookies with FireFox and Internet Explorer without too much of a hassel.
Development Coding
You may want to have a development PHP and Apache server on your own local computer to program and test data and new changes to your current web development software. A local Apache and PHP server allows for easy programming with a plus of not having to upload programmed files to the production server. But what about storing cookies on Localhost? Well I recently came across an issue with the setcookie function on the localhost Apache and PHP server. I searched sometime to find the answers I was looking for. Lets dive in!
SetCookies with Localhost and Apache
Setting cookies on localhost with Apache and PHP running is not to much of a chore. I would recommend coding a particular part for your development box that is strictly for it to house all the necessary modified settings, such as setcookies. Here is the correct format needed to SetCookies on localhost box with Apache and PHP.
setcookie("username", "George", false, "/", false);
Using that code to set the cookie the web application needs will save someheartache. I do not know the whole reasoning why the setcookie must be set up in that format, but I do know using the setcookie formatted as above with your development system does work!
Ending Notes
Using the format of the setcookie function with PHP and Apache works great on a Localhost. I love this for my development server, grant it I have variables set for domain and time so I can change all this with one swoop of a config file. Set it up the way you want on your localhost Apache and PHP server. Now you have the correct setcookie code, use it at your own risk!
; works whearas
saved me a lot of coding to work around my off server domain testing lol