westman Posted September 23, 2012 Share Posted September 23, 2012 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 More sharing options...
niche Posted September 23, 2012 Share Posted September 23, 2012 You can use require/include. Link to comment Share on other sites More sharing options...
westman Posted September 23, 2012 Author Share Posted September 23, 2012 require/include does not move a user to a different page. Link to comment Share on other sites More sharing options...
niche Posted September 24, 2012 Share Posted September 24, 2012 (edited) Sure it can! include "index.php"; BTW, please post the complete code for the parts that are giving you trouble. Edited September 24, 2012 by niche Link to comment Share on other sites More sharing options...
Don E Posted September 24, 2012 Share Posted September 24, 2012 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 More sharing options...
niche Posted September 24, 2012 Share Posted September 24, 2012 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 More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 this code is for my login page.so after i set all sessions i need to move the user to the signed in page. any help? Link to comment Share on other sites More sharing options...
niche Posted September 24, 2012 Share Posted September 24, 2012 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 More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 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 More sharing options...
Don E Posted September 24, 2012 Share Posted September 24, 2012 If you have session_start(); and somewhere down the line a header() on the same page, that is probably the issue. Link to comment Share on other sites More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 i have not coded session_start(); yet am coding bit by bit for testing Link to comment Share on other sites More sharing options...
Don E Posted September 24, 2012 Share Posted September 24, 2012 I see. Also, echoing something before the header() call may result in the headers already sent error as well. Link to comment Share on other sites More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 its not echo, i only have 1 echo and that's at the bottom of the .php file Link to comment Share on other sites More sharing options...
niche Posted September 24, 2012 Share Posted September 24, 2012 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 More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 i also tried header($_SERVER['PHP_SELF']); but with no luck and i did post my code Link to comment Share on other sites More sharing options...
Don E Posted September 24, 2012 Share Posted September 24, 2012 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 More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 yes i do, full code on index.php...<?php require("code.php"); ?> full code on code.php...<?php require("code2.php"); ?> and on page code2.php is the full site of coding and where i am having header () problems Link to comment Share on other sites More sharing options...
niche Posted September 24, 2012 Share Posted September 24, 2012 (edited) 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 September 24, 2012 by niche Link to comment Share on other sites More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 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 More sharing options...
Don E Posted September 24, 2012 Share Posted September 24, 2012 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 More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 i tried all my code on index.php whith no requiring/including and it still did not work Link to comment Share on other sites More sharing options...
Don E Posted September 24, 2012 Share Posted September 24, 2012 (edited) 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 September 24, 2012 by Don E Link to comment Share on other sites More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 i tried putting my php above the html but it still is not working Link to comment Share on other sites More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 i also tried removing all code on index.php and just adding header("location: ../user/index.php?id=$id"); and my header did not work.my index.php is on a sub domain (life.example.com) is that my problem? Link to comment Share on other sites More sharing options...
westman Posted September 24, 2012 Author Share Posted September 24, 2012 i think my problem is that i am using a sub domain. is there a different way i can change the url in php, html or javascript with out using header () snd that will work on a sub domain? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now