hologramman Posted August 25, 2009 Share Posted August 25, 2009 Hello everyone, I have not coded in years so I am a bit rusty. I want it to be able to see if a particular type of user is registered (for example, writers, administrators, etc.). If you are a writer, then a link appears to take you to the "writers" page. My login itself works, but when I try to redirect to the "writers.php" page I am having issues. The writers.php page includes "check_session.php" and check_session.php is supposed to see if you are a writer before allowing you access to that page. But instead of loading writers.php, it just takes you back to the login page. The following code page is my check_session.php. It seems my new host uses php as cgi so that could be the issue? Or maybe I'm using antiquated code? I haven't coded in a very long time so I guess maybe I'm doing something wrong. Any help is very much appreciated. <?php session_start(); if (!session_is_registered("user_type") || (!strstr($user_type, "writer"))) { header("Location: ../login.php?target=writer/writers.php"); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/171711-help-with-sessions-in-my-login-script/ Share on other sites More sharing options...
hologramman Posted August 25, 2009 Author Share Posted August 25, 2009 Just found out that session_is_registered is obsolete. If anybody can tell me how to properly code this session, would be appreciated. Thank you. Link to comment https://forums.phpfreaks.com/topic/171711-help-with-sessions-in-my-login-script/#findComment-905492 Share on other sites More sharing options...
Jezza Posted August 25, 2009 Share Posted August 25, 2009 Well usually i set variables so like for instance, if someone is logging into a general website and i only needed to remember the persons logged in username as he went around the website my coding would look like <? //if login is correct blablabla $_SESSION['user'] = $_POST['username']; ?> so then i would be identified as Jezza. On other pages there would be something to check to see if i'm logged in it could simply be <? if($_SESSION['user'] <> "') { echo "You're logged in! Welcome ".$_SESSION['user']; } else { echo "Go away..."; } ?> For your thing you need the persons type of account to be registered too so it could be on login setting 2 session variables $_SESSION['user'] = $_POST['username'];(for example) $_SESSION['type'] = whatever (whereever you get his type from); then pages that check it can look like this <? if($_SESSION['type'] == "writer") { echo "You are a writer flhalfhaofhflkashdaskl;hdaslkh"; } else { echo "You are not a writer"; } ?> Link to comment https://forums.phpfreaks.com/topic/171711-help-with-sessions-in-my-login-script/#findComment-905645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.