Gamestudio Links
Zorro Links
Newest Posts
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 1,429 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
PHP help #202048
04/13/08 00:49
04/13/08 00:49
Joined: Jan 2008
Posts: 1,580
Blade280891 Offline OP
Serious User
Blade280891  Offline OP
Serious User

Joined: Jan 2008
Posts: 1,580
I am in the process of writing a PHP website template, but i have hit a snag .
I need the user to enter there details for there, mysql database, and then use them details to connect to it.
I have that part, but now , how can i get save these details so it will always connect to the database?


My Avatar Randomness V2

"Someone get me to the doctor, and someone call the nurse
And someone buy me roses, and someone burned the church"
Re: PHP help [Re: Blade280891] #202059
04/13/08 01:44
04/13/08 01:44
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
You need to reconnect everytime you enter a new page. If you store the connection data in, let's say a cookie or a session, you take a big risk that your clients will get to know the login data and abuse it.
I usually make a config.php where I put in all my global functions and external connections. Then include config.php in every file I will load, and call the database_connect function whenever I need it.


Click and join the 3dgs irc community!
Room: #3dgs
Re: PHP help [Re: Joozey] #202062
04/13/08 01:48
04/13/08 01:48
Joined: Jan 2008
Posts: 1,580
Blade280891 Offline OP
Serious User
Blade280891  Offline OP
Serious User

Joined: Jan 2008
Posts: 1,580
Yer, but how can i save the data they enter.
Before anyone says in there database, the data they enter is there database infomation.
I need to save what they enter and be able to recall it.


My Avatar Randomness V2

"Someone get me to the doctor, and someone call the nurse
And someone buy me roses, and someone burned the church"
Re: PHP help [Re: Blade280891] #202063
04/13/08 01:53
04/13/08 01:53
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Uh, okay. Well after the client is done filling in the form, the formdata is transmitted to the server as soon as the user presses the submit button. You can gain this information by calling $_POST['name_of_formobject'] in the page that is loaded after pressing submit.


Click and join the 3dgs irc community!
Room: #3dgs
Re: PHP help [Re: Joozey] #202064
04/13/08 01:57
04/13/08 01:57
Joined: Jan 2008
Posts: 1,580
Blade280891 Offline OP
Serious User
Blade280891  Offline OP
Serious User

Joined: Jan 2008
Posts: 1,580
but this will only work one, time after the form is entered, i need to save the data they enter and call it at a later time.

This is my code:
 PHP:
$dbhost = ($dbhost); $dbuser = ($dbuser); $dbpass = ($dbpass); $dbname = ($dbname); $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql. Please go back and check your details. '); if($conn) echo("Connected to '$dbname' database<br> With these details:<br> Database Host: '$dbhost' <br> Database Username: '$dbuser' <br> Database Password: '$dbpass' <br>"); mysql_select_db($dbname)or die(mysql_error()); $dbhost= $_POST['dbhost']; $dbuser= $_POST['dbuser']; $dbpass= $_POST['dbpass']; $dbname= $_POST['dbname']; $sql_db = "CREATE TABLE rgb_dbinfo( user_id int(10) AUTO_INCREMENT NOT NULL PRIMARY KEY, dbhost varchar(100) NOT NULL, dbuser varchar(100) NOT NULL, dbpass varchar(100) NOT NULL, dbname varchar(100) NOT NULL )"; mysql_query($sql_db); ?> <html> <body> <form action="adminsetup.php" method="post"> <input type="submit" value="Continue" name="continue"> </form> </body> </html> <?php $query = "INSERT INTO rgb_dbinfo (dbhost,dbuser,dbpass,dbname) VALUES('$dbhost','$dbuser','$dbpass','$dbname')"; mysql_query($query) or die(mysql_error()); mysql_close();

and this is the database connecter
 PHP:

<?php
include 'databaseinfo.php';
/*This is the information to use to connect to the MYSql database */
$dbhost = '$dbhost';
$dbuser = '$dbuser';
$dbpass = '$dbpass';
$dbname = '$dbname';
/*If the connection could not be made show this message*/

?>



the connecter needs to call data from somewhere to connect, i want the data that is called, to be what the user has entered. But this data that they entered must be saved somewhere.

Last edited by Blade28081991; 04/13/08 02:01.

My Avatar Randomness V2

"Someone get me to the doctor, and someone call the nurse
And someone buy me roses, and someone burned the church"
Re: PHP help [Re: Blade280891] #202065
04/13/08 02:11
04/13/08 02:11
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
After you compared the login details the clients filled into the form with the account details in your database, and they match, write a session that stores the user id. Every new page they enter you can see if $_SESSION['user_id'] is empty or not. If it is empty, then let them redirect back to your homepage. If not, then the user is apparantly logged in and he may proceed.

Make sure you put everyones password as md5, sha or whatever hash algorithm in the database, and never as the original password. Just compare the encrypted password in the database with the password you get from the form after you encrypted it as well, and you know if there is a match.

I can't guarantee that this is the most safe method in the big meany world of the internut, but it should work fine. For more secure methods, there is plenty of information to find with googly.


Click and join the 3dgs irc community!
Room: #3dgs
Re: PHP help [Re: Joozey] #202066
04/13/08 02:15
04/13/08 02:15
Joined: Jan 2008
Posts: 1,580
Blade280891 Offline OP
Serious User
Blade280891  Offline OP
Serious User

Joined: Jan 2008
Posts: 1,580
Soz, but this isn't about user login to a website, this is about storing mysql database information and then using that information to connect to the database.
Basically is there any way to store inputed data and then get the data?


My Avatar Randomness V2

"Someone get me to the doctor, and someone call the nurse
And someone buy me roses, and someone burned the church"
Re: PHP help [Re: Blade280891] #202067
04/13/08 02:29
04/13/08 02:29
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Using a $_SESSION or making a cookie. But you shouldn't just store your database connection details into a session (and certainly not into a cookie), that is kinda insecure.

Rather design something like this (Okay, some pseudo code!):

For registration of new users:
 Code:
<!--Registration page!-->
<form>
  <input id=name>
  <input id=password>
</form> <!--After submit, link to input-user-page!-->
 Code:
//input-user-page
$name = $_POST['name']
$pass = $_POST['password']

query_insertuser($name, $pass) //make some mysql code from this


For login existing users:
 Code:
<form>
  <input id=name>
  <input id=password>
</form> <!--After submit, link to user-validation-page!-->
 Code:
//User-validation-page
$name = $_POST['name']
$pass = $_POST['pass']

$result = query_validation($name, md5( $pass )) //compare name and password with those in the database (this is all psuedo code!!)
if (result == true) { //user validated! (of course, this is pseudo code too)
  $_SESSION['userId'] = $name //We'll keep track of this user now
}

else {
  header("Location: index.php") //no validation, be gone!
}


Every new page should call this code:
 Code:
//function to be called in every page that requires login
if (!empty($_SESSION['userId')) { //user exists
  echo("Let's drink a beer mate!");
}
else {
  header("Location: index.php") //not validated, be gone!
}


Last edited by Joozey; 04/13/08 02:33. Reason: few little errors

Click and join the 3dgs irc community!
Room: #3dgs
Re: PHP help [Re: Joozey] #202069
04/13/08 02:32
04/13/08 02:32
Joined: Jan 2008
Posts: 1,580
Blade280891 Offline OP
Serious User
Blade280891  Offline OP
Serious User

Joined: Jan 2008
Posts: 1,580
What about, do u no how to store data in a text file and call the data,
using PHP?


My Avatar Randomness V2

"Someone get me to the doctor, and someone call the nurse
And someone buy me roses, and someone burned the church"
Re: PHP help [Re: Blade280891] #202070
04/13/08 02:33
04/13/08 02:33
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands

Last edited by Joozey; 04/13/08 02:35.

Click and join the 3dgs irc community!
Room: #3dgs
Page 1 of 5 1 2 3 4 5

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1