I have on my website:


What i am trying to do is i have login point to redirect passing the login info from login.php. in redirect.php I want it to set all of the session variables that i will need everywhere else in the site, however, using:

On members/redirect.php

$_SESSION['id'] = 1;
header("location: ../index.php");

On index.php

print $_SESSION['id'];

Output not a thing..
Any help is greatly appreciated.

The code is fine - at least it runs on my Apache installation, and the output is "1", as expected.

On Redirect.php



$sql = mysql_query("SELECT * FROM members WHERE username='$username' AND password='$password'"); 
$login_check = mysql_num_rows($sql);
if($login_check > 0){ 
    $row = mysql_fetch_row($sql);
    $_SESSION['id'] = $row[0];

Later in that PHP scrip i am able to read the $_SESSION fin, but when i go to index.html:



$testvar = $_SESSION['id'];

<?php echo $testvar; ?>

I still return nothing from that.. I know that i have all my names correct.. it just wont pass between pages. I have cookies enabled and it will now work on either of my computers.
Could this be because i am going from subdirectory to root? do i have to have it work out of all the same folder?

Your HTML code is malformed, but I doubt that this is the cause of the unexpected behaviour.
If I understand the specs correctly, cookies are sent with the current document path as the cookie path. But all browsers which I have tested behave as expected on your code - the session cookie is set correctly and the session variables are available.
Did you try another browser?

i have tried it in both IE and Chrome and neither work =/
the html is different in the actual document i just made a quick mock up to show the usage.
i guess i will just stick to setting cookies instead of session vars.

Session variables rely on cookies - on the session cookie, to be precies, which in standard PHP has the name PHPSESSID. Check the cookies in your browser to see if this cookie is set, and if it has a path other than '/'.