Jump to content

header ()


westman

Recommended Posts

hi all,i have a problem with header () this is what i have... header("location: ../user/index.php?id=$id"); and this is my error.... Warning: Cannot modify header information - headers already sent by (output started at /home/content/31/9408631/html/....../index.php:2) in /home/content/31/9408631/html/....../....../.......php on line304 is there any thing elts i can use instead of header () to change the page? if not how can i solve my error?

Link to comment
Share on other sites

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

Sure it can!

include "index.php";

BTW, please post the complete code for the parts that are giving you trouble.

Edited by niche
Link to comment
Share on other sites

From my understanding, including just includes a page(file) into the current page. If you're processing user info for example, checking all is valid and correct, then executing an include file to send the user to the members page, it will from my understanding just include that particular file on the current page(file) and not actually take them to a whole other page.

Link to comment
Share on other sites

The OP could pass that data through a cookie or the session array. More importantly, I don't think we have enough info to solve the original question. I'll bet the needed code will appear shortly.

Link to comment
Share on other sites

We need to see your code if we're to help you with your original question. Else, you can probably move your data via session or cookie. Do you need help with that?

Link to comment
Share on other sites

i have made login pages before and they worked fine with header () moving users to a new page.however the new site i am making is 1 site many pages in 1 .php file so to move the users to different pages i need to change the URL.is there a way i can change the URL with my error?

Link to comment
Share on other sites

Is there a reason you can't post your code? That's how we make sure you get the answer you need and avoid 64 questions.

Link to comment
Share on other sites

Are you including a page on the main page and on that included page you're echoing something? If so this can cause the error as well. niche is suggesting you post the section of code that you think is giving you the problem; not just the error message

Link to comment
Share on other sites

Please confirm that the code in post #17 is the code that produces the problem in your original post. If so you'll have to post more code. You're not posting enough to diagnose the problem (ie what's the code in code.php and code2.php?

Edited by niche
Link to comment
Share on other sites

in index.php 1 line of code...<?php require("code.php"); ?>in code.php 1 line of code...<?php require("code2.php"); ?> and in code2.php is my 1 php file site. i used this method to help stop the site get hacked or downloaded, will this method help? and is this my header problem?

Link to comment
Share on other sites

If you are requiring/including on to your main page and within that included file you're echoing something and then use header() in the main page somewhere down the line, yes you're likely to get that header problem.

Link to comment
Share on other sites

Do you have any HTML output anywhere that is not coming from PHP? For example:

<!doctype html><html><head></head><body>  <?php        if(!empty($name) && !empty($email))	   {			header(); //this can cause an error because above we have HTML output	   }	   else	   {		   echo '<p class="error">Please insert all required fields. Click back and try again.</p>';	   }  ?></body> </html>

What is the error displaying now after making changes?

Edited by Don E
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...