How do you create session variables ?

Discussion in 'PHP' started by crazygirl, Mar 6, 2008.

  1. #1
    I am trying to integrate 2 programs phpfox and fscchat and the fscchat people to do it simply :

    "When the user logs into your site just create php session variables user_id and user_sex. In user_id variable the value should be the user name that will appear in chat. User picture cannot be loaded in icon."


    Easy for them to say how in the world can you do that ?? I will gladly pay a few bucks to someone willing to do this thanks in advance
     
    crazygirl, Mar 6, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Make sure you initialize the session at the very top of the document.

    session_start();

    To register a session variable, all you need to do is this:

    $_SESSION['user_id'] = $user_id;
    $_SESSION['user_sex'] = $user_sex;

    As long as session_start() is called, those variables will be available.
     
    jestep, Mar 6, 2008 IP
  3. crazygirl

    crazygirl Peon

    Messages:
    659
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks I tried that in php_loader.php which is called in every session I believe and index.php and when you try to go to the Chat Area is still says "Error Invalid User" which they say "you have created the variables incorrectly"
     
    crazygirl, Mar 6, 2008 IP
  4. crazygirl

    crazygirl Peon

    Messages:
    659
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here are the instructions and I followed them no luck

    1) open the file ‘chat1.php’ in ‘vchat’ folder and remove the following lines

    $_SESSION['user_id']=$_POST['uname'];
    $_SESSION['user_sex']=$_POST['sex'];
    if($_SESSION['user_id']=="" || $_SESSION['user_sex']=="")
    header("Location:chat.php?e=1");

    create session variables user_id, user_sex when the user logs in your
    site. The video chat will automatically read data from session
    variables(user_id,user_sex) and the user will log into the chat with the
    id,sex values stored in session variables.

    For value of sex in session variable(user_sex ) use
    “F” in caps for Female
    “M” in caps for Male
    “C” in caps for Couple
    Please make sure that “F”, “M”, “C” values are in uppercase

    Note: If you check the lines that we have just removed from chat1.php,
    then you will find that we were just creating session variables with the
    data posted by the form on chat.php and as we have removed the
    above code for creating session variables, so you are required to create
    these session variables when user logs in your site. After you have
    created session variables and user clicks the link for the video chat,
    values from user_id,user_sex session variables will be read by video
    chat. If you have not created session variables correctly, you will receive
    an “Invalid User” error in chat.

    2) Provide a link on your site directly to chat1.php after doing the above
    step 1. Your chat will be integrated into your site.
     
    crazygirl, Mar 6, 2008 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    That looks fine to me. Is session_start() somewhere above that code? If the session was never started then those variables won't be registered. Other than that, I'm not sure what's going on.
     
    jestep, Mar 6, 2008 IP
  6. crazygirl

    crazygirl Peon

    Messages:
    659
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes session_start() is directly above the code
     
    crazygirl, Mar 6, 2008 IP