MrFish Posted June 23, 2009 Share Posted June 23, 2009 I attempted to put an entire login script before the <html>. Since you have to set cookies before the html begins I thought, might as well just do the whole thing before the html tags! (like searching the mysql database and stuff). Will this work? What happens when you put things before the html tags? I know I put javascript before them once and it worked fine. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 23, 2009 Share Posted June 23, 2009 It's typically a better practice to do all PHP processing before you output any HTML. That way you can tailor the HTML (or redirect, send headers, etc) depending on what happened during processing. Link to comment Share on other sites More sharing options...
Synook Posted June 24, 2009 Share Posted June 24, 2009 By the way, you can't access cookies anywhere on the same script they are created in. The page has to be reloaded at least once. Link to comment Share on other sites More sharing options...
ckrudelux Posted June 24, 2009 Share Posted June 24, 2009 Sure works but there will be alot things to keep track on. I prefer to include php files with functions or statment where they are needed and I can add them as many times I want so I don't need too write my code twice.Any how if you are going to have all php codes over the html I strongly recommend too make a include so you get the html separated from the php, just like you separate the css. Some php codes still needs to be on the main page like "session_start();" Link to comment Share on other sites More sharing options...
Synook Posted June 24, 2009 Share Posted June 24, 2009 You can actually include the file with the session_start() call - I do it all the time. In PHP, including a page is equivalent to copying all its code and pasting it where the include statement is. Link to comment Share on other sites More sharing options...
ckrudelux Posted June 24, 2009 Share Posted June 24, 2009 You can actually include the file with the session_start() call - I do it all the time. In PHP, including a page is equivalent to copying all its code and pasting it where the include statement is.I didn't know I thought if you wanted a session_start it needed to be the first line Good to know I can add it to my includes Link to comment Share on other sites More sharing options...
justsomeguy Posted June 24, 2009 Share Posted June 24, 2009 I didn't know I thought if you wanted a session_start it needed to be the first lineIt sends a header, so it only needs to come before any output. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.