Need some help in passing variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rmd1984
Forum Newbie
Posts: 2
Joined: Mon May 26, 2008 5:14 am

Need some help in passing variables

Post by rmd1984 »

Hi everybody,
I am trying to modify a php script which accesses user information from several databases. It checks for username and password(in index.php) and then redirects the page to another script(hub.php), which uses different database according to users project.
Now this script uses database information(like $host,$database,$password and $username) from a script(database.php). I want to modify the database in this script dynamically according to the users selection of project. since each project is situated on different database. So.
1. after username and password check in index.php script it should redirect to a script called hub.php as well as modify the $database in database.php script.
I was trying to use $_SESSION but some how it is not working properly. Any help is deeply appreciated.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Need some help in passing variables

Post by califdon »

rmd1984 wrote:Hi everybody,
I am trying to modify a php script which accesses user information from several databases. It checks for username and password(in index.php) and then redirects the page to another script(hub.php), which uses different database according to users project.
Now this script uses database information(like $host,$database,$password and $username) from a script(database.php). I want to modify the database in this script dynamically according to the users selection of project. since each project is situated on different database. So.
1. after username and password check in index.php script it should redirect to a script called hub.php as well as modify the $database in database.php script.
I was trying to use $_SESSION but some how it is not working properly. Any help is deeply appreciated.
First of all, I would certainly avoid maintaining password data in a session variable, because sessions are commonly implemented as cookies on the client machine, making it simple to hack.

Why don't you just do the user info lookup in hub.php, where you can determine the connection data from the project (which CAN be stored as a session variable)?
rmd1984
Forum Newbie
Posts: 2
Joined: Mon May 26, 2008 5:14 am

Re: Need some help in passing variables

Post by rmd1984 »

Thanks for reply.
The user name and password are fetched from an html page and then checked in index.php script. Here I also check the number of different projects a user is working in.(each project is situated in different database). And depending upon the selection of a particular project the hub.php file should access the particular database of the selected project. Now I have modify this database in mysql_select_db() option in hub.php file everytime the user select a project in index.php file.
but the problem is not only that. This hub.php script uses two more scripts called detail.php and insert.php for doing some things. Now my question is, how do I modify the database in these two scripts selected by user in index.php script.
(In short how to pass variables to these two scripts from insert.php(first script).
What I did till now is as follows:
1. I accept username and password from an html page and pass it to index.php script for verification as well as check for the projects(each project has different database) the user is involved in.
2. Then display a dropdown box with different projects for selection.
3. After selection of the project the page is redirected to hub.php.(I am trying to use $_SESSION for passing the selected database(project) to hub.php)
4. hub.php uses two more scripts which are supposed to use the same database as hub.php
So how do I pass this database variable to these two scripts.
(tried using $_SESSION, it seems to work for some time,but then after a while I loose the connection with database and get error message saying database does not exist. i think i am loosing the database variable somehow after sometime because of some reason i am not able to understand. it works fine for sometime but stops working abruptly.)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Need some help in passing variables

Post by califdon »

rmd1984 wrote:Thanks for reply.
The user name and password are fetched from an html page and then checked in index.php script. Here I also check the number of different projects a user is working in.(each project is situated in different database). And depending upon the selection of a particular project the hub.php file should access the particular database of the selected project. Now I have modify this database in mysql_select_db() option in hub.php file everytime the user select a project in index.php file.
but the problem is not only that. This hub.php script uses two more scripts called detail.php and insert.php for doing some things. Now my question is, how do I modify the database in these two scripts selected by user in index.php script.
(In short how to pass variables to these two scripts from insert.php(first script).
What I did till now is as follows:
1. I accept username and password from an html page and pass it to index.php script for verification as well as check for the projects(each project has different database) the user is involved in.
2. Then display a dropdown box with different projects for selection.
3. After selection of the project the page is redirected to hub.php.(I am trying to use $_SESSION for passing the selected database(project) to hub.php)
4. hub.php uses two more scripts which are supposed to use the same database as hub.php
So how do I pass this database variable to these two scripts.
(tried using $_SESSION, it seems to work for some time,but then after a while I loose the connection with database and get error message saying database does not exist. i think i am loosing the database variable somehow after sometime because of some reason i am not able to understand. it works fine for sometime but stops working abruptly.)
Maybe either your session is timing out or the MySQL host is timing out. You should be able to control your session time-out, which certainly should remain active for hours, at the very least, but you might not be able to control the db server, depending on whether you have access to the configuration of the server.

But as an overall approach, I think you are now describing what I suggested: keep the user and the project in session variables, do the lookup of database connection string in each script and connect to the db only when you need to perform a query.
Post Reply