PHP4/IP address

Advertisement


Question
ok that was a nice idea but there is some problem.

Warning: Cannot modify header information - headers already sent by (output started at

i used like this code example
setcookie("user", "Alex Porter", time()+3600);

and i retrive this by using:
$username = $_COOKIE["user"];
then the warning show up. then i cant store cookies.  
could you tell me whats wrong and how could i fix this problem. thanks!

Answer
The problem you are having is this: when a webpage is sent from a server to a client, first the headers are sent over, which define some basic data about the page, and then the html of the page is sent over. The operation you are attempting requires adding some data to the header, but obviously this cannot be done once the headers have finished and the html is being sent across. Try doing this before you start echoing things onto the page and it should work. However, it is easiest to use $_SESSION :) In this case, just set all the variables up (using cookies or session) before you echo anything and echo based on this.

PHP4

All Answers


Ask Experts

Volunteer


Draicone

Expertise

I can answer almost all things related to php, and have years of experience coding for almost any situation. Snippets and bug fixes are the most common issues I deal with.

Experience

For the past four years I have been coding in php for various purposes. My recent uses of the skill have been in coding for xtraticwar.com, an online game written entirely in php that has allowed me to make use of my various experience with the language. For mathematical purposes I once turned an algorithm relating to probability into php code to calculate all possibilitie

Organizations
None.

Publications
School newsletters, general publications.

Education/Credentials
None related to the category.

Awards and Honors
None related to the category. However, I won the 2006 ICAS Computer Skills competition.

Past/Present clients
XtraticWar.com, LogicZero.net, Combobularity@SPLC (a toastmasters public speaking club requiring a web presence).

©2012 About.com, a part of The New York Times Company. All rights reserved.