Click here to Skip to main content
15,885,182 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I can't understand the code below and I don't know when we use session_id() before session_start()


PHP
<?php
if($_GET){
    //defining the session_id() before session_start() is the secret
    session_id($_GET['session_id']);
    session_start();
    echo "Data: " . $_SESSION['theVar'];
    //use your data before below commands
    session_destroy();
    session_commit();
}else{
    //common session statement goes here
    session_start();
    $session_id=session_id();
    $_SESSION['theVar'] = "theData";
    echo "your.php?session_id=" . $session_id;
}
?>


on the other hand , where is session_id() used ?! what's its usage ?!
i want you to explain it or give me a better example ! not just copying the description of php.net !
thank you in advance !
Posted
Updated 26-Jul-15 20:27pm
v2
Comments
Mohibur Rashid 25-Jul-15 13:04pm    
I was going to answer you, but then I read 'i want you to explain it ! not just copying the description of php.net !'
Sergey Alexandrovich Kryukov 25-Jul-15 21:47pm    
I understand. "Explaining the code" is generally pretty bad idea for learning things. OriginalGriff illustrated it on several examples.
—SA
Member 11862812 27-Jul-15 2:33am    
Do you think analyzing a code is bad for learning !!?!!!!! By the way , i added the sentences "i want you to explain it ...!" , because many of people just write php.net description with no further explanation ....
Sergey Alexandrovich Kryukov 27-Jul-15 10:25am    
We are not talking about analyzing. Don't mix up different things and jump to wrong conclusions. In-depth analysis can be useful, but only if "I don't understand the code below..." is out of question. Code review can be useful. Learning by the code you have trouble to understand is a bad idea, explaining code you don't understand is a bad idea. Good idea is: write your own code and understand every line of it.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900