Jump to content

Some help please


acoole

Recommended Posts

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!

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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');

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.