hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Php simple scripting error...
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Php simple scripting error...

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 12-27-2004, 04:11 PM
VolkNet VolkNet is offline
Web Hosting Master
 
Join Date: Jun 2004
Location: Bay Area -USA
Posts: 1,738

Php simple scripting error...


I keep getting an error and im not sure how to fix this problem.

PHP Code:
<?php if(!isset($_COOKIE['cap'])) { ?>
<script>do some javascript</script>
<?php setcookie('cap'"1"time() + (86400 12));
?>
Seems good but i get this.

Warning: Cannot modify header information - headers already sent by (output started at index.php:6) in index.php on line 11

__________________
<<< Please see Forum Guidelines for signature setup. >>>

Reply With Quote


Sponsored Links
  #2  
Old 12-27-2004, 04:23 PM
sonicgroup sonicgroup is offline
WHT Addict
 
Join Date: Jul 2004
Location: Indiana, USA
Posts: 153
Cookies are set in the header, so if your script has outputted anything to the user before your setcookie() line (including <html> tags or whitespace), you need to move it after, or move the setcookie() earlier in your script.

__________________
Dave Scott
President/CEO
The Sonic Group, LLC
Core Team Member - International Web Developers Network

Reply With Quote
  #3  
Old 12-27-2004, 04:24 PM
samscripts samscripts is offline
New Member
 
Join Date: Oct 2002
Location: London, UK
Posts: 4
You have to call the setcookie() function before anything has been output to the webbrowser - in your code, the following will have already been outputted to the browser before your call to setcookie():

<script>do some javascript</script>

Additionally, if you have any html (or just blank lines) prior to the setcookie() function, that would also cause that error.

One way around this if you don't want to rearrange your code is to call the function: ob_start() at the beginning of your script to turn on output buffering (nothing is sent to the browser until the script ends, or you call ob_end_flush() )

See http://www.php.net/ob_start and http://www.php.net/setcookie for more info.

Hope that helps

Reply With Quote
Sponsored Links
  #4  
Old 12-27-2004, 05:59 PM
VolkNet VolkNet is offline
Web Hosting Master
 
Join Date: Jun 2004
Location: Bay Area -USA
Posts: 1,738
I think ill just set my cookie via javascript because the scripting between the php codes has to be in the head of the html document. I thought i'd be able to have the code not even show if the cookie is there but oh well. Thx for everything guys

__________________
<<< Please see Forum Guidelines for signature setup. >>>

Reply With Quote
  #5  
Old 12-28-2004, 01:17 PM
nnormal nnormal is offline
Web Hosting Guru
 
Join Date: Nov 2003
Posts: 297
ob_start();

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Expired SSL Certificate Brings Down Windows Azure Cloud Web Hosting News 2013-02-25 10:38:00
FireHost Report Shows Cross-Site Scripting Attacks Up 160 Percent from Q3 Web Hosting News 2013-01-30 14:43:57
Zetta Launches Appliance-Free Hybrid Smart Cloud Backup Solution Web Hosting News 2012-10-23 16:29:27
European Security Firm SecPoint Releases Cloud Penetrator Scanner Web Hosting News 2011-09-22 18:38:31
Web Host Hostek.com Launches Range of Linux ColdFusion Hosting Plans Web Hosting News 2011-09-12 19:12:41


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?