robert_gsfame Posted July 24, 2009 Share Posted July 24, 2009 Friends, i got some simple questions here Put require_once['bla.php'] between <head></head> Put require_once['bla.php'] between <body></body> Which one is actually correct, or both are correct thanks! Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/ Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 where the require is (abstractly speaking) doesn't matter. what matters is that the code inside the include is in the correct spot. so, if what is inside blah.php should be between the head tags, then put it there Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/#findComment-881938 Share on other sites More sharing options...
robert_gsfame Posted July 24, 2009 Author Share Posted July 24, 2009 require_once['bla.php'] ----> it's a connection to mysql database bla.php $host="localhost"; $username="xxxx"; $password="xxxx"; $db_name="xxxx"; mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB"); Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/#findComment-881944 Share on other sites More sharing options...
PFMaBiSmAd Posted July 24, 2009 Share Posted July 24, 2009 <head></head> and <body></body> tags only have meaning in a browser where they are rendered, same for all the other HTML tags and CSS and Javascript. They don't actually have any meaning in a php file. Php outputs content (HTML/SCC/Javascript) to a browser. You put php code in a .php file wherever it is needed to perform its' intended purpose. If you need to require_once a setting file or a file that contains function/class definition(s), you do that near the start of the code so that the settings/functions/classes are available in the remainder for the code. If you need to require_once a file that contains content that goes in the head of a web page, you do that inside of the <head></head> tags... Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/#findComment-881945 Share on other sites More sharing options...
robert_gsfame Posted July 24, 2009 Author Share Posted July 24, 2009 thank you everyone Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/#findComment-881947 Share on other sites More sharing options...
robert_gsfame Posted July 24, 2009 Author Share Posted July 24, 2009 Is it correct if i put this way <?php session_start();?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <meta name="description"> <meta name = "keywords"> <style type = "text/css"> </style> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> <?php require_once['config.php'];?> </head> i created this using dreamweaver, and when i put this way, highlighted <?> mark appeared on my properties is there something wrong with the code, can explain it to me about the meaning of that error? Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/#findComment-881976 Share on other sites More sharing options...
Maq Posted July 24, 2009 Share Posted July 24, 2009 When someone doesn't answer your question within 10 minutes please don't start a new thread about it. http://www.phpfreaks.com/forums/index.php/topic,261884.msg1233169.html#msg1233169 Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/#findComment-881988 Share on other sites More sharing options...
rhodesa Posted July 24, 2009 Share Posted July 24, 2009 i don't use dreamweaver...so i can't answer that question... is there anything "wrong" with the code...absolutely not, that code will run fine. is the code "correct"...well, that is tougher to say as you are the only one that knows what the final output should be. if the outcome is what you expect, then i would say it's fine does it follow "normal standards"...i would say no, and the norm is to put the inclusion of a config file at the top of your script: <?php session_start(); require_once('config.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <meta name="description"> <meta name = "keywords"> <style type = "text/css"> </style> <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script> </head> p.s. - i also noticed that you were using [] instead of () in your require_once Quote Link to comment https://forums.phpfreaks.com/topic/167269-solved-which-one-is-correct/#findComment-881991 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.