Jump to content

Recommended Posts

Posted

If you don't know what SQL injection is, all you need to know about it as it relates to your server's website is that a malicious user could use your own php scripts to modify your server's database or potentially even take full control of your MySQL database.

 

With the following scripts you can have better security..

 

(One word of caution: SQL Injection may still be possible if a user finds a way to pass a "change charset" command to your MySQL database. I can't think of a way to do that through any of these scripts, so they *should* be safe.)

 

Account registration:

 

PHP code:

<?php 
//set host, username and password for MySQL 
$dbhost = "localhost"; 
$dbuser = "YOURMYSQLUSERNAME"; 
$dbpass = "YOURMYSQLPASSWORD"; 
  
//connect to MySQL or return an error 
$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") 
or die('Could not connect: ' . mysql_error()); 
  
//set database name 
$dbname = "l2jdb"; 
  
//select database or return an error 
$dbselect = mysql_select_db("$dbname")  
or die ('Could not select database'); 
  
//get username and password info from the form, protecting against SQL injection 
$pass = mysql_real_escape_string($_POST["pass"]); 
$confirm = mysql_real_escape_string($_POST["confirm"]); 
$user = mysql_real_escape_string($_POST["name"]); 
  
//validate user input 
if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$user)) { 
die ('Error: Usernames can only contain alphanumeric characters and must be between 5 and 20 characters in length.'); 
} 
  
if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$pass)) { 
die ('Error: Passwords can only contain alphanumeric characters and must be between 5 and 20 characters in length.'); 
} 
  
if($pass != $confirm) { 
die ('Error: Passwords do not match.'); 
} 
  
//make sure user doesn't already exist and if it doesn't, add new record to the database 
$result = mysql_query("SELECT login FROM accounts WHERE login='$user'"); 
  
if(mysql_num_rows($result)>0) { 
die ('Error: Username already exists.'); 
}else{ 
mysql_query("INSERT INTO accounts (login, password, access_level) VALUES ('".$_POST['name']."', '".base64_encode(pack('H*', sha1($_POST['pass'])))."', 0)") 
or die ('Error: ' . mysql_error()); 
} 
  
//report successful registration 
echo "Account created successfully."; 
  
//close MySQL connection 
mysql_close(); 
  
?>

 

Save this as acc.php and then use the following html to add the account registration form to your webpage

 

<form action="acc.php" method=post>
UserID: <input type="text" name="name" size=20><br><br>
Password: <input type="password" name="pass" size=20><br><br>
Confirm Password: <input type="password" name="confirm" size=20><br><br>
<input type=submit name="submit" value="Create"></form>

 

The script has built in protection against SQL injection and also forces the user to submit a username and password that are between 5 and 20 characters in length, and limits them to only alphanumeric characters.

 

Password reset scripts are even more subject to SQL injection exploits, so here is a (to the best of my knowledge) secure password reset script.

 

<?php 
  
//set host, username and password for MySQL 
$dbhost = "localhost"; 
$dbuser = "YOURMYSQLUSERNAME"; 
$dbpass = "YOURMYSQLPASSWORD"; 
  
//connect to MySQL or return an error 
$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") 
or die('Could not connect: ' . mysql_error()); 
  
//set database name 
$dbname = "l2jdb"; 
  
//select database or return an error 
$dbselect = mysql_select_db("$dbname")  
or die ('Could not select database'); 
  
//get username and password info from the form, protecting against SQL injection 
$user = mysql_real_escape_string($_POST["name"]); 
$currentpass = mysql_real_escape_string($_POST["currentpass"]); 
$newpass = mysql_real_escape_string($_POST["newpass"]); 
$confirm = mysql_real_escape_string($_POST["confirm"]); 
  
//username and password should already be valid and newpass and confirm should match or this script will die 
//so just validate the newpass and then check to see if newpass and confirm are the same 
if(!preg_match('/^[a-zA-Z0-9]{5,20}$/',$newpass)) { 
die ('Error: Passwords can only contain alphanumeric characters and must be between 5 and 20 characters in length.'); 
} 
  
if($newpass != $confirm) { 
die ('Error: New passwords do not match.'); 
} 
  
//encrypt the passwords 
$currentpass = base64_encode(pack('H*', sha1($currentpass))); 
$newpass = base64_encode(pack('H*', sha1($newpass))); 
  
