php SESSION

Discussion in 'PHP' started by ohdang888, Mar 2, 2008.

  1. #1
    i want to be able to store the user ID into the session. How would i do that? I think the problem is below.

    
    $user_info = mysql_fetch_array($result);
    $id = stripslashes($user_info['id']);
    
    if($count==1){
    	// if user login is successful then create session
    	$_SESSION['email']=$email;
    	$_SESSION['id']=$id;
    	echo "<meta http-equiv='refresh' content='0;url=member_home.php'>";
    
    }else {
    	// if user login is wrong direct to failed.php
    	session_destroy();
    	echo "<meta http-equiv='refresh' content='0;url=failed.php'>";
    
    }
    
    Code (markup):
    and the code i would use to reveal it on the next page would be...
    
    $_SESSION['id']=$id; 
    echo $id;
    
    Code (markup):
    but its not working......
     
    ohdang888, Mar 2, 2008 IP
  2. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Morishani, Mar 2, 2008 IP
  3. zerxer

    zerxer Peon

    Messages:
    368
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #3
    As Morishani pointed out, you would need session_start(); before you attempt to do any other session stuff. Also, might I ask if it's required that you redirect with a meta tag like that? Does it have to put other stuff on the page too that you're doing it that way? Have you thought of redirecting with PHP instead using header("Location: failed.php"); ? Would be much quicker. :)
     
    zerxer, Mar 2, 2008 IP