tags:

views:

41

answers:

1

hey guys, i'm having a little problem. I'm working on a wordpress template which lists all files on my ftp. Therefore i ask for the the password and pass it straight along to the ftp_connect.

So the structure looks like this. I'm asking for the password, and if entered (and send) i'll include a file called ftp_include.php which lists all my files. That's working fine so far.

The only problem I have is that I reload/refresh this inlcude with Ajax (jQuery). However only the include. And everyime i refresh this include has to connect to the server again (with the password entered at the beginning).

A few guys already told me here that I need to work with SESSIONS in PHP, which store my password and inside my include i'm retrieving it again.

Somehow i can't figure out why my SESSION cookie wont work. I guess it's getting stored properly with this:

session_start();

                session_start();
                if(!isset($_SESSION['ftp-password']) ) {
                    $_SESSION['ftp-password'] = $_POST['password'];
                }
                var_dump(ini_get_all('session')); //shows both times 
                //this result:http://cl.ly/1hzA -> 
                //so it seems it doesn't get stored properly, does it? 

i think so because i'm retrieving the password inside the include with this lines:

if(isset($_SESSION['ftp-password']) ) {
    $ftp_user_pass = $_SESSION['ftp-password'];
    echo "Password: " . $ftp_user_pass;
} else {
    print "can't find cookie!";
}

and it even CONNECTS to the server for the first time. However as soon as i refresh the include with Ajax somehoe it always says "can't find cookie". Any idea why that happens. I even tried with set_cookie() but the same result.

thank you for your tips

A: 

It looks like WP does strange things with the sessions. Like it unsets them and/or overwrites them. Here is a page with some discussion on it, such as putting session_start() before get_header() (which was probably causing your headers already sent error).

Why don't you just store the password in a variable in php and pass that to jquery? E.g:

<?php
   $ftp_pass = $_GET['ftp_pass'];//or however you get the password
?>

<script>
window.setInterval('yourfunction()', 1000);

function yourfunction() { 
    alert('<?=$ftp_pass?>');//replace with your jQuery refresh code
}
</script>
stormdrain