$SESSIONS
Page 1 of 114 Replies - 908 Views - Last Post: 08 February 2010 - 12:20 PM
#1
$SESSIONS
Posted 22 January 2010 - 01:38 PM
I have multiple databases that I use. Calendar, check book etc..
They don't all use username for the session id, one uses cal_user, the other uses cb_user after logging in. The name logged in with is the same, just different id for each database.
Is there a way so when logged in that the $SESSIONS can be changed to the right one so not having to log in on each database?
Thanks
Bob
Replies To: $SESSIONS
#2
Re: $SESSIONS
Posted 22 January 2010 - 01:48 PM
So you want to just which the session if you where logged into one db then when you want to go into the other if you are logged in to the first switch the session to the correct db that you are going too?
Like I said not pro but, If you can just do some code that checks the sessions, and if there is a session that is registered and proves that the user is logged into the other db go ahead and take the information from that session and put it into the new db session ID.
I do not know if this can be done I guess, because I don't know actually how your code is, but in theory (with my limited knowledge) I believe this can work.
***Edit: I do believe this can only work if the database's are on the same server, because session is saved on the server not database if I am correct, but wait from some one with a little more knowledge to post what they think***
This post has been edited by Elbrus: 22 January 2010 - 01:51 PM
#3
Re: $SESSIONS
Posted 22 January 2010 - 01:58 PM
It would also need to know in reverse when I go back to something else.
Would I just put a lot variables?
$username = $cal_user;
$username = $cduser;
I would think one would cancel the other out.
or would I put the one that is needed for that particular database and back again?
Calendar------
$username = $cal_user
-----------------
Back to previous database
$cal_user = $username;
What I use now
[code]
<?php
require_once('config.php');
session_start();
if(!isset($_SESSION['username'])) { // if not logged in
header("Location: $config_base_dir/loginform.html"); // redirect to login form from any url
exit;
}
[/end code]
?>
Elbrus, on 22 Jan, 2010 - 12:48 PM, said:
So you want to just which the session if you where logged into one db then when you want to go into the other if you are logged in to the first switch the session to the correct db that you are going too?
Like I said not pro but, If you can just do some code that checks the sessions, and if there is a session that is registered and proves that the user is logged into the other db go ahead and take the information from that session and put it into the new db session ID.
I do not know if this can be done I guess, because I don't know actually how your code is, but in theory (with my limited knowledge) I believe this can work.
***Edit: I do believe this can only work if the database's are on the same server, because session is saved on the server not database if I am correct, but wait from some one with a little more knowledge to post what they think***
#4
Re: $SESSIONS
Posted 22 January 2010 - 02:06 PM
$_SESSION['username']=cal_user; // this is calender database $_SESSION['username']=cd_user; // is other database
Before I say anything please correct me if I am wrong
#5
Re: $SESSIONS
Posted 22 January 2010 - 02:10 PM
But yes, this looks like what I might be looking for.
I'll have to look in the WebCalendar and find where to put it, or would there be a way to put it in the link command from a menu I could create?
Elbrus, on 22 Jan, 2010 - 01:06 PM, said:
$_SESSION['username']=cal_user; // this is calender database $_SESSION['username']=cd_user; // is other database
Before I say anything please correct me if I am wrong
#6
Re: $SESSIONS
Posted 22 January 2010 - 02:42 PM
If this looks good to you test if offline please first.
function check_session($session){
if($session == $_SESSION['username'] || $_SESSION['cal_user'] || $_SESSION['cd_user'])
$value=true;
}
else{
$value=false;
}
return $value;
}
// Now just check what the function return if it returns false redirect to login.
#7
Re: $SESSIONS
Posted 22 January 2010 - 03:39 PM
I too am just learning this stuff. I only started a few weeks ago.
I did a bit in "C" back when dos 3.2 was the big deal and windows 2.0 was just starting out. Never learned Visual.
I then started using Linux Slackware back when they called it Slackware 95, before they started calling it and number 2.0, 12.1, etc. Still use it. Do as little as possible on windows. I also use Mandriva for anything that does not need windows to run.
So this has been a real learning curve. but it's coming along.
A lot of good sources on the web since PHP/MySql is open source so help can always be fouond.
Elbrus, on 22 Jan, 2010 - 01:42 PM, said:
If this looks good to you test if offline please first.
function check_session($session){
if($session == $_SESSION['username'] || $_SESSION['cal_user'] || $_SESSION['cd_user'])
$value=true;
}
else{
$value=false;
}
return $value;
}
// Now just check what the function return if it returns false redirect to login.
#8
Re: $SESSIONS
Posted 22 January 2010 - 04:03 PM
While you are learning just post back here and you will get help, it may some time take a while but it will come.
#9
Re: $SESSIONS
Posted 22 January 2010 - 04:49 PM
Elbrus, on 22 Jan, 2010 - 03:03 PM, said:
While you are learning just post back here and you will get help, it may some time take a while but it will come.
#10
Re: $SESSIONS
Posted 22 January 2010 - 05:06 PM
brosskgm, on 22 Jan, 2010 - 03:49 PM, said:
Elbrus, on 22 Jan, 2010 - 03:03 PM, said:
While you are learning just post back here and you will get help, it may some time take a while but it will come.
Well It depends on how you want to do it you can put it in a class and call it from another file... or add it to the page so your options
include("php file that has the function in it");
// rest of code here...
Or yes add that to every page... it makes more sens to call a file that has the function then right it every time, but that is up to you really.
This post has been edited by Elbrus: 22 January 2010 - 05:09 PM
#11
Re: $SESSIONS
Posted 22 January 2010 - 05:17 PM
Any of the ones I put together will use the main one, so I might only have to put it in the ones that are different.
This will work great.
Thanks
Elbrus, on 22 Jan, 2010 - 04:06 PM, said:
brosskgm, on 22 Jan, 2010 - 03:49 PM, said:
Elbrus, on 22 Jan, 2010 - 03:03 PM, said:
While you are learning just post back here and you will get help, it may some time take a while but it will come.
Well It depends on how you want to do it you can put it in a class and call it from another file... or add it to the page so your options
include("php file that has the function in it");
// rest of code here...
Or yes add that to every page... it makes more sens to call a file that has the function then right it every time, but that is up to you really.
#12
Re: $SESSIONS
Posted 22 January 2010 - 05:33 PM
Ill still post it here for the sake of it just in case you need it, again please test it before hand because I am new and don't want to give you bad code by mistake.
<?php
//this is the class with the function you will use.
Class youclassname
{
function check_session($session){
if($session == $_SESSION['username'] || $_SESSION['cal_user'] || $_SESSION['cd_user']){
$value=true;
}
else{
$value=false;
}
return $value;
}
}
//save the above code in a seprate file name it what everyou want, and you can change the class name...
//the code below will be in the begining of your other pages
include("classfile.php")
session_start();
//this starts the relation between the class with the function and this file.
class = new yourclassname();
//now to call the function
$output=class->check_session($_SESSION['username']);
//thiss will call the function from the class and put the value returned into $output
//now all you need to do now is wright a small if statment to check the $output if its false then redrect to log in page.
//or you can just make another function in the class and call it the same way.. but you do not need to call another new youclass();
// I will just do the if statment here, if this all works you can just add to class file or keep it as is your choice.
if($output == false){
header(Location:"login location");
}
?>
#13
Re: $SESSIONS
Posted 22 January 2010 - 06:13 PM
I know what database I need to put together. One to store all the little pieces of code, so I can search and reference from anywhere. Right now I burn them to DVD, but mySql might be better better choice.
Elbrus, on 22 Jan, 2010 - 04:33 PM, said:
Ill still post it here for the sake of it just in case you need it, again please test it before hand because I am new and don't want to give you bad code by mistake.
<?php
//this is the class with the function you will use.
Class youclassname
{
function check_session($session){
if($session == $_SESSION['username'] || $_SESSION['cal_user'] || $_SESSION['cd_user']){
$value=true;
}
else{
$value=false;
}
return $value;
}
}
//save the above code in a seprate file name it what everyou want, and you can change the class name...
//the code below will be in the begining of your other pages
include("classfile.php")
session_start();
//this starts the relation between the class with the function and this file.
class = new yourclassname();
//now to call the function
$output=class->check_session($_SESSION['username']);
//thiss will call the function from the class and put the value returned into $output
//now all you need to do now is wright a small if statment to check the $output if its false then redrect to log in page.
//or you can just make another function in the class and call it the same way.. but you do not need to call another new youclass();
// I will just do the if statment here, if this all works you can just add to class file or keep it as is your choice.
if($output == false){
header(Location:"login location");
}
?>
#14
Re: $SESSIONS
Posted 22 January 2010 - 06:43 PM
and don't forget to click this post was helpful
Good Luck
#15
Re: $SESSIONS
Posted 08 February 2010 - 12:20 PM
This post has been edited by brosskgm: 09 February 2010 - 09:41 AM
|
|

New Topic/Question
Reply




MultiQuote



|