adaywalkr Posted December 31, 2006 Share Posted December 31, 2006 Hello people!I installed and modified a login script on my website.. it works fine, but when I'm logged in, it redirects me to the index page. That's normall. But what I want now is to make my website different for people that are registered.For example that when your logged in, there are more options in the menu like "My Account" and things like that.And if your logged in some parts on pages will reveal more text then the standard guest page.I was wondering if this is hard?I guess it's not.. but I recently started with php so I don't know how to do it.Thanx in advance Quote Link to comment Share on other sites More sharing options...
marcus Posted December 31, 2006 Share Posted December 31, 2006 That's pretty simple.If you use cookies:[code]<?php//stuff available to everyone hereif(isset($_COOKIE['logged'])){//add my account logged in only stuff here}?>[/code]For sessions:[code]<?php//stuff available to everyone hereif(isset($_SESSION['logged'])){//add my account logged in only stuff here}?>[/code]Just changed logged to whatever your cookie or session is called when the user logs in. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 31, 2006 Share Posted December 31, 2006 Well, you don't state what variables you set once a user is logged in so it's impossible to give any specific example. But, assuming you have a session variable called $_SESSION['loggedin'] and have it set to one if the user is logged in and 0 otherwise, just create your menu something like this:[code]<?phpecho "<a href=\"link1.htm\">Menu Item 1</a><br />";echo "<a href=\"link2.htm\">Menu Item 2</a><br />";echo "<a href=\"link3.htm\">Menu Item 3</a><br />";echo "<a href=\"link4.htm\">Menu Item 4</a><br />";if ($_SESSION['loggedin']==1) { echo "<a href=\"link5.htm\">Menu Item 5</a><br />"; echo "<a href=\"link6.htm\">Menu Item 6</a><br />";}?>[/code] Quote Link to comment Share on other sites More sharing options...
adaywalkr Posted December 31, 2006 Author Share Posted December 31, 2006 Thanks for the replies.In the script itself there is a php file called "logged_in.php" and this that's where it should lead you after you logged in.[code]<?phpinclude('config.php');if(!isset($_SESSION['user'])) { header("Location: login.php");}?><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Logged in with succes!</title></head><body><p>Welcome, <?=$_SESSION['user']?></p><p>--> <a href="logout.php">Logout</a> </p><p> </p></body></html>[/code]And it works with me if I put this in my menu:[code]<?phpinclude('config.php');if ($_SESSION['user']) {echo "It WOrks !!!";}?>[/code]It works.. but it shows this error:Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/website/domains/website.com/public_html/index.php:8) in /home/website/domains/website.com/public_html/session.php on line 2 Quote Link to comment Share on other sites More sharing options...
HoTDaWg Posted December 31, 2006 Share Posted December 31, 2006 can u please reexplain, which script are u getting that error from? Quote Link to comment Share on other sites More sharing options...
adaywalkr Posted December 31, 2006 Author Share Posted December 31, 2006 That error is there because I insered this code into my home page:[code]<?phpinclude('config.php');if ($_SESSION['user']) {echo "It WOrks !!!";}?>[/code]It does work.. but it gives that error before the textI think it's because of the include before the session... but the include has to be there or it won't work :-[ Quote Link to comment Share on other sites More sharing options...
adaywalkr Posted December 31, 2006 Author Share Posted December 31, 2006 Ok, got it to work.Can someone explain how I can replace Login in my menu with Logout if the person is logged in?Thanx! Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted December 31, 2006 Share Posted December 31, 2006 [code=php:0]if(isset($_SESSION['user'])){echo "Logout";}else{echo "Login";}[/code]:) Quote Link to comment 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.