//if the user input passed all the checks, make sure the account exists and then update the password 
$result = mysql_query("SELECT login,password FROM accounts WHERE login='$user' AND password='$currentpass'"); 
  
if(mysql_num_rows($result)>0) { 
mysql_query("UPDATE accounts SET password='$newpass' WHERE login='$user' AND password='$currentpass'"); 
echo "Password succesfully updated.";  
}else{ 
die ('Error: Account does not exist or password is incorrect.'); 
} 
  
//close MySQL connection 
mysql_close(); 
  
?>

 

Save the preceding as changepass.php and use the following HTML to insert a change password form into your website.

 

<form action="changepass.php" method=post> UserID:<input type="text" name="name" size=20><br><br> Password: <input type="password" name="currentpass" size=20><br><br> New password: <input type="password" name="newpass" size=20><br><br> Confirm password:<input type="password" name="confirm" size=20><br><br> <input type=submit name="submit" value="Update Password"> 

 

This script uses the same protection as the registration script, and should be safe against all the SQL injection exploits that I can come up with.

 

Server status scripts don't take any input from the user, and thus are not susceptible to SQL injection, but here is a server status script that is tested and working, and as a bonus will use graphics to display your server status.

 

<?php 
  
//set server, port and timeout information 
$server = "localhost"; 
$portg = "7777"; 
$portl = "2106"; 
$timeout = "1"; 

//try to open a connection to the game and login server  
$game = @fsockopen("$server", $portg, $errno, $errstr, $timeout); 
$login = @fsockopen("$server", $portl, $errno, $errstr, $timeout); 
  
//let us know if the servers are up or not  
echo $game ? "<img src=\"gameonline.jpg\">" : "<img src=\"gameoffline.jpg\">"; 
echo $login ? "<img src=\"loginonline.jpg\">" : "<img src=\"loginoffline.jpg\">"; 
  
  
?>

 

All you have to do with this one is create a few graphics and insert the preceding php directly into your HTML whever you want the server status displayed. If the script isn't self-explanatory, the graphics you need to create are gameonline.jpg, gameoffline.jpg, loginonline.jpg and loginoffline.jpg.

 

And last but not least, here is a little script that will display the number of users currently online as a graphic on your webpage.

 

<?php 
  
//set host, username and password for MySQL 
$dbhost = "localhost"; 
$dbuser = "YOURMYSQLUSERNAME"; 
$dbpass = "YOURMYSQLPASSWORD"; 
  
//connect to MySQL or return an error 
$conn = mysql_connect("$dbhost", "$dbuser", "$dbpass") 
or die('Could not connect: ' . mysql_error()); 
  
//set database name 
$dbname = "l2jdb"; 
  
//select database or return an error 
$dbselect = mysql_select_db("$dbname") or die ('Could not select database'); 
  
//select all records from the characters table where that character is currently online 
$chars = mysql_query("SELECT online FROM characters where online='1'") or die ('Query failed: ' . mysql_error()); 
  
//count how many online characters there are 
$rows = mysql_num_rows($chars); 
  
//convert the number of online characters to a string 
$count =(string)$rows; 
  
//convert each digit in the string to a graphic 
for ($i=0; $i < strlen($count); $i++) { echo('<img src="' . $count{$i} . '.jpg">'); }  
  
//close MySQL connection 
mysql_close(); 
  
?>

 

Save this as onlineplayers.php and then insert the following code into your html where you want to display the number of online players.

 

<?php 
include 'onlineplayers.php'; 
?>

 

Now all you need to do is create a graphic for each digit and save them as 0.jpg, 1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg, 6.jpg, 7.jpg, 8.jpg, and 9.jpg. The script will find the number of players currently online and use the graphics you created to diplay the number on your page.

 

 

credits to:threadreaper

  • 1 month later...
Posted

All the PHP and HTML codes are [C O D E D]

 

do it the next time you will release an other guide with scripts.

 

