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!

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 trial

General Discussion

Beer Warning

Im making a site for a beer bar and they need a page/pop up before you can navigate the page saying "are you 18 or older?". But I was wondering whats the best way to do that. Would having the index.html page just be the warning page then if they hit yes then they can go to the home page and if they hit no then they get sent some were else. Or would a pop up be better that take up the home screen thats the same with the index page, if you hit yes then you go navigate the site. Or is there another way thats better.

7 Answers

If it was me.. I would probably keep index as per normal i.e. your home page is your index page. Remember the user might enter the site on any page so only confirming the age on the index page might be a little redundant.

I would use a cookie or session via php to check if the user has confirmed their age. You'll need to run the check at the beginning of every page. If they have the cookie / it's confirmed true, you can proceed with the page. If they don't have the cookie you can redirect to a confirmation page

Thinking about it, I would definitely use a cookie, not a session. You can find more info on setting cookies here https://php.net/manual/en/function.setcookie.php

Can I use the cookie php on a html and css website?

It would have to be in php code in a .php file - so it would mean converting your .html files to .php. Are you restricted to .html? If you're not, I would really recommend taking a look at "build a simple php application" and "enhancing a php application" if you haven't already (https://teamtreehouse.com/tracks/php-development) :-) If you're using html, you must be repeating yourself a lot with stuff like the navigation and footer? A nice simple thing to do is create a header.php file and footer.php file and include (http://www.php.net/manual/en/function.include.php) These files on every page. That way, your css files, javascript files, navigation, header etc only need to be edited in one file, once!

does Teamtreehouses workspace use php?

You can create a php file - when you go to menu and select 'new file', you can name it xxxxxx.php to create a php file :-)

In php does it style its self or do i need another language (like html and css) or can i do all the styling in php?

p.s. thank you so much this guys my first client so thanks a lot =)

Sorry man, I've just looked at workspaces and I'm not sure you can create php and run php files, only html.

I would really recommend taking the build a simple php application because it will tell you how to set your computer up for working with php!

Essentially, php is a server-side language. You write php code and the code is interpreted by the server and sent to the browser when the page is requested. You will never see php code in the browser, you'll only see the output from the php code.



     echo '<h1 class="main-heading">Hello</h1>'; 


Will output in the page source as

<h1 class="main-heading">Hello</h1>

I'm pretty confident you'll be able to complete your website after going through this track http://teamtreehouse.com/tracks/php-development

If you're looking to skip to the good bit, go straight for http://teamtreehouse.com/library/build-a-simple-php-application

Good luck!

Hey man, I've just had a little play with sessions - the results are here:


Is this what you're after?

yes! how did you get that. Thats exactly what im looking for.

So this demo creates a variable in $_SESSION which is set to bool true when the user says they're over 18. When I have a moment and after I've tidied them slightly, I'll upload the files to github so you can take a look :-)

Is this for php?