PDA

View Full Version : Invisible/visible include....



Shile
09 May 2008, 01:11 PM
I am making a php project..its made with container with multiple include/require functions (including php pages).

I need that if visitor has a cookie (from my site) he sees different include, or include is visible only if visitor has cookie in his comp...

Cookie will be made with loging in...

If someone has any idea to make this more elegant please help.

dk01
09 May 2008, 01:46 PM
Something like this would work:



<?php
if (isset($_COOKIE["loggedin"]))
include('validuser.php');
echo "Welcome " . $_COOKIE["user"] . "!<br />";
else
include('guest.php');
echo "Welcome guest!<br />";
?>


You'd need to set the cookie named "loggedin" to something when the user logs in by using the setcookie() function. This is a pretty basic system.

Remember that using cookies is not a secure way to do this, because anyone could set a cookie. If really need the extra security you'd have to issue each visitor a unique key which is stored in a cookie, and then check that key against the user's logged in data (which would be handled by sessions).