Jump to content

Help with Sessions in my Login Script


hologramman

Recommended Posts

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

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";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.