jokerfool Posted September 10, 2009 Share Posted September 10, 2009 Some of my pages that are used for members only, the content can partially be seen by non members, exposing content to them, is there a command I can add to the top of the page that forces the user to login on the login.php page, so they don't see the part content? Is there some code I can use to validate the person is already a member and if they have the cookie log them in, otherwise redirect to login.php page? Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/ Share on other sites More sharing options...
eugeniu Posted September 10, 2009 Share Posted September 10, 2009 What is the code you use to validate that someone is logged in? Non-members can only see part of all of the content, so there must be something. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916347 Share on other sites More sharing options...
jokerfool Posted September 10, 2009 Author Share Posted September 10, 2009 What I mean by only seeing part of the content is because its protect by the php and cant be shown, I have no security to prevent users loading abc.php and see the content that isn't protected. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916374 Share on other sites More sharing options...
kingnutter Posted September 10, 2009 Share Posted September 10, 2009 I would use sessions for this. I use this for a site on which only I have admin permissions: <?php // Starting the session session_start('username'); $username = ($_SESSION['username']); if ($username !== 'insert admin persons login here') { header("Location: index.php"); } ?> It sends unauthorised users back to the homepage. So I'm sure you could use this based on a certain permissions level rather that a specific login. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916376 Share on other sites More sharing options...
jokerfool Posted September 10, 2009 Author Share Posted September 10, 2009 kingnutter, magic, does exactly what I need, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916381 Share on other sites More sharing options...
jokerfool Posted September 10, 2009 Author Share Posted September 10, 2009 Hmmmm, I have a question, with the above code am I too change anything? When I add the above code, the issue I am having is once I have logged in and visit a members page, the page reloads the index.php page and is displayed in the members section instead of the actual page. Did I miss something? Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916405 Share on other sites More sharing options...
ldb358 Posted September 11, 2009 Share Posted September 11, 2009 did you change the value of 'insert admin persons login here' to an actual username? Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916433 Share on other sites More sharing options...
jokerfool Posted September 11, 2009 Author Share Posted September 11, 2009 so what I just add the username of the admin login to that spot? Because if so I did that and still same issue. Just reloads index page. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916470 Share on other sites More sharing options...
mikesta707 Posted September 11, 2009 Share Posted September 11, 2009 post code? Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916471 Share on other sites More sharing options...
jokerfool Posted September 11, 2009 Author Share Posted September 11, 2009 there is no code to post, it just reloads the index page in the members page. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916481 Share on other sites More sharing options...
mikesta707 Posted September 11, 2009 Share Posted September 11, 2009 well if there were no code it wouldnt be doing anything. where is the code that reloads the index page? Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916510 Share on other sites More sharing options...
jokerfool Posted September 11, 2009 Author Share Posted September 11, 2009 kingnutters code is the code that I have used, in theory it works, but it doesnt. Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916536 Share on other sites More sharing options...
kingnutter Posted September 11, 2009 Share Posted September 11, 2009 You need to start the session again in the header of every page with member content. Then use code such as this where appropriate to restrict who can see it: <?php if(isset($_SESSION['username'])) { // Code for Logged members // Identifying the user $username = $_SESSION['username']; echo "Hello $username "; ?> <a href="logout.php"> Log Out?</a> <?php // Information for the user. } else { echo "Hello Stranger."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/173839-php-login-and-send-elsewhere-help-please/#findComment-916942 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.