Website Php Scripts for SQL 2005

Status
Not open for further replies.
Joined
Jul 8, 2007
Messages
1,627
Reaction score
1,613
Since i struggled to find the php scripts for SQL 2005 that were working....
ill release them here...Credits to those who made them and thanks for sharing them :)



(YOU WILL NEED TO EDIT THE PASSWORDS IN THESE SCRIPTS TO GET THEM TO CONNECTO TO YOUR SERVER!)




CastleOwner.php (Who owns the Castle)

Code:
<?php
  $config = array(
    'db_username' => 'sa', // database username
    'db_password' => 'YOURPASSHERE',   // database password
    'db_dsn'      => 'kal_db',   // system DSN to the database
    'debug'       => false,
);



        $conn = odbc_connect($config['db_dsn'],
                             $config['db_username'],
                             $config['db_password']);

                             
            $guild_query = odbc_exec($conn,"SELECT [GID] FROM GuildCastle WHERE CID = 1");                 

$guild2 = odbc_fetch_array($guild_query);
$guildGID = $guild2[0];

$guild_query = odbc_exec($conn,"SELECT [Name] FROM Guild WHERE GID = '".$guildGID."'");
$guild2 = odbc_fetch_array($guild_query);
$guild = $guild2[0];

if($guild)
     echo "<p>Castle Owner: $guild</p>";
else
     echo "<p>Castle Owner: None</p>";
?>


MoneyRanking.php (Which players have the most money)

Code:
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="Shortcut Icon" href="favicon.ico">

 <?php
// table style
DEFINE("STYLE", "font: 12px Verdana, Geneva, sans-serif; color: black; text-align; center;");
  $config = array(
    'db_username' => 'sa', // database username
    'db_password' => 'YOURPASSWORDHERE',   // database password
    'db_dsn'      => 'kal_db',   // system DSN to the database
    'debug'       => false,
);



        $conn = odbc_connect($config['db_dsn'],
                             $config['db_username'],
                             $config['db_password']);
  
  $top = 1;
  $plist = "SELECT TOP 100 Player.Name, Player.Level, Player.Specialty, Item.Num, Player.Class
    FROM Player
    LEFT JOIN Item
    ON Player.PID=Item.PID
        WHERE
            [Index] = 31 
        ORDER BY
            Item.Num DESC";
  $pplist = odbc_exec($conn,$plist);
  
    echo '<br><br><br>';
    echo '<center><table width="400px" style="STYLE">';
    echo '<tr style="text-align: center">
    <td width="100px"><b>Rank</b></td>
    <td width="100px"><b>Name</b></td>
    <td width="100px"><b>Gold</b></td></tr>';

    while($r = odbc_fetch_array($pplist)){
        echo '<tr style="text-align: center"><td>'.$top.'</td><td>'.$r['Name'].'</td><td>'.$r['Num'].'</td></tr>';
        $top++;
    }
    
    echo '</table>';


Online.php (shows how many players are online - updates once every 30 minutes)

Code:
 <?php
  $config = array(
    'db_username' => 'sa', // database username
    'db_password' => 'YOURPASSWORDHERE',   // database password
    'db_dsn'      => 'kal_db',   // system DSN to the database
    'debug'       => false,           
);


        $conn = odbc_connect($config['db_dsn'],
                             $config['db_username'],
                             $config['db_password']);


$st = "SELECT TotalUser FROM [Statistics]";
$st2 = odbc_exec($conn,$st);
while($r = odbc_fetch_array($st2)){

$on = $r['TotalUser'];
};

if(empty($on))
{
        echo '<font color="red">Players Online <b>0</b></font><br>';
}

if(!empty($on)){
        echo "Players Online : <b>$on</b><br>";
}
?>


ServerStatus.php (Shows if the server is online or offline ... you will need to make 2 image files - online.png and offline.png and put them in the same folder as this script)

Code:
<html>
<style type="text/css">
body {
    margin: 0px;
}
</style>
<header></header>

<body>
<script>
<!--

/*
Auto Refresh Page with Time script
By JavaScript Kit (javascriptkit.com)
Over 200+ free scripts here!
*/

//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="0:5"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{ 
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
//-->
</script>
    <?php 
      $fp = @fsockopen ("127.0.0.1", 30001, $errno, $errstr, 10); // 10 = sec. timeout 
      if (!$fp) { 
        echo "<img src=\"offline.png\" width=\"158\" height=\"128\" alt=\"ServerOffline\" longdesc=\"offliine.png\" />"; 
      }
      else
      { 
        echo "<img src=\"online.png\" width=\"158\" height=\"128\" alt=\"ServerOnline\" longdesc=\"online.png\" />"; 
      } 
      @fclose($fp); 
    ?>
