Jump to content

setcookie issue, working on local server, not working on real server


jdock1

Recommended Posts

I just did a huge import from an app I have been working on. No issues except for this.

 

I uploaded & imported all files & databases from my wampserver (localhost, local server) to my main online server.

 

Before I continue with the problem, I have to give you info on how the files work.

 

I am using a "controller" to view the files. Meaning, from index.php, I call all the files. For example, instead of mysite.com/register.php, its mysite.com/index.php?page=register.

 

The index defines the doctype & html tags etc.

 

The other files that are called through index.php are just pure php code, it does not contain the head & body tags etc.

 

So, the issue is , when the surfer submits a form, i need to set a cookie. this cookie is VERY important.

I cannot get it to work. I am getting the header warnings after submit

 

Of course, this is to be expected. But I tried it on my local server, & it worked. I am not very familiar with cookies, this is a side of PHP i never really even touched. I know almost everything but that.  So the php code is before the html code on the page, so I figured it was worth a shot.

Im guessing the problem here is, since the code being outputted as index.php code + the form page code. So the cookie is being set after the html tags.

 

How can I fix this? I need it to work thru the controller. I cannot just make it a single file, all files on the site needs to be thru this controller, otherwise it will mess everything up.

 

Ino I could just add the code from index.php plus the form page code & just run the php code before all of the html tags, but like I said it has to be called thru index.php.

 

I appreciate your replies, & I hope you guys dont think im an idiot & can understand my question, im terrible with words!

If you're getting a 'headers already sent' warning, then you're obviously attempting to set the cookie after some sort of output has already been sent to the browser.

 

http://www.phpfreaks.com/forums/index.php?topic=37442.0

To avoid the header error, you can use this code.

<? php
/*
 "Warning: Cannot modify header information - headers already sent by "
  	To avoid the header error , give value zero to
	$mosConfig_locale_debug = 0;
	$mosConfig_locale_use_gettext = 0;
*/
$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0;
ob_start();

To avoid the header error, you can use this code.

<? php
/*
 "Warning: Cannot modify header information - headers already sent by "
  	To avoid the header error , give value zero to
	$mosConfig_locale_debug = 0;
	$mosConfig_locale_use_gettext = 0;
*/
$mosConfig_locale_debug = 0;
$mosConfig_locale_use_gettext = 0;
ob_start();

 

So will that actually set the cookie though?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.