Add to Google

Errors With Php Setcookie() And Headers! Please Help! - Having header errors when I try to set a cookie with PHP function setc

free web hosting
Open Discussion > General > Hosted Members Area

Errors With Php Setcookie() And Headers! Please Help! - Having header errors when I try to set a cookie with PHP function setc

runeco
Hey guys, I'm having a problem setting cookies with PHP. I am trying to implement a script that will allow someone to log in and access members only pages on my website. One of the aspects is that I have to place a cookie on that persons computer. I know that you can use the PHP function setcookie() to place it on your computer. The problem is that wherever i have setcookie() in my PHP code I get an error:

"Warning: Cannot modify header information - headers already sent by (output started at /home/runeco/public_html/cookie.php:6) in /home/runeco/public_html/cookie.php on line 8"

i looked up some information about it and everyone says that it is problem that I have may have blank spaces after the closing php tag "?>". I througly checked my editor and could not find any blank spaces. So i decided to test something. I opened a new PHP document and just told it to set a cookie, here is the code:

CODE
<HTML>
<HEAD>
<TITLE>Cookie Tester</TITLE>
</HEAD>
<BODY>
<?
$message = 'hello';
setcookie("IM_A_COOKIE", $message, time() + 3600);
?>
</BODY>
</HTML>


I ran this code and I got the exact error i already stated above. This proves that the problem has to do with the setcookie() function. Is anybody else using setcookie()? If so, how do you get it to work, or are you experiencing the same problems? If there is no solution, I'm going to need to find a different way to make a login system for my site users. In that case, does anyone know how to make a login script with PHP that gets information from a MySQL database and supports members only pages. I would really much rather have a solution for my setcookie() problem, as I may need it for other parts of my website. Thanks in advance, and props to anyone that can solve my problem!

 

 

 


Reply

electron
In headers and COOKIE functions you cannot output anything before the header has been sent. Here your HTML tags are outputted before the header. Hence you are getting this error.
If you want to solve it try the following Code:

CODE
<?
$message = 'hello';
setcookie("IM_A_COOKIE", $message, time() + 3600);
?>
<HTML>
<HEAD>
<TITLE>Cookie Tester</TITLE>
</HEAD>
<BODY>

</BODY>
</HTML>


Note the change of the PHP header or Setcookie() function is being called before the output has been started.
This will not gvew any error.

Hope this helps ad have a good day.

Reply

farsiscript
dear runeco I agree electron when you use Setcookie() function Your all codes must goes at top of page and you can include file form another space , you must compile the file and Setcookie() form this file

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. php setcookie host - 125.21 hr back. (2)
  2. setcookie fatal error - 382.04 hr back. (1)
  3. godaddy php setcookie - 417.48 hr back. (1)
  4. php set cookie bottom of page - 468.69 hr back. (1)
  5. php setcookie & display - 784.97 hr back. (1)
  6. php setcookie "internet explorer" - 817.00 hr back. (1)
  7. php setcookie folder - 852.01 hr back. (1)
  8. php setcookie in virtual include - 1260.76 hr back. (1)
Similar Topics

