General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 22nd, 2003, 08:54 PM
Decoy Decoy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 28 Decoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Work around 'Header already sent' problem?

On one site I am working on I set a cookie immediately upon visiting the site.

I am writing a fairly simple function that allows users to recommend the site to their friends. To help prevent spamming I wanted to set an additional cookie that would register the referral and not allow the same person to refer again for 24 hours.

PHP Code:
if($sent '1')
  { 
    
genMsg('refer_limit'); 
  }
  else
  {
    
$num $sent 1
    
setcookie("sent""$num"time()+86400);

    
mail sent...
  } 

Of course, I get the 'Headers already sent' error. Does anyone know a way around this, or if not, have a suggestion that will allow me to control the number of referrals a visitor can send?

Thanks

Reply With Quote
  #2  
Old October 22nd, 2003, 09:27 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Only allow up to maybe 50 referrals per IP address per day. Makes things a lot simpler.

On the referral submit form, only give the user two or three boxes to fill in so they can only submit to that may people at once.

--
Wil Moore III
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old October 22nd, 2003, 10:02 PM
Decoy Decoy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 28 Decoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi laidbak,

Good idea...I use the following function.

PHP Code:
function GetIP()
{
  if(
getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
    
$ip getenv("HTTP_CLIENT_IP");
  else if (
getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
    
$ip getenv("HTTP_X_FORWARDED_FOR");
  else if (
getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
    
$ip getenv("REMOTE_ADDR");
  else if (isset(
$_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
    
$ip $_SERVER['REMOTE_ADDR'];
  else
    
$ip "unknown";
  return(
$ip);



thanks,
Rob

Reply With Quote
  #4  
Old October 23rd, 2003, 12:19 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Alright... good job. Glad I could help.

Reply With Quote
  #5  
Old October 23rd, 2003, 11:49 AM
mjlivelyjr mjlivelyjr is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Idaho, US
Posts: 9 mjlivelyjr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If you use php's output buffering functions it should do the trick. At the begining of the code put this line:

Code:
//begin buffering
ob_start();


and at the end of the code put this function

Code:
//end buffering
ob_end_flush();


basically what this does is prevents any text from being sent to the browser until your entire page has processed. This also will prevent the headers from being sent until after the script has run.

By default PHP will automatically send headers as soon as your script attempts to send its first character to the browser. Hence the "headers already sent" error. Use the above code and your problem should be fixed.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Work around 'Header already sent' problem?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT