Page 1 of 1

How do I get session variables in file browser navigates to?

Posted: Sat May 31, 2008 8:32 am
by wvxvw
Hi, I'm doing this for the first time, so please forgive me if I ask something dumb...
First, here're php.ini settings related to handling sessions:

Code: Select all

[Session]
session.save_handler = files
session.save_path = "C:\windows\tmp"
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 1800
session.cookie_path = /
session.cookie_domain = 
session.cookie_httponly = 0
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor     = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = 0
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = 
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
This file, if passed login section (don't mind it, it's not the actual script I use to authenticate the user, just an example)

Code: Select all

<?php
session_start();
session_regenerate_id(true);
 
function session_started(){
    if(isset($_SESSION)){
        return true;
    }else{
        return false;
    }
}
function go_relogin(){
    session_unset();
    session_destroy();
    header('Location: login.php');
}
 
if ($_POST["user_name"] == "admin"){
    if ($_POST["user_password"] == "password") {
        $user_admin = true;
        $user_login = $_POST["user_name"];
        $user_pwd = $_POST["user_password"];
        $_SESSION["suser_admin"] = 1;
        $_SESSION["suser_name"] = $user_login;
        $_SESSION["suser_password"] = $user_pwd;
        session_write_close();
        if (!session_started()) {
            exit ("Failed to start session!");
        }
        output_success();
    } else {
        go_relogin();
    }
} else {
    go_relogin();
}
if(!$user_admin) exit("wrong login / password!");
 
function output_success () {
    if ($_SESSION["suser_admin"]) {
        header('Location: manage_uploads.php');
        //print "<a href=\"manage_uploads.php\">Manage uploads</a>";
    } else {
        print "There\'s something weird going on with the session...";
    }
}
?>
And here's the manage_uploads.php

Code: Select all

function session_started(){
    if(isset($_SESSION)){
        return true;
    }else{
        return false;
    }
}
if(!session_started()) exit ("Session not started!"); // always exits here, no matter what...
What am I doing wrong?
TIA.

Re: How do I get session variables in file browser navigates to?

Posted: Sat May 31, 2008 1:29 pm
by xitura
You have no session_start() in manage_uploads.php

Re: How do I get session variables in file browser navigates to?

Posted: Sat May 31, 2008 2:26 pm
by wvxvw
Ok, thank you. I sort of figured out that by now, but anyway, thank you. I had few more problems, with it.
session.save_path = "C:\windows\tmp" (this folder didn't exist) me bad...