Keywords : errors php setcookie headers header errors cookie php function setc

  1. Is The Database System Gone Again? [resolved] - Errors on PHPMyAdmin again (12)
  2. Genuine Help With Smtp And Php Mail() Function - I need help using the PHP mail() function and the SMTP server on Trap1 (3)
    Hello, I have looked up the solution to this problem numerous times on this forum but cannot seem to
    get a straight answer. I have also read that something called SMTP Authetication is required. I have
    looked up numerous ways this should be done, but I believe it required special protocols. This is
    the code that I tried to use to send e-mail using the SMTP server here at Trap17. CODE
    $email_to = "whoever@whoever.com"; //SEND MAIL TO HERE $subject = "Testing the SMTP server";
    $message = "This is a test of the SMTP server on Trap17.com Hosting."; mail($email_to, $s...
  3. Two Errors I Get. - On my phpBB2 forums. (1)
    One is one I think everyone is getting. I tried to submit a support request but it says I have to
    define a language. I click the button and I get a WHW error or something. Then it redirects me back
    to the main page. Then at the bottom of the sumbit request page is says that this feature has not
    been set up by a admin yet. I think everyone is getting this one. If so please say you are or if I
    am alone. QUOTE Warning: mysql_connect() : Can't connect to local MySQL server through
    socket '/var/lib/mysql/mysql.sock' (2) in /home/damen/public_html/phpBB/db/m...
  4. Database Errors! - Started after HDD change.. (5)
    Hello, I am having database errors. They started after yesterdays HDD change. Its all fine when i
    refresh site, they not that often but still i get them. It says "could not connect to database". And
    i also received mail from gamma.xisto.com which says: QUOTE There has been a problem with the
    database! This is a notice email to let you know that SMF could not connect to the database, contact
    your host if this continues. so i am contacting my host.....
  5. Parse Errors While Installing Smf Board - (3)
    I seem to be getting a LOT of parse errors with my php scripts. there are two things they have in
    common: 1. they are downloaded and uploaded without modifying them. 2. they all seem to have
    "unexpected $end" e.g QUOTE Parse error: syntax error, unexpected $end in
    /home/random1/public_html/hsp/forum/webinstall.php on line 271 that example for webinstall.php, a
    script used to install SMF. I know that trap17 provides fantastico to install SMF, but I want to
    install SMF1.1RC3 to use with joomla-smf, which fantastico doesn't support. if I upload and
    install SMF t...
  6. Sites Disapeard, Mysql Errors? Also Server Folders Deleted - (18)
    Hello its 15:40 and I login see if everything runs oke, and I see numerus things deleted my mysql is
    working again. Whats going on? My Webpage couple websites got deleted, and server folder files now
    whats going on? /sad.gif" style="vertical-align:middle" emoid=":(" border="0" alt="sad.gif" /> my
    forum also give errors but mysql db stil there /sad.gif" style="vertical-align:middle" emoid=":("
    border="0" alt="sad.gif" />......
  7. [solved]dsn Help (errors) - (3)
    Solved...
  8. Is The Report Function Working? - (3)
    I have asked many mods this, and have been told no... i have asked an admin i never got an answer
    ive asked in almost every PM report ive sent.... lol so here it is again "Is the Report Feature
    Working?!?!?" i was told my one mod yes it was yet a few days ago i was told my 2 no... hmm i cant
    get a straight answer *sigh*...
  9. Why Is Php All Of A Sudden Spitting Errors At Me? - (7)
    hi, I have a problem with my PHP on my site. It just started happening now but i think the PHP
    database some how corrupted its self. How can i reinstall the PHP or upgrade it to the latest PHP
    version, please respond back as this is effecting alot of my PHP scripts. Thanks...
  10. Mail() Function - the mails are sent as SPAM!! (4)
    hello guys! i was thinking about the Mail() function coz lately all the mails i send to my friends
    are send as SPAM and honestly it is a little annoying due to some of them (maybe all of them) use
    hotmail and the mails they got arrive to the SPAM section, is there anything wrong with my script
    should i add more headers? and why scripts like the Zen Cart can send mails directly to the Inbox
    folder?...
  11. Mailing Lists - Does Trap17 support this function & how? (1)
    I keep trying to use the Mailing List fuction in cPanel but evertime I click edit I get a "this page
    cannot be found". Is this because Trap17 doesn't have a mailing list function or am I doing
    something wrong? If I'm doing something wrong can someone please explain how you set up the
    mailing list. If it isn't supported, does anyone know how I can make a mailing list (like with
    php - though I am unfamiliar with PHP as yet, so premade scripts always go down well with me
    /wink.gif' border='0' style='vertical-align:middle' alt='wink.gif' /> ) Thanks heaps!...
  12. Errors Trying To Access Website - along with cpanel access (2)
    My website, http://morosophos.trap17.com/ doesn't work as http://www.morosophos.trap17.com/ .
    Why is this? I can no longer use 99% of the functions on cpanel, and wordpress (which I installed)
    is also no longer working correctly. Does anyone know why this is happening? Topic title and
    description are very important. Editing. ...
  13. Header Web Joomla - (6)
    How i do to change index.php of joomla sript if index.php is unwriteable? I want to put my own
    header. How i do? /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' /> i heard for
    change the header web you have to change index.php(site.-->Template--->template site-->edit
    html=edit index.php and suddenly appears unwriteable)...
  14. Error When Using Imagefilter() - Fatal Error: Call to undefined function (1)
    Hello, i need to use in my site a function called imagefilter but it not work , here is de
    documentation from php.net QUOTE Description bool imagefilter ( resource src_im, int filtertype
    ]] ) imagefilter() applies the filter filtertype to the image, using arg1, arg2 and arg3 where
    necessary. Note: This function is only available if PHP is compiled with the bundled version of
    the GD library. The error when i try to execute it is: QUOTE Fatal error: Call to undefined
    function: imagefilter() kservice USE QUOTE TAGS. YOU WERE PREVIOUSLY WARNED ABOUT ...
  15. Posting Issues... - Many errors when people post (11)
    It seems lately that I have seen a lot of grammatical and spelling errors when people post in the
    forums. I really have enjoyed my stay here at Trap17 but I get really frustrated when I see
    people carelessly type their message and give little consideration to any errors they may have
    typed. Now of course it's not a big deal if there is one or two errors when you post, but when
    someone posts a small message and there is a couple of errors, it really bothers me. I'm not
    going to whine or anything, I just want to pass the message that we should all do our best ...
  16. Cookie Error - help... (7)
    When I reach my forum I see this QUOTE Unable to add cookies, header already sent. File:
    /home/admins/public_html/forum/includes/init.php Line: 919 Can someone tell me how to fix
    this?...
  17. Relevant Links - some errors (6)
    I know that the new relevant links feature gives trap17 money. But it shows the hosting competitors....
  18. Frequent Dns Errors... - Trap17 or .cjb.net? (8)
    I am working on my site and am getting DNS errors every 2 minutes or so, and was wondering is the
    DNS errror Trap17's name servers or my .cjb.net, my free DNS domain provider? Because I was
    planning to buy a .com domain and switch to that, but if it's Trap17 I don't want to pay
    money if it might not always be up, but if it is .cjb.net then I will switch sooner....
  19. I Keep Getting Errors When.. - ..trying to view directories on my site (5)
    My site is www.subzero.trap17.com However, I set the servers in GoDaddy for my domain to
    ns1.trap17.com and ns2.trap17.com Every time I try to go to a directory on the site (for example,
    /boards) I always get a 500 error. I keep getting it and even got it when trying to log into my
    cPanel. It's extremely annoying! /mad.gif' border='0' style='vertical-align:middle'
    alt='mad.gif' /> Can somebody please tell me why I get these errors?...
  20. Errors And Things To Do With Cpanel - cpanel errors after trying a fix..... (7)
    I installed cube cart into one of my subdomains. It kept giving me errors when I opened the url.
    So I wnet ot a help forum for the thing and followed their advice and added tmp folders and gave
    them chmod 777 well I did it in the admin folder of the subdomain as well as the subdomain folder
    (whitebird.unicornrose.com) and in the public_html folder/www folder. Well I removed the cubecart
    because this did not help me at all. I removed the tmp folder i made in the www folder and now I am
    getting this error whe I try to install anything in cpanel and my cpanel is not wor...
  21. Regarding Bandwidth Usage - errors ? (2)
    Did any1 notice that the bandwidth usage on the frontpage of cpanel is actually DOUBLE the
    bandwidth that u had actually used? U can go to section under bandwidth and see ur bandwidth usage.
    For mine it stated that i've used 199.56 Meg but looking at the details it only total up to
    99.78 Meg. But looking at the AWStats (updated) .. it stated that i;ve only use 77 Meg (including
    traffic viewed + not viewed ) I need some advise about this .. because i think if i've used 200
    mb for only day 4 of the month ... then im going to run out of bandwidth very soon...
  22. Missing File In Cpanel ? - Errors in quota (1)
    When i enter in quota of accout default at : http:// user name
    .trap17.com:2082/frontend/rvorange/ftp/editquota.html?acct=ftp I seen : QUOTE Not Found   
    The server was not able to find the document (./frontend/rvorange/ftp/editquota.html) you requested
       Please check the url and try again.  You might also want to report    this error to your webhost.
    Is this a errors or missing file ? And Raw Log Manager don't working too . I checked
    cell : "Archive Logs in your home directory at the end of each stats run " and put save but i
    never seen logs that...
  23. Install Moodle 1.3.4 In Cpanel Have Errors ! - I trying install few feature in my site (0)
    My hosting till enought space for anything intalls , i have about 26 mb for this intalls ! I seen
    errors after intall Moodle 1.3.4 Warning: main(mod/resource/lib.php): failed to open stream: No
    such file or directory in /home/nuhoaxul/public_html/moodle/index.php on line 6 Fatal error:
    main(): Failed opening required 'mod/resource/lib.php'
    (include_path='.:/usr/lib/php:/usr/local/lib/php') in
    /home/nuhoaxul/public_html/moodle/index.php on line 6 I sorry , but i think moodle is pretty big
    with host 50 mbs ! I can't delete this post ! Any mods or a...
  24. Restore Database Have Bug ? - I restore and have errors ! (2)
    I tried restore a database as type : username_forumname.sql ! After restore , check in cpanel ,
    feature mysql datase , I seen a new database is : username_usernameforumnamesql ! Have anything
    wrong ?...
  25. phpbb header - i think i did somthing wrong (1)
    i didn't like the way the header was set up so i went to overall_header and changed with html
    editor. but then i tried to see if it worked but now i get a green flash and them nothing happens.
    no forum at all. please tell me what i can do to fix this problem. thanks in advance....
  26. Control Panel Errors.... - Help? (2)
    Hey, i used fantastico auto installer to install some forum but everytime i do it (no matter what
    forum i install) it only comes up with an error page. I dont know why so could you please help?...



Looking for errors, php, setcookie, headers, header, errors, set, cookie, php, function, setc






*SIMILAR VIDEOS*
Searching Video's for errors, php, setcookie, headers, header, errors, set, cookie, php, function, setc

*MORE FROM TRAP17.COM*
advertisement



Errors With Php Setcookie() And Headers! Please Help! - Having header errors when I try to set a cookie with PHP function setc



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE