Jump to content

Ive had it with trying to get this cookie to set! Im lost


jdock1

Recommended Posts

Ok I have NEVER had problem like this before.

 

First of all, I am not that great with cookies or headers. But I know how to set cookies & sessions & how to use them.

 

Any way, this is the most important feature & page on my app. Its for the register page, it sets a cookie that is needed to prevent fraud.

 

I did the development of this script on my local server & this is my first time testing it on a real server.

 

My issue is, I keep getting the damn headers already sent error;

 

Warning: Cannot modify header information - headers already sent by (output started at /../../..//mysite.com/admin/includes/linkmysql.php:2) in /../../../mysite.com/reg.php on line 36

 

I literally tried everything. I completely rewrote the page to work around this. I cannot stress enough how important this cookie is.

 

I dont udnerstand. The php is b4 all the html, etc etc. There should be no other "headers being sent".

 

Heres the code;

 

<?php


					require_once 'is_email.php';

$result = is_email(@$email, true, true);
				if (isset($_POST['register_clicked']) && $_POST['register_clicked']==1)
				{
					$uname = $_POST['uname'];
					$upasswd = $_POST['passwd'];
					$email = $_POST['email'];




					if (!(strlen($uname) > 0 && strlen($uname) < 31))
						echo '<td colspan="3" align="center" class="FormError"> USERNAME length must be between 1 and 30! </td>';
					else if (!(strlen($upasswd) > 0 && strlen($upasswd) < 41))
						echo '<td colspan="3" align="center" class="FormError"> PASSWORD length must be between 1 and 30! </td>';
					else if ($upasswd != $_POST['passwdconf'])
						echo '<td colspan="3" align="center" class="FormError"> PASSWORD doesn\'t match! </td>';


else if (!is_email($email)) echo "<td colspan='3' align='center' class='FormError'>{$email} is not a valid email address! (result code $result)</td>";
else
					{
						include_once('admin/includes/linkmysql.php');
						include('admin/includes/func.php');
						if (!newuser($uname, $upasswd, $email))
							echo "<td colspan='3' align='center' class='FormError'>Username already in use!</td>";

						else
						{
							echo '<strong><font color="black">Registration Completed!</font></strong>';
							$value = "no-delete";
							setcookie("Muffins", $value, mktime (0, 0, 0, 12, 31, 2015));

							#if (isset($_POST['autologin']))
							#{

								add_login($uname);
								$_SESSION['login_name'] = $uname; 
								?>
								<!--<script language="javascript" type="text/javascript">
								window.location.href = "index.php?a=home";
								</script> -->
								<?php
							}
						}
					}

				?>
                    <?php
				if (isset($_COOKIE['Muffins']))
{
Header ('Location: http://mysite.com/index.php?a=noreg');
}

?>

 

line 36 is obviously the line with the setcookie. I have no idea why it is referencing the include file, it has two lines of code that defines the mysql connections.

 

This code is at the top of the page, before all the HTML etc. NO reason why it should be giving me header errors rigght!?? Im having the same issue with another page. I ban users thru setting a value in a mysql table, when the "system" notices the ban value is set, it redirects them to an account banned page using a header. BUT ITS THE SAME ******** THING!!!!!

 

NEVER in my YEARS of coding have I ran into such AN ANNOYING & SENSELESS ISSUE!

 

Sorry I am just SO frustrated, due to this I have not worked on this in days I pretty much gave up. I cannot launch this site that I have been working on for years without this working.

 

THANK YOU FOR ALL YOUR HELP!!! Much appreciated.

 

Link to comment
Share on other sites

You can use this code to solve the header error.

Place it beginning of the 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();

Link to comment
Share on other sites

You can use this code to solve the header error.

Place it beginning of the 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, using this code will set the cookie? & If cookie is set, will do header redirect? Idk why Im asking. Im gonna try it, thanks! But in case it doesnt Id like to know. Thanks

Link to comment
Share on other sites

The HTTP protocol requires that HTTP headers be sent to the client/browser before any CHARACTER gets sent.

 

output started at .../linkmysql.php:2

 

Something in your linkmysql.php file on or up to and including line 2 is sending one or more characters to the browser.

 

You are also going to find that near the end of the code you posted, that all the white-space (tabs, new-lines,...) after the closing ?> tag up to the <?php tag on the next line is output that will prevent the final header() redirect from working.

 

The reason your code worked on your development system is because php thought it would be a good idea to 'help' beginning coders write code that 'worked' that they could turn in for assignments over writing code that is correct and will work in real live on all server configurations. Your development system has output_buffering turned on in the master php.ini. That allows code to improperly send output to the browser (it gets buffered instead) before sending a http header.

 

If output_buffering is ON, on your development system, turn it off so that the code you develop will work on the widest range of server configurations and you won't waste any more time developing code that might be suitable to turn in as an assignment but won't work when you put it onto a server that is not under your complete control.

Link to comment
Share on other sites

You can use this code to solve the header error.

Place it beginning of the 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, using this code will set the cookie? & If cookie is set, will do header redirect? Idk why Im asking. Im gonna try it, thanks! But in case it doesnt Id like to know. Thanks

 

You can use this code to avoid the header error .

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.