Greetings,
I got no clue how to make / set a session.
When i login on my page and then press a link i get out-logged, I've tried to read on PHP.net but i cant get it together.

Anyone got an explaination or code i could go from to keep my members logged in for 60min at a time?

It sounds as if you are using a system that has it's own login and timeout processing. This is specific to the system that you are using (e.g. a Forum or a CMS) and even though it may be using PHP session management as part of the timeout processing, that probably isn't what you need to change. You have provided a very vague explanation of your problem. No one will be able to help you unless you provide more details. If you are using a package of some sort, then you may get a quicker answer from a forum that is specific to that system.

It sounds as if you are using a system that has it's own login and timeout processing. This is specific to the system that you are using (e.g. a Forum or a CMS) and even though it may be using PHP session management as part of the timeout processing, that probably isn't what you need to change. You have provided a very vague explanation of your problem. No one will be able to help you unless you provide more details. If you are using a package of some sort, then you may get a quicker answer from a forum that is specific to that system.

I am building my first "CMS"
No cache or cookie is included, and to be honest i do not know what information i should post. All i need is a small wake-up how i could make a user, who logs in, to stay logged in.
I dunno what to include..

My login.php script:

<?php
if (!isLoggedIn())
{
    // user is not logged in.
    if (isset($_POST['cmdlogin']))
    {
        // retrieve the username and password sent from login form & check the login.
        if (checkLogin($_POST['username'], $_POST['password']))
        {
            show_userbox();
        } else
        {
            echo "Incorrect Login information !";
            show_loginform();
        }
    } else
    {
        // User is not logged in and has not pressed the login button
        // so we show him the loginform
        show_loginform();
    }
 
} else
{
    // The user is already loggedin, so we show the userbox.
    show_userbox();
}
?>

My login.functions.inc.php:

<?php
 
#### Login Functions #####

 
function isLoggedIn()
{
 
    if (session_is_registered('loginid') && session_is_registered('username'))
    {
        return true; // the user is loged in
    } else
    {
        return false; // not logged in
    }
 
    return false;
 
}
 
function checkLogin($u, $p)
{
global $seed; // global because $seed is declared in the header.php file
 
    if (!valid_username($u) || !valid_password($p) || !user_exists($u))
    {
        return false; // the name was not valid, or the password, or the username did not exist
    }
 
    //Now let us look for the user in the database.
    $query = sprintf("
		SELECT loginid 
		FROM login 
		WHERE 
		username = '%s' AND password = '%s' 
		AND disabled = 0 AND activated = 1 
		LIMIT 1;", mysql_real_escape_string($u), mysql_real_escape_string(sha1($p . $seed)));
    $result = mysql_query($query);
    // If the database returns a 0 as result we know the login information is incorrect.
    // If the database returns a 1 as result we know  the login was correct and we proceed.
    // If the database returns a result > 1 there are multple users
    // with the same username and password, so the login will fail.
    if (mysql_num_rows($result) != 1)
    {
        return false;
    } else
    {
        // Login was successfull
        $row = mysql_fetch_array($result);
        // Save the user ID for use later
        $_SESSION['loginid'] = $row['loginid'];
        // Save the username for use later
        $_SESSION['username'] = $u;
        // Now we show the userbox
        return true;
    }
    return false;
}
 
?>

My header.php (is included in index.php)

<?php
error_reporting(0); // we don't want to see errors on screen
// Start a session
session_start();
require_once ('db_connect.inc.php'); // include the database connection
require_once ('functions.inc.php'); // include all the functions
$seed="0dAfghRqSTgx"; // the seed for the passwords
$domain =  "dawnforged.com/"; // the domain name without http://www.
?>

And i think it is important to tell that i have a small and smart php script that loads my pages into a frame in my index.php without refreshing the index completly.

I hope this will help, all i want is to make the user to stay logged in.

Cheers,
Sorcher

Solved via PM!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.