Helllo I am getting Warning: Cannot modify header information - headers already sent by error on header("location: sucessful_registration.php"); line please help me how can i fix it function NewUser() { $full_name = $_POST['full_name']; $user_name = $_POST['user_name']; $password = $_POST['password']; $email_address = $_POST['email_address']; $phone = $_POST['phone']; $address = $_POST['address']; $city = $_POST['city']; $zip = $_POST['zip']; $state = $_POST['state']; $country = $_POST['default_country']; $member_id = $_POST['member_id']; $card_csv = $_POST['card_csv']; $activation_new = "0"; $query = "INSERT INTO user_registration (full_name,username,password,email,phone,address,city,zip,state_province,country,member_id,member_csv,activation) VALUES ('$full_name','$user_name','$password','$email_address','$phone','$address','$city','$zip','$state','$country','$member_id','$card_csv','$activation_new')"; $data = mysql_query ($query)or die(mysql_error()); if($data) { header("location: sucessful_registration.php"); } } newuser(); } PHP:
You can only call header BEFORE anything is output -- either outside php tags or using echo/print. The bug isn't in that function so much as it's likely before wherever it is you are calling that function. Find out where you are calling it, and see what's outputting markup (or even blank lines) before it. Part of why I still say there should only be one <?php per php file and it should be the FIRST thing in it.... actually, not entirely accurate; I say that the PHP tags need to be removed from PHP entirely -- no more <?php ?> I say! Though honestly, doing a stupid handshake redirect instead of just *SHOCK* showing the successfuly result page means your methodology is flawed. I'll NEVER understand why people do that crap in their systems as it's just a waste of the user and server's time. Why are you redirecting instead of just doing an include?!? Of course, the endless pointless variables for nothing, blind string addition with no sanitation, and soon to be deprecated mysql_ functions we've been told for eight to nine years to stop using probably aren't helping matters in a "security? What's that?" kind of way.
Please use javascript for redirecting to successful page.. the best and easy way. OR There are some problems with your header() calls, one of which might be causing problems You should put an exit() after each of the header("Location: calls otherwise code execution will continue You should have a space after the : so it reads "Location: url" It's not valid to use a relative URL in a Location header, you should form an absolute URL like http://www.mysite.com/some/path.php
@nico_swd, really kind of wish I could mash the like button a few thousand more times... Because of course, dumbass scripttardery is going to be such an improvement over a header redirect that ALSO serves no legitimate purpose.
What if the PHP script posts on a forum or makes a purchase? Do you really want the user refreshing it?
Of course not, that's why you use a unique (and expiring) token for each transaction where repetition is bad... something you should probably have there ANYWAYS to make session hijacks harder.
The fact that he used the words "please" and "best way" felt like a kick in the nut sack. It still hurts, to be honest.
For me it was more like Larry the Cable guy's joke about something so hideous it makes your wiener shrink back so far it sticks out the other end. I tell you what that's funny right, there... don't care who you are that's funny.
Hello, I was looking at the original code at I think in there the 3rd curly bracket was not opened before it was closed. I am new here btw but was not sure where to introduce myself.
While the third end-bracket doesn't have any starting bracket to match, it has nothing to do with the OP's original question.
I just assumed that we're not seeing the whole picture as it's a snippet, instead of a complete file... though some sane and rational formatting would have gone a long ways to help with the code clarity. (but then I'm so old school I call K&R formatting "new kid BS")