cannot see where to locate the php Header function
Posted: Tue Feb 25, 2014 9:12 am
hi
This is structure question about where I place my chunks of PHP code so my call to the Header() fuction works.
I have an HTML page derived from an HTML Dreamweaver template (so it has a chunk of HTML at the top i.e. head, body tags, and a nav menu). The page has a PHP script to get the users userid and password from a form. The script goes and checks a sql dbase to ensure the user has entered the correct info. If he has, I want to use the Header(Location: "Page2...") to take him to my next page, e.g. Page2 I get the known error "cannot redirect, headers already sent".
Now, I know I get this error because I am violating the rule which says I must not send any kind of output prior to the Header call, but my problem is what structure should I use to comply with that rule? On my Page1 I must have the HTML ahead of the Header call else how would I be able to display the form?
I could maybe set up a page called Page2 with just the PHP code only to check the form variables and call the Header function but how do I call that page into the browser from Page1 so it can execute? As Page1 will have the HTML for the form and call to go to Page2 with Header( function will fail. I believe I cannot use include to jump to Page2 because that also violates the 'no output' rule... It seems an unsolvable conundrum to me, like a chicken & egg situation! I'm sure one of you gurus have the solution for me! many thanks in anticipation, Dave Higgs
This is structure question about where I place my chunks of PHP code so my call to the Header() fuction works.
I have an HTML page derived from an HTML Dreamweaver template (so it has a chunk of HTML at the top i.e. head, body tags, and a nav menu). The page has a PHP script to get the users userid and password from a form. The script goes and checks a sql dbase to ensure the user has entered the correct info. If he has, I want to use the Header(Location: "Page2...") to take him to my next page, e.g. Page2 I get the known error "cannot redirect, headers already sent".
Now, I know I get this error because I am violating the rule which says I must not send any kind of output prior to the Header call, but my problem is what structure should I use to comply with that rule? On my Page1 I must have the HTML ahead of the Header call else how would I be able to display the form?
I could maybe set up a page called Page2 with just the PHP code only to check the form variables and call the Header function but how do I call that page into the browser from Page1 so it can execute? As Page1 will have the HTML for the form and call to go to Page2 with Header( function will fail. I believe I cannot use include to jump to Page2 because that also violates the 'no output' rule... It seems an unsolvable conundrum to me, like a chicken & egg situation! I'm sure one of you gurus have the solution for me! many thanks in anticipation, Dave Higgs