kipper1960 Posted July 12, 2013 Share Posted July 12, 2013 Hoping someone can shed some light as I am new to php I have set up a login for members on my site and all this works well, once logged in it sends me to a members page where I have used the following code to protect the page but for the life of me I cannot get it to work, could some one help me out <? session_start(); if(!isset($_SESSION['username']) || $_SESSION['username']=="") { echo "Please login to see this page....."; } else { content(); } function content() { My members page information I thought goes in here } ?> Quote Link to comment https://forums.phpfreaks.com/topic/280108-password-protect-page/ Share on other sites More sharing options...
fastsol Posted July 12, 2013 Share Posted July 12, 2013 What exactly doesn't work? The first thing to note is that the function you declare needs to go before the call of the function in your else{}. Remember that php works top-to-bottom, so if you try to use a var or function before it's actually declared it won't work. Also you would have know this if you have error_reporting(E_ALL) turned on. Quote Link to comment https://forums.phpfreaks.com/topic/280108-password-protect-page/#findComment-1440529 Share on other sites More sharing options...
kipper1960 Posted July 12, 2013 Author Share Posted July 12, 2013 Fatsol thanks for your reply but I dont understand sorry, this is the error I get after I have logged in and re-directed to the protected page Parse error: syntax error, unexpected '}' in /home3/profitst/public_html/integration.php on line 17 Quote Link to comment https://forums.phpfreaks.com/topic/280108-password-protect-page/#findComment-1440535 Share on other sites More sharing options...
trq Posted July 12, 2013 Share Posted July 12, 2013 That is a simple syntax error. You should be able to fix it yourself, if not, we need to see your actual (and only relevant) code. Quote Link to comment https://forums.phpfreaks.com/topic/280108-password-protect-page/#findComment-1440538 Share on other sites More sharing options...
kipper1960 Posted July 13, 2013 Author Share Posted July 13, 2013 trq, thanks for that, as I have limited knowledge all I was asking for does the member content go in the position of the code as I showed in the first post and if not were does it sit Quote Link to comment https://forums.phpfreaks.com/topic/280108-password-protect-page/#findComment-1440542 Share on other sites More sharing options...
fastsol Posted July 13, 2013 Share Posted July 13, 2013 This is the correct way to use the code you have. session_start(); // Notice that the function declaration is now above where you call the function. function content() { echo 'My members page information I thought goes in here'; } if(!isset($_SESSION['username']) || $_SESSION['username']=="") { echo "Please login to see this page....."; } else { // This is considered a function call below. content(); } Quote Link to comment https://forums.phpfreaks.com/topic/280108-password-protect-page/#findComment-1440543 Share on other sites More sharing options...
kipper1960 Posted July 13, 2013 Author Share Posted July 13, 2013 Fastsol, thank you kindly for you information, that has fixed the problem Quote Link to comment https://forums.phpfreaks.com/topic/280108-password-protect-page/#findComment-1440545 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.