</body>
    </html>


THE RANKINGS
REGISTER
AND TOP 3 PLAYERS can be downloaded from the attacthed files
 

Attachments

Hey and welcome back again we missed you:).
Could you make an register and change pw script with sn?:p thank you.
 
good job could you upload change password script w/o SN^^
PHP:
<?php

function encode($password)
{
    $EncTable = array('!'=>'95', '"'=>'88', '#'=>'9D', '$'=>'4C', '%'=>'F2', 
'&'=>'3E', '\''=>'BB', '('=>'C0', ')'=>'7F', '*'=>'18', '+'=>'70', 
','=>'A6', '-'=>'E2', '.'=>'EC', '/'=>'77',
                        '0'=>'2C', '1'=>'3A', '2'=>'4A', '3'=>'91', 
'4'=>'5D', '5'=>'7A', '6'=>'29', '7'=>'BC', '8'=>'6E', '9'=>'D4', ':'=>'40', 
';'=>'17', '<'=>'2E', '='=>'CB', '>'=>'72', '?'=>'9C',
                        '@'=>'A1', 'A'=>'FF', 'B'=>'F3', 'C'=>'F8', 
'D'=>'9B', 'E'=>'50', 'F'=>'51', 'G'=>'6D', 'H'=>'E9', 'I'=>'9A', 'J'=>'B8', 
'K'=>'84', 'L'=>'A8', 'M'=>'14', 'N'=>'38', 'O'=>'CE',
                        'P'=>'92', 'Q'=>'5C', 'R'=>'F5', 'S'=>'EE', 
'T'=>'B3', 'U'=>'89', 'V'=>'7B', 'W'=>'A2', 'X'=>'AD', 'Y'=>'71', 'Z'=>'E3', 
'['=>'D5', '\\'=>'BF', ']'=>'53', '^'=>'28', '_'=>'44',
                        '`'=>'33', 'a'=>'48', 'b'=>'DB', 'c'=>'FC', 
'd'=>'09', 'e'=>'1F', 'f'=>'94', 'g'=>'12', 'h'=>'73', 'i'=>'37', 'j'=>'82', 
'k'=>'81', 'l'=>'39', 'm'=>'C2', 'n'=>'8D', 'o'=>'7D',
                        'p'=>'08', 'q'=>'4F', 'r'=>'B0', 's'=>'FE', 
't'=>'79', 'u'=>'0B', 'v'=>'D6', 'w'=>'23', 'x'=>'7C', 'y'=>'4B', 'z'=>'8E', 
'{'=>'06', '|'=>'5A', '}'=>'CC', '~'=>'62');

    $Encode = "0x";

    for ($i = 0; $i < strlen($password); $i++)
        $Encode .= $EncTable[$password[$i]];

    return $Encode;
}

function decode($password)
{
    $DecTable = array('95'=>'!', '88'=>'"', '9D'=>'#', '4C'=>'$', 'F2'=>'%', 
'3E'=>'&', 'BB'=>'\'', 'C0'=>'(', '7F'=>')', '18'=>'*', '70'=>'+', 
'A6'=>',', 'E2'=>'-', 'EC'=>'.', '77'=>'/',
                        '2C'=>'0', '3A'=>'1', '4A'=>'2', '91'=>'3', 
'5D'=>'4', '7A'=>'5', '29'=>'6', 'BC'=>'7', '6E'=>'8', 'D4'=>'9', '40'=>':', 
'17'=>';', '2E'=>'<', 'CB'=>'=', '72'=>'>', '9C'=>'?',
                        'A1'=>'@', 'FF'=>'A', 'F3'=>'B', 'F8'=>'C', 
'9B'=>'D', '50'=>'E', '51'=>'F', '6D'=>'G', 'E9'=>'H', '9A'=>'I', 'B8'=>'J', 
'84'=>'K', 'A8'=>'L', '14'=>'M', '38'=>'N', 'CE'=>'O',
                        '92'=>'P', '5C'=>'Q', 'F5'=>'R', 'EE'=>'S', 
'B3'=>'T', '89'=>'U', '7B'=>'V', 'A2'=>'W', 'AD'=>'X', '71'=>'Y', 'E3'=>'Z', 
'D5'=>'[', 'BF'=>'\\', '53'=>']', '28'=>'^', '44'=>'_',
                        '33'=>'`', '48'=>'a', 'DB'=>'b', 'FC'=>'c', 
'09'=>'d', '1F'=>'e', '94'=>'f', '12'=>'g', '73'=>'h', '37'=>'i', '82'=>'j', 
'81'=>'k', '39'=>'l', 'C2'=>'m', '8D'=>'n', '7D'=>'o',
                        '08'=>'p', '4F'=>'q', 'B0'=>'r', 'FE'=>'s', 
'79'=>'t', '0B'=>'u', 'D6'=>'v', '23'=>'w', '7C'=>'x', '4B'=>'y', '8E'=>'z', 
'06'=>'{', '5A'=>'|', 'CC'=>'}', '62'=>'~');


    for ($i = 0; $i < strlen($password); $i++)
	{
		$Hex = sprintf("%02x", ord($password[$i]));
        $Decode .= $DecTable[strtoupper($Hex)];
	}

    return $Decode;
}
function auth($ID, $PWD)
{
	$connect = mssql_connect('127.0.0.1', 'SA', 'pass');
	$db = mssql_select_db('kal_auth', $connect);

	$q = mssql_query("SELECT [PWD] FROM Login WHERE [ID] = '$ID'", $connect);
	$r = mssql_fetch_array($q);
	$pwd = decode($r['PWD']);

	if($pwd == $PWD)
		return true;
	else
		return false;
}

