Recent Entries
- Tips to Avoid Sp...
- Popular Torrent...
- Tips for Creatin...
- Save The Interne...
- Win a 1990 FJ62...
- Mile-Hi SkyDivin...
- USBank: Prevent...
- KTorrent, Linux'...
- Converting from...
- Isagenix is a Co...
Random Entries
PHP SetCookie with Localhost and Apache
Jan 19th, 2006 - Subscribe
Keywords: Apache Localhost with PHP
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!
![]()
Comments:
david
on January 20th, 2006
![]()
converge
on January 23rd, 2006
-clark
![]()
frost
on January 23rd, 2006
--FrosT
![]()
converge
on January 23rd, 2006
also, if i want my blog in the CENTER of the screen versus the left side of the page, how and where do i go in and fix that? can you help me if you arent too busy there docta frost. thanks chief
![]()
frost
on January 24th, 2006
--FrosT
![]()
converge
on January 25th, 2006
-c-
![]()
frost
on January 25th, 2006
--FrosT
![]()
aeonity
on January 25th, 2006
![]()
converge
on January 25th, 2006
![]()
aeonity
on January 25th, 2006
![]()
converge
on January 25th, 2006
![]()
frost
on January 25th, 2006
--FrosT
![]()
anonymous
on February 15th, 2006
ex. setcookie("user","george",time()+3600,"/"
; works whearassetcookie("user","georgy",time()+3600); doesn't
![]()
frost
on February 15th, 2006
--FrosT
![]()
anonymous
on September 17th, 2006
Thank you!
![]()
anonymous
on December 16th, 2006
output_buffering = On
(output_buffering = Off)
; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit. You can enable output buffering during runtime by calling the output
; buffering functions. You can also enable output buffering for all files by
; setting this directive to On. If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On', as
; a value for this directive (e.g., output_buffering=4096).
RGS mfunk
![]()
anonymous
on May 10th, 2007
![]()
anonymous
on July 12th, 2007
Ps. to the previous commenter... you destroy the cookie the same as you do regular cookies: you eat it! :-) Just kidding...
Simply replace the expiration time to sometime in the past like: time()-1 (it's the third parameter)
Hope that helps.
-Steve
![]()
anonymous
on November 27th, 2007
Most browsers will throw a domain name with less than two dots away. If you don't send a domain through with the cookie request the browser will save it with the current domain of the site (localhost).
Adam
![]()
anonymous
on February 17th, 2008
![]()
anonymous
on March 29th, 2008
![]()
anonymous
on May 08th, 2008
Spot on, shame I just put my foot through my latest computer though due to this.
Thanks for taking the time to document it.
I'm off to get another computer so I can try it.
Cheers.
Jaz
![]()
anonymous
on May 13th, 2008
Can you please tell me what to put in the Network Domain, Server Name and Admin Email Address fields requested in the installation? I know these are used in the config file but I can't remember what to put.
If you can help I would grateful.
Regards,
Chris
![]()
anonymous
on May 16th, 2008
![]()
anonymous
on May 18th, 2008
@Anonymous on May 16th, 2008:
Try an if($_SERVER == "localhost"
{ } else { } construct ^^ That's how I save myself effort between my testing and live servers.
![]()
anonymous
on May 18th, 2008
![]()
jgooda
on May 20th, 2008
![]()
