Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJames Barrett
13,253 PointsWhat is more efficient? PHP INCLUDE Question
Hi,
Alena talks about using the $_GET method to change the title of the page. In my own project, I have used an INCLUDE for the navigation and just echo'd out the $pageTitle each time with a different string.
So my question is, what way is more efficient? Are there bad practices to this?
Thanks, James.
2 Answers
Edward C. Young
10,323 PointsMost Web Programming Languages (PHP, ASP.NET, ASP, JSP) are server side languages. That means that the Web Server hosting your pages does all the processing before the resulting page is passed to your browser. Your method, while it works detracts from that principle. While the include is still pre-processed, the _GET global allows you to pass parameters anywhere in your entire website, with the added benefit of only typing
$pageTitle
in at least two places (Page Title, Page h1). Your code has at least 5 places (Page Title, Page h1, and your 3 includes), plus you have no way to test if
cat
is empty.
Jeremy Canela
Full Stack JavaScript Techdegree Graduate 30,766 PointsI think just echo
ing the $pageTitle
is fine.