function change($ID, $PWD)
{
	$connect = mssql_connect('127.0.0.1', 'SA', 'pass');
	$db = mssql_select_db('kal_auth', $connect);

	$EPWD = encode($PWD);

	mssql_query("UPDATE [Login] SET [PWD] = ".$EPWD." WHERE [ID] = '{$ID}'", 
$connect);
}

if( isset($_POST['change']) )
{
	$id = $_POST['id'];
	$oldpwd = $_POST['oldpwd'];
	$pwd1 = $_POST['pwd1'];
	$pwd2 = $_POST['pwd2'];

	if($id == "")
	{
		echo "Please type in your id!";
		return;
	}

	if($oldpwd == "")
	{
		echo "Please type in your password!";
		return;
	}

	if($pwd1 == "")
	{
		echo "Please type in your new password!";
		return;
	}

	if(auth($id, $oldpwd))
	{
		if($pwd1 != $pwd2)
		{
			echo "Passwords do not match...";
		}
		else
		{
			change($id, $pwd2);
			echo "<font color=\"Red\"> Password changed successfully.. </font>";
		}
	}
	else
	{
		echo "Wrong password...";
	}


	return;
}

?>

<p><font color="Red"></font>
</p>
<form method="POST" action="">

<label></label>
<p>
<label></label>

<table width="350" border="0" align="center" cellpadding="0" 
cellspacing="0">
  <tr>
    <td colspan="2"> </td>
  </tr>
  <tr>
    <td>ID:</td>
    <td><div align="center">
      <input name="id" type="text" id="id" />
    </div></td>
  </tr>
  <tr>
    <td><label>Old Password:</label></td>
    <td><div align="center">
      <input name="oldpwd" type="password" id="oldpwd" />
    </div></td>
  </tr>
  <tr>
    <td>New Password: </td>
    <td><div align="center">
      <input name="pwd1" type="password" id="pwd1" />
    </div></td>
  </tr>
  <tr>
    <td> </td>
    <td><div align="center">
      <input name="pwd2" type="password" id="pwd2" />
    </div></td>
  </tr>
  <tr>
    <td height="50" colspan="2"><div align="center">
      <input type="submit" name="change" value="Change Pass..." />
    </div></td>
  </tr>
</table>
<p> </p>
</form>
 
thx bird but i got problem when i change password i got that

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'Scode'., SQL state S0022 in SQLExecDirect in C:\xampp\htdocs\ChangePassword\index.php on line 145

Warning: odbc_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ChangePassword\index.php on line 148
Account has no Secret Number! Changing password not possible
 
thx bird but i got problem when i change password i got that

Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'Scode'., SQL state S0022 in SQLExecDirect in C:\xampp\htdocs\ChangePassword\index.php on line 145

Warning: odbc_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\ChangePassword\index.php on line 148
Account has no Secret Number! Changing password not possible