bye.

  • 3 weeks later...
  • 4 months later...
  • 2 months later...
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Dark mode should be on by default instead. Please fix the flickering on refresh.
    • Hello, We’re preparing to launch something new on L2network.eu… ⚠️   A premium SponsorAuction system is coming soon — introducing a new way to gain maximum visibility on the platform.     👉 Important: Your standard fixed sponsor spots are NOT going anywhere. They will remain available as always.   🔥 So what’s new? We’re adding a limited auction-based premium spot that will stand above everything else. This special placement will: Appear above all servers in the toplist Be visible on every page of the platform Deliver the highest possible exposure   💥 And here’s the catch: Only a very limited number of these premium spots will exist Access will be decided through competitive bidding This means: 👉 The most visible position on L2Network will no longer be bought — it will be won. ⏳ The first auction is opening soon. Early bidders will have the advantage. Get ready — because once it starts, competition will be intense. ------------------------------------------------------------------------------------ We've spent the last week rebuilding how your server pages work behind the scenes. Every server listed on L2Network now has a smarter, more discoverable detail page — and it's already pulling in better Google rankings. Here's what's new and how it helps you get more votes and players. ⭐ Star Ratings in Google Search Your server page now tells Google exactly how players have rated you. When someone searches for your server (or related Lineage 2 keywords), Google can now display golden stars next to your listing in the search results. REAL Stats- Live stats 📖 Auto-Generated Server Summary At the top of every detail page, there's now a clean intro paragraph describing your server in plain language — chronicle, rates, age, rating, and a call-to-action. It's built automatically from your existing server data, so you don't have to write anything. Players landing on your page see what your server is about within 2 seconds, instead of having to dig through tables.   ❓ FAQ Section on Every Page Every server page now has a Frequently Asked Questions block answering things like: What chronicle is this server? What are the rates? Is it L2OFF or L2J? When did it launch? How is it rated by players? These are auto-generated from your server settings — no work for you. Bonus: Google sometimes shows these directly in search results as expandable answers, giving you even more screen space in SERPs.   📈 What You Can Expect Over the next 2-4 weeks as Google re-crawls every detail page: What    Expected change Star ratings showing in Google searches    Servers with 5+ votes get ★ stars Click-through rate from search results    📈 Up to 35% higher Long-tail keyword rankings (e.g. "interlude x100", "high five pvp")    📈 Better positions Mobile click rate    📈 Improved with new layout
    • Thank you very much. It would also be good if you looked into this issue. UnknownSoldier has been manipulating me to make me look bad. He deleted all the evidence I uploaded and left all the insults against me. You'll also see that on April 26th, he reopened the thread and then locked it again just so his friend from Argentina could post: links down :l XD   In the thread: https://maxcheaters.com/topic/253997-sourceservercliente-l2devs-files-l2devscom/page/2/ They do this so they can later tell people that I deleted the links because it was a lie, and so on. Realize that all the damage you're causing is related to this same person. Regards and thank you very much! 🙂 PS: I would like UnknownSoldier to publish the evidence for why he has repeatedly called me a SCAMMER and explain why he also says that to other people. This person is using forum privileges to smear and discredit those who don't work with him. I WANT ALL THE EVIDENCE OF WHAT HE'S SAYING.  
    • Theres a lot of drama going on about Guytis scamming people. I want real, solid proof showing that he scammed anyone attach everything you have.   About reputation: we’re all adults here, yet some are acting like kids fighting over pixels. Think before spreading rumors. False claims don’t make you look better they make you look worse.   I’m waiting for actual evidence that he scammed any user. If there’s nothing to back it up, I’ll deal with it myself. Time’s running out this has been going on long enough.
    • I’ve read the whole topic about Baylee and Protojah. From what I can see, Baylee wanted to buy some htmls and they agreed on a price. Later, Baylee changed her mind and decided not to go through with it. The product wasn’t delivered because Baylee changed her mind. Even if she initially agreed to the price, to avoid confusion. if the files had been sent and payment not made, I would call it a scam. But since they weren’t sent, this isn’t a scam.   I want to stress that I try to be fair to everyone, no matter the situation.   Yeah, Protojah did put in time and effort, and that’s fine, but disagreements happen all the time, even in real life jobs, no matter what the work is. I’m going to lock this topic to avoid more drama. Please keep all personal issues in private messages. And before anyone says anything else I’m not taking sides. I don’t protect scammers and I ban them, but since this isn’t a scam, you both should resolve this situation in DMs.
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and 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..