ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to get student matric, pass as session variable at test.php page, but it prints nothing, simply blank page, but in URL address I can see that I am in test.php page.
Distribution: Solaris 10, Solaris 8.0, Fedora Core 3
Posts: 203
Rep:
pcghost,
I used that method when I 1st began working on my web page. I started off using post forms to send logon info throughout different pages which worked. Using the session handling functions made it much easier. One thing I am not sure is how to get a session to stay alive if a user opens a new window from the same system. My website has a page that is members only while all other pages are open to anybody. When members navigate from the members only page to open pages I use session function calls to keep them logged in with a username variable. The member page checks the username against my database to see if they are still logged in. This process works fine as long as the member stays within the same window. If the member opens a new browser window they have to logon again. Is there anyway to perserve the session beyond a browser window? I'm still brainstorming on this. Perhaps someone else has already figured it out.
Distribution: Solaris 10, Solaris 8.0, Fedora Core 3
Posts: 203
Rep:
I have the info in a database already. I have a boolean variable that turns to false when members log off and true when they login. My problem is getting the username when a user opens up a new window. At that point I need to figure out how to identify the user.
Personnaly, what I use to do in those situation is recording the session_id in a cookie and in the db. Next time the user comes to the page, I get the old sessioin_id from the cookie and compare it to the one stored in the db. If there's a match so I can retreive the user's information based on that old session_id.
Distribution: Solaris 10, Solaris 8.0, Fedora Core 3
Posts: 203
Rep:
could you tell me how to do that or point me in a good direction. I've viewed tutorials from php.net, dev shed, and phpfreaks. like i said it works fine as long as the member is using the same window they used to login. i use session_register('username') on my login page and session_start() on the other pages. I also set the cookie on the home page. should i set a cookie every page? how do i use the cookie to get this user info?
Ok, here's what I mean... Note this will be pseudo-code not php:
<?php
session_start();
if (! isset($username)){
if(checksession(session_id()) ){
//Check if there was a session with this user
}else{
//new user without old session
// display login page
}
}
function checksession(session_id){
$oldSession=checkCookie("oldSession") ; // This function should return the old sessionID
$record=checkDB($oldSession); //this function should return the ID of the corresponding line in the db
// query should look like
// select *from table where oldSession=$oldSession;
// check if the query returned a record
// if so
$username=$record[username]
}
if this is not clear enough, I will program you a demo page and put the sources available somewhere..
Distribution: Solaris 10, Solaris 8.0, Fedora Core 3
Posts: 203
Rep:
I understand what you are saying but I just can't figure out how the checkCookie function works to get the old session_id. If I could just figure out how to get that old session id. Do i need to set a cookie at every page and store it somehow?
Last edited by linux_pioneer; 06-03-2004 at 12:29 AM.
I didn't bother about the mysql functionnality to get the record from the corresponding $old_session value ...
<?php
function checkCookie (){ // Finaly, no need for the session id as parm
global $_COOKIE,$old_session;
if (isset($_COOKIE['MyCookie'])) {
foreach ($_COOKIE['MyCookie'] as $name => $value) {
//echo "$name : $value <br />\n";
${$name}=$value; // Creates the variable and fill it. You should have $old_session=value afterward
}
}
if(isset($old_session) && $old_session !=""){
// compare this value in the database and take the correspondant records to fill
// The user's informations
}
// Then replace the information in the cookie by the new information:
$value = session_id()
setcookie("MyCookie[old_session]", $value);
// Also store the new value of old_session in the database..
?>
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.