change the index.php with this
PHP:
<?php
	//Set banned IP 
	$banned  = '123.123.123.123'; 
	//get user IP address 
	$userip = $_SERVER['REMOTE_ADDR']; 

	//check for banned IP address 
	if($userip == $banned){  
		echo "<center><BR>Get **** Off! You are Banned!</center>"; 
	exit();  
	} 
	/**
	* Registration handling
	*
	* @author     Claus Jّrgensen <[email protected]>
	* @category   Common
	* @package    Kalonline Registration
	* @copyright  Copyright (c) 2006 Claus Jّrgensen (http://dragons-lair.org)
	* @license    MIT License
	*/

	include 'Password.php'; // password class
	include 'Captcha.php';  // captcha class

	session_start(); // required for captcha to work

	// Anti-SQL Injection 
	function check_inject() 
	{ 
		$badchars = array(";", "'", " \ ", "DROP", "SELECT", "drop", "select","DELETE","delete"); 

		foreach($_POST as $value) 
		{ 
			$value = clean_variable($value);

			if(in_array($value, $badchars)) 
			{ 
				die("SQL Injection Detected - Make sure only to use letters and numbers!\n<br />\nIP: ".$_SERVER['REMOTE_ADDR']);
			} 
			else 
			{ 
				$check = preg_split("//", $value, -1, PREG_SPLIT_OFFSET_CAPTURE);
				foreach($check as $char) 
				{ 
					if(in_array($char, $badchars)) 
					{ 
						die("SQL Injection Detected - Make sure only to use letters and numbers!\n<br />\nIP: ".$_SERVER['REMOTE_ADDR']); 
					} 
				} 
			} 
		} 

		
		#start a check for SQL injections.
		#this is kinda nub here, you can make it better by just escaping stings and what not.
		if(strstr($v, "'") || strstr($v, '"') || strstr($v, "\\") || strstr($v, "/"))
		{
		#if we detect an injection, stop the script.
			die("Injection Detected");
		}
		
	} 


	// configuration
	$config = array(
					'db_username' => 'sa', // database username
					'db_password' => '******',   // database password
					
					'template'    => 'registration.tpl',  // registration template path/filename
					'debug'       => false,               // show SQL errors if true
					);

	// HTML error
	define('UI_ERROR','<span class="error">%s</span>');

	// if we need to output a captcha
	if(isset($_GET['captcha'])) {
		$captcha = new Captcha(120,40,6);
	}

	// if submitted
	if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
		$username = $_POST['username'];
		$password = $_POST['password'];
		$captcha  = $_POST['captcha'];
		
		$newpw  = $_POST['newpw'];
		$newpw_re  = $_POST['newpw_re'];
		$error = array();
		// validate username
		if(!ctype_alnum($username)) {
			$error['username'] = sprintf(UI_ERROR,'Illigal characters in the username');
		}
		// validate password
		if(!ctype_alnum($password)) {
			$error['password'] = sprintf(UI_ERROR,'Illigal characters in the password');
		
		}
		// validate captcha
		if($captcha != $_SESSION['captcha']) {
			$error['captcha']  = sprintf(UI_ERROR,'Wrong security code');
		}

		if(!ctype_alnum($newpw)) {
			$error['newpw'] = sprintf(UI_ERROR,'Illigal characters in the password');
		}
		
		if($newpw !== $newpw_re) {
			$error['newpw'] = sprintf(UI_ERROR,'The Password doesnt match!');
		}
		
		if(!ctype_alnum($newpw)) {
			$error['newpw'] = sprintf(UI_ERROR,'Illigal characters in the password');
		}

		// no errors, continue to username check
		if(empty($error)) {
			// db connect
			$conn = odbc_connect(
								$config['db_username'],
								$config['db_password']);

			$sql = "SELECT     ID
					FROM         Login
					WHERE     (ID = '".$username."')";
					
			$result = odbc_exec($conn, $sql);
			$data = odbc_fetch_row($result);
			
			if($data) {
				$sql = "SELECT [PWD] FROM Login WHERE [ID] = '".$username."'";
				$result = odbc_exec($conn, $sql);
				$i=1;

				while (odbc_fetch_row($result, $i)){
					$password1 = odbc_result($result, 1);
					$password1 = Password::decode($password1);
					$i++;
				}

				if($password1 == $password){

					$sql = "SELECT [Scode] FROM [Login] WHERE [ID] = '".$username."'";
					$result = odbc_exec($conn, $sql);
					$i=1;

					while (odbc_fetch_row($result, $i)){
						$scode1 = odbc_result($result, 1);
						$i++;
					}

					if(empty($scode1))
					{
						die("Account has no Secret Number! Changing password not possible");
					}
					else
					{

						if($scode !== $scode1){
							$error['scode'] = sprintf(UI_ERROR,'Wrong Secret number');
							$result = false;
						} else {
							$newpw = Password::encode($newpw);
							$sql = "UPDATE [Login] SET [PWD] = ".$newpw." WHERE [ID] = '".$username."'";
							$result = odbc_exec($conn, $sql);}
					}
				} else {
					$error['password'] = sprintf(UI_ERROR,'Wrong Password');
					$result = false;}
			} else { 
				$error['username'] = sprintf(UI_ERROR,'Account does not exist!');
				$result = false;}
		}
	}


	// display template
	include $config['template'];

