acoole Posted March 15, 2008 Share Posted March 15, 2008 Hey there, I want to make a login that reads a .ini file, so the username comes from - [myname].ini and the password comes from the "key" section of the .ini file. Here is the contents of the .ini file: Level=1 AdminLevel=0 DonateRank=0 UpgradePoints=0 ConnectedTime=0 Registered=1 Sex=1 Age=25 Origin=2 CK=0 Muted=0 Respect=0 Money=25900 Bank=50000 Crimes=0 Kills=0 Deaths=1 Arrested=0 WantedDeaths=0 Phonebook=0 LottoNr=0 Fishes=0 BiggestFish=0 Job=0 Paycheck=1175 HeadValue=0 Jailed=0 JailTime=0 Materials=0 Drugs=0 Leader=0 Member=0 FMember=255 Rank=0 Char=0 ContractTime=0 DetSkill=0 SexSkill=0 BoxSkill=0 LawSkill=0 MechSkill=0 JackSkill=0 CarSkill=0 NewsSkill=0 DrugsSkill=0 CookSkill=0 FishSkill=0 pSHealth=0.0 pHealth=48.0 Int=0 Local=255 Team=3 Model=264 PhoneNr=8284 House=255 Bizz=255 Pos_x=246.6 Pos_y=-1161.9 Pos_z=1029.6 CarLic=0 FlyLic=0 BoatLic=0 FishLic=0 GunLic=0 Gun1=0 Gun2=0 Gun3=0 Gun4=0 Ammo1=0 Ammo2=0 Ammo3=0 Ammo4=0 CarTime=0 PayDay=4 PayDayHad=0 CDPlayer=0 Wins=0 Loses=0 AlcoholPerk=0 DrugPerk=0 MiserPerk=0 PainPerk=0 TraderPerk=0 Tutorial=1 Mission=0 Warnings=0 Adjustable=1 Fuel=0 Married=0 MarriedTo=No-one Can somebody please give me an example of a login script like this? Thanks! Quote Link to comment Share on other sites More sharing options...
derrick1123 Posted March 15, 2008 Share Posted March 15, 2008 Did you start with any code besides the .ini? Quote Link to comment Share on other sites More sharing options...
acoole Posted March 15, 2008 Author Share Posted March 15, 2008 What do you mean? This is the code that creates the .ini file: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Rounded Green</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <div id="wrapper"> <div id="header"> <div id="navigation"> <ul> <li><a href="#" class="active">Register</a></li> <li><a href="http://cp.sf-rp.com/login.php">Control Panel</a></li> <li><a href="http://sf-rp.com/forums/">Forums</a></li> </ul> </div> <h1>SF-RP <a href="index.html">Control Panel</a> <sup>Beta 2</sup></h1> </div> <div id="content"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Samp Servers</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link rel="stylesheet" href="style.css"> </head> <body> <div align="center"> <table width="990" border="0" cellpadding="0" cellspacing="0"> <tr><td><img id="design006_01" src="images/design006_01.gif" width="990" height="144" alt="" /></td></tr> <tr><td background="images/design006_02.gif" style="padding-left:20px; padding-right:20px;"> <table width="100%"> <tr> <td width="2%" class="nav"> <!-- ENDE --> </td> <td width="98%" class="cont"> <!-- INHALT --> </table> </table> </div> <h1>SF-RP Control Panel :: Registration Complete</h1> <?php $path = "/home/sfrp/sa-mp/scriptfiles/"; // this will prevent XSS echo "<h1>Congratulations!</h1> - You're registered on SF-RP(78.129.168.26:9999)"; echo "Congratulations on completing registeration to the best roleplay server in the world. Please feel free to visit our" echo "Control Panel located by click "Control Panel" above!" echo "If there is an error message below, this means an error was found during the set-up process" echo "If there is an error below try to fix it by re-signing up with a different name" echo "If it occurs continuously then please contact us at http://sf-rp.com/forums" // replace $_SESSION['username'] will the variable that holds your user name $file = fopen($path.$_POST["name"].".ini","a+"); if (file_exists($file)) { echo "Sorry, that name is already registered on SF-RP! "; } else { $text = "Key=" . $_POST["age"]; $text .= " Level=1 AdminLevel=0 DonateRank=0 UpgradePoints=0 ConnectedTime=0 Registered=1 Sex=1 Age=25 Origin=2 CK=0 Muted=0 Respect=0 Money=25900 Bank=50000 Crimes=0 Kills=0 Deaths=1 Arrested=0 WantedDeaths=0 Phonebook=0 LottoNr=0 Fishes=0 BiggestFish=0 Job=0 Paycheck=1175 HeadValue=0 Jailed=0 JailTime=0 Materials=0 Drugs=0 Leader=0 Member=0 FMember=255 Rank=0 Char=0 ContractTime=0 DetSkill=0 SexSkill=0 BoxSkill=0 LawSkill=0 MechSkill=0 JackSkill=0 CarSkill=0 NewsSkill=0 DrugsSkill=0 CookSkill=0 FishSkill=0 pSHealth=0.0 pHealth=48.0 Int=0 Local=255 Team=3 Model=264 PhoneNr=8284 House=255 Bizz=255 Pos_x=246.6 Pos_y=-1161.9 Pos_z=1029.6 CarLic=0 FlyLic=0 BoatLic=0 FishLic=0 GunLic=0 Gun1=0 Gun2=0 Gun3=0 Gun4=0 Ammo1=0 Ammo2=0 Ammo3=0 Ammo4=0 CarTime=0 PayDay=4 PayDayHad=0 CDPlayer=0 Wins=0 Loses=0 AlcoholPerk=0 DrugPerk=0 MiserPerk=0 PainPerk=0 TraderPerk=0 Tutorial=1 Mission=0 Warnings=0 Adjustable=1 Fuel=0 Married=0 MarriedTo=No-one "; } // write contents fwrite($file,$text); // close the file fclose($file); ?> <hr> <p><br></p> <!-- ENDE --> <table> <tr><td background="images/design006_03.gif" height="69"> <div align="center"> </div> </td> </tr> </body> <p>SF-RP Thanks it's many helpers, please visit the forums for a full list of credits.</p> </div> <div id="footer"><span class="main"><!--This theme is free for distriubtion, so long as link to openwebdesing.org and dubaiapartments.biz stay on the theme--> SF-RP Control Panel Script Developed by Soleinen Haler: Last Update was made at: 9 AM 15 March 2008 by Admin: Soleinen</span></div> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
acoole Posted March 15, 2008 Author Share Posted March 15, 2008 Nobody can help? Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted March 15, 2008 Share Posted March 15, 2008 Get the ini manipulation class from here: http://www.phpclasses.org/browse/package/789.html Then you could write: <?php require 'ini.class.php'; $ini = new ini; $ini->parse_constants = FALSE; $userdata = $ini->read_ini('settings.ini', TRUE); echo $userdata['Password']; ?> Quote Link to comment Share on other sites More sharing options...
acoole Posted March 15, 2008 Author Share Posted March 15, 2008 err.. Can you explain a bit? Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted March 15, 2008 Share Posted March 15, 2008 You said you wanted a login script which would use .ini file to store login information, right? I provided you with method how to obtain the data from .ini file, you must write the login script yourself. Or aren't you able to? Quote Link to comment Share on other sites More sharing options...
acoole Posted March 15, 2008 Author Share Posted March 15, 2008 Well.. that would read my current data? And no, i'm really not able to write it fully myself, I can probally finish it off if somebody gave me an example. Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted March 15, 2008 Share Posted March 15, 2008 Oh cmon, use Google next time! Is it that hard to type "php login script" and hit Search!? Anyway, here we go: HTML file: In progress... Quote Link to comment Share on other sites More sharing options...
ChompGator Posted March 15, 2008 Share Posted March 15, 2008 Yep, that is about the simplest login script you can make, are you wanting to store the user/name and password using sessions, and cookies? Or are you just looking for a real simple login Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted March 15, 2008 Share Posted March 15, 2008 Oh cmon, use Google next time! Is it that hard to type "php login script" and hit Search!? Anyway, here we go: form html: <form name="form1" method="post" action="checklogin.php"> Username: <input name="myusername" type="text" id="myusername"> Password: <input name="mypassword" type="text" id="mypassword"> <input type="submit" name="Submit" value="Login"> </form> checklogin.php <?php $myusername = $_POST['myusername']; $mypassword=$_POST['mypassword']; if (!file_exists($myusername . '.ini')): die('Error - User isn\'t registered yet.'); endif; require 'ini.class.php'; $ini = new ini; $ini->parse_constants = FALSE; $userdata = $ini->read_ini($myusername . '.ini', TRUE); $userpass = $userdata['password']; if($userpass == $mypassword): // Register $myusername, $mypassword and redirect to file "login_success.php" @session_start(); $_SESSION['user'] = $myusername; $_SESSION['pass'] = $mypassword; header("location:login_success.php"); else: die('Error - Wrong username or password.'); endif; ?> That's practically it, now if you want to logout, you use this: session_start(); unset($_SESSION['user']); header('location: somewhere.html'); Quote Link to comment Share on other sites More sharing options...
acoole Posted March 15, 2008 Author Share Posted March 15, 2008 Thankss soo much, but I want it to read from /home/sfrp/sa-mp/scriptfiles/ How do I do that(on this script) <?php $myusername = $_POST['myusername']; $mypassword=$_POST['mypassword']; if (!file_exists($myusername . '.ini')): die('Error - User isn\'t registered yet.'); endif; require 'ini.class.php'; $ini = new ini; $ini->parse_constants = FALSE; $userdata = $ini->read_ini($myusername . '.ini', TRUE); $userpass = $userdata['password']; if($userpass == $mypassword): // Register $myusername, $mypassword and redirect to file "login_success.php" @session_start(); $_SESSION['user'] = $myusername; $_SESSION['pass'] = $mypassword; header("location:login_success.php"); else: die('Error - Wrong username or password.'); endif; ?> Quote Link to comment Share on other sites More sharing options...
acoole Posted March 15, 2008 Author Share Posted March 15, 2008 I want it to READ the .ini file from /home/sfrp/sa-mp/scriptfiles/ <?php $myusername = $_POST['myusername']; $mypassword=$_POST['mypassword']; if (!file_exists($myusername . '.ini')): die('Error - User isn\'t registered yet.'); endif; require 'ini.class.php'; $ini = new ini; $ini->parse_constants = FALSE; $userdata = $ini->read_ini($myusername . '.ini', TRUE); $userpass = $userdata['password']; if($userpass == $mypassword): // Register $myusername, $mypassword and redirect to file "login_success.php" @session_start(); $_SESSION['user'] = $myusername; $_SESSION['pass'] = $mypassword; header("location:login_success.php"); else: die('Error - Wrong username or password.'); endif; ?> Thanks in advanced Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 This is a PHP help forum, not a 'write a program for me' forum. $userdata = $ini->read_ini('path/to/your/file' . $myusername . '.ini', TRUE); Also, please do not double post Quote Link to comment Share on other sites More sharing options...
acoole Posted March 15, 2008 Author Share Posted March 15, 2008 Yes, I am aware it's not a write program for me forum. I just suck at PHP :'( Especially at this whole reading .ini files things. Can someone give me a link to a website where I can learn about reading .ini files/writing etc.. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 15, 2008 Share Posted March 15, 2008 Well, learning the language basics is your best first step. Learn to walk before you run... But here's a couple functions that would come in helpful: http://php.net/file_get_contents http://php.net/file http://php.net/file_put_contents Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.