14 Replies - 1050 Views - Last Post: 08 February 2010 - 12:20 PM Rate Topic: -----

#1 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

$SESSIONS

Post icon  Posted 22 January 2010 - 01:38 PM

Question about $SESSIONS

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
Is This A Good Question/Topic? 0
  • +

Replies To: $SESSIONS

#2 Elbrus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: $SESSIONS

Posted 22 January 2010 - 01:48 PM

I'm no pro in php, I am actually still new, but I am going to take a hit in the dark with this one...


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

Was This Post Helpful? 0
  • +
  • -

#3 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: $SESSIONS

Posted 22 January 2010 - 01:58 PM

I'm not sure where to look. I'm not sure what the I would change this to. When logging in, it's username, but in the calendar it's cal_user, how do I tell this username also = cal_user

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]
?>


View PostElbrus, on 22 Jan, 2010 - 12:48 PM, said:

I'm no pro in php, I am actually still new, but I am going to take a hit in the dark with this one...


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***

Was This Post Helpful? 0
  • +
  • -

#4 Elbrus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: $SESSIONS

Posted 22 January 2010 - 02:06 PM

So how I am understanding is in each database
$_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
Was This Post Helpful? 0
  • +
  • -

#5 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: $SESSIONS

Posted 22 January 2010 - 02:10 PM

And then another database is username, and username is the main one that I use more than the others.

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?


View PostElbrus, on 22 Jan, 2010 - 01:06 PM, said:

So how I am understanding is in each database
$_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

Was This Post Helpful? 0
  • +
  • -

#6 Elbrus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: $SESSIONS

Posted 22 January 2010 - 02:42 PM

Please look over this code I am trying to help, but I am new to php.

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.




Was This Post Helpful? 0
  • +
  • -

#7 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: $SESSIONS

Posted 22 January 2010 - 03:39 PM

OK, sure will.

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.

View PostElbrus, on 22 Jan, 2010 - 01:42 PM, said:

Please look over this code I am trying to help, but I am new to php.

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.




Was This Post Helpful? 0
  • +
  • -

#8 Elbrus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: $SESSIONS

Posted 22 January 2010 - 04:03 PM

Yes, PHP and mysql has alot of help since it is open source. I have been trying to learn for a while, and once I found this site my learning sky rocketed the help the member of this site give in the mod's is the best I have seen and I have been on a lot of programing forum sites.

While you are learning just post back here and you will get help, it may some time take a while but it will come.
Was This Post Helpful? 0
  • +
  • -

#9 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: $SESSIONS

Posted 22 January 2010 - 04:49 PM

with the function you posted. Does that get put only on the login, or does it have to go on each page?

View PostElbrus, on 22 Jan, 2010 - 03:03 PM, said:

Yes, PHP and mysql has alot of help since it is open source. I have been trying to learn for a while, and once I found this site my learning sky rocketed the help the member of this site give in the mod's is the best I have seen and I have been on a lot of programing forum sites.

While you are learning just post back here and you will get help, it may some time take a while but it will come.

Was This Post Helpful? 0
  • +
  • -

#10 Elbrus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: $SESSIONS

Posted 22 January 2010 - 05:06 PM

View Postbrosskgm, on 22 Jan, 2010 - 03:49 PM, said:

with the function you posted. Does that get put only on the login, or does it have to go on each page?

View PostElbrus, on 22 Jan, 2010 - 03:03 PM, said:

Yes, PHP and mysql has alot of help since it is open source. I have been trying to learn for a while, and once I found this site my learning sky rocketed the help the member of this site give in the mod's is the best I have seen and I have been on a lot of programing forum sites.

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

Was This Post Helpful? 0
  • +
  • -

#11 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: $SESSIONS

Posted 22 January 2010 - 05:17 PM

The calendar has a class file. The others do not. they are small anyway.

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


View PostElbrus, on 22 Jan, 2010 - 04:06 PM, said:

View Postbrosskgm, on 22 Jan, 2010 - 03:49 PM, said:

with the function you posted. Does that get put only on the login, or does it have to go on each page?

View PostElbrus, on 22 Jan, 2010 - 03:03 PM, said:

Yes, PHP and mysql has alot of help since it is open source. I have been trying to learn for a while, and once I found this site my learning sky rocketed the help the member of this site give in the mod's is the best I have seen and I have been on a lot of programing forum sites.

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.

Was This Post Helpful? 0
  • +
  • -

#12 Elbrus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: $SESSIONS

Posted 22 January 2010 - 05:33 PM

Good, glad to help I was writing some more code to help you, but had to stop to feed my son :D

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");
	
	}

?>



Was This Post Helpful? 0
  • +
  • -

#13 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: $SESSIONS

Posted 22 January 2010 - 06:13 PM

Wow!!, thanks.

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.

View PostElbrus, on 22 Jan, 2010 - 04:33 PM, said:

Good, glad to help I was writing some more code to help you, but had to stop to feed my son :D

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");
	
	}

?>



Was This Post Helpful? 0
  • +
  • -

#14 Elbrus  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 107
  • Joined: 22-July 08

Re: $SESSIONS

Posted 22 January 2010 - 06:43 PM

I would like to know if you use my code how it works :D

and don't forget to click this post was helpful :^:

Good Luck
Was This Post Helpful? 0
  • +
  • -

#15 brosskgm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 20-January 10

Re: $SESSIONS

Posted 08 February 2010 - 12:20 PM

N

This post has been edited by brosskgm: 09 February 2010 - 09:41 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1