?>
 
here is it without s/n and captcha

PHP:
<?php
		include 'Password.php'; // password class


	// configuration
	$config = array(
					'db_username' => 'sa', // database username
					'db_password' => '******',   // database password
					'db_dsn'      => 'kal_auth',   // system DSN to the database
					'template'    => 'registration.tpl',  // registration template path/filename
					'debug'       => false,               // show SQL errors if true
					);

	// HTML error
	define('UI_ERROR','<span class="error">%s</span>');

	// if submitted
	if(strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
		$username = $_POST['username'];
		$password = $_POST['password'];
		$newpw  = $_POST['newpw'];
		$newpw_re  = $_POST['newpw_re'];
		$error = array();
		// validate username
		if(!ctype_alnum($username)) {
			$error['username'] = sprintf(UI_ERROR,'Illigal characters in the username');
		}
		// validate password
		if(!ctype_alnum($password)) {
			$error['password'] = sprintf(UI_ERROR,'Illigal characters in the password');
		}

		if(!ctype_alnum($newpw)) {
			$error['newpw'] = sprintf(UI_ERROR,'Illigal characters in the password');
		}
		
		if($newpw !== $newpw_re) {
			$error['newpw'] = sprintf(UI_ERROR,'The Password doesnt match!');
		}
		
		if(!ctype_alnum($newpw)) {
			$error['newpw'] = sprintf(UI_ERROR,'Illigal characters in the password');
		}

		// no errors, continue to username check
		if(empty($error)) {
			// db connect
			$conn = odbc_connect($config['db_dsn'],
								$config['db_username'],
								$config['db_password']);

			$sql = "SELECT     ID
					FROM         Login
					WHERE     (ID = '".$username."')";
					
			$result = odbc_exec($conn, $sql);
			$data = odbc_fetch_row($result);
			
			if($data) {
				$sql = "SELECT [PWD] FROM Login WHERE [ID] = '".$username."'";
				$result = odbc_exec($conn, $sql);
				$i=1;

				while (odbc_fetch_row($result, $i)){
					$password1 = odbc_result($result, 1);
					$password1 = Password::decode($password1);
					$i++;
				}

				if($password1 == $password){


							$newpw = Password::encode($newpw);
							$sql = "UPDATE [Login] SET [PWD] = ".$newpw." WHERE [ID] = '".$username."'";
							$result = odbc_exec($conn, $sql);


				} else {
					$error['password'] = sprintf(UI_ERROR,'Wrong Password');
					$result = false;}
			} else { 
				$error['username'] = sprintf(UI_ERROR,'Account does not exist!');
				$result = false;}
	}


	// display template
	include $config['template'];

?>
 
frist thx for you guys but i got this error when i change password-,-
this error of script by bird
Warning: odbc_connect() expects at least 3 parameters, 2 given in C:\xampp\htdocs\ChangePassword\index.php on line 122

Warning: odbc_exec() expects parameter 1 to be resource, null given in C:\xampp\htdocs\ChangePassword\index.php on line 128

Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in C:\xampp\htdocs\ChangePassword\index.php on line 129

Account does not exist!


and this error when i go to page of change password
script of thedargon

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\ChangePassword\index.php on line 91

just need script password change with captcha and work w/o sn
 
frist thx for you guys but i got this error when i change password-,-
this error of script by bird
Warning: odbc_connect() expects at least 3 parameters, 2 given in C:\xampp\htdocs\ChangePassword\index.php on line 122

Warning: odbc_exec() expects parameter 1 to be resource, null given in C:\xampp\htdocs\ChangePassword\index.php on line 128

Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in C:\xampp\htdocs\ChangePassword\index.php on line 129

Account does not exist!


and this error when i go to page of change password
script of thedargon

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\ChangePassword\index.php on line 91

just need script password change with captcha and work w/o sn

Is cos the script that bird posted is for SQL 2000 not SQL 2005 - i think

I have been looking for a password change script for SQL 2005 but i have so far rendered unlucky finding one... i know DragoN and Arachne have them somewhere... think Ghost had one kicking about too... n so does Zelda its just hunting them down ;)
 
Is cos the script that bird posted is for SQL 2000 not SQL 2005 - i think

I have been looking for a password change script for SQL 2005 but i have so far rendered unlucky finding one... i know DragoN and Arachne have them somewhere... think Ghost had one kicking about too... n so does Zelda its just hunting them down ;)
all scripts working with any sql version 2000 / 2005 / 2008
he get this error maybe because (didnt create kal_auth ODBC / sa password isnt correct / sql server name not found )
 
Status
Not open for further replies.
Back