php - How can I access a session variable set on page from a different page -


i've tried looking information on i'm trying do, results not i'm need done. i'm pretty sure there's answer out there issue, have no idea how search correct wording. anyways i'm trying is: here have created session variable

<?php // session started session_start();   // connecting database $host = "localhost"; $username = "username"; $password = "password"; $db_name = "potholio"; $tbl_name = "usertbl";  $conn = mysql_connect( $host, $username, $password ); if (! $conn ) {     die('could not connect: ' . mysql_error()); }  mysql_select_db( $db_name );  // submitting query , retrieving result) $myusername = $_get['myusername']; $mypassword = $_get['mypassword'];  $sql = "select * $tbl_name usrname='". $myusername ."' , pwd='". $mypassword ."'"; $result = mysql_query( $sql );  // checking results $count = mysql_num_rows( $result );  // directing user based on result if ( $count == 1 ) { 

now down below have set session variable want access later on.

    $userid = mysql_fetch_assoc( $result );     $_session['user'] = $userid['msgid'];      header('location: http://potholio.csproject.org/map.html'); } else {     echo "<script>alert('incorrect username or password');</script>";     header('location: http://potholio.csproject.org/'); }  // close database connection mysql_close(); ?> 

now i'm trying access session variable have set in different file called map.html using following code:

<?php // initiate session  session_start();  // store session data echo $_session['user'];  ?> 

the issue when echo see whether being set, echo doesn't return anything, i'm not sure what's going 1 since know variable getting set in other file, login.php. great. i'm complete beginner sessions , session variables.

you connecting in localhost , header redirect header('location: http://potholio.csproject.org/map.html'); seems redirect map.html different remote host, how expect keeps localhost session?


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -