Hello,
I really need to get a script to work that can add username to my MSSQL Server 2000 database table.
This is a script I got using PHP to ODBC to MSSQL.
Thank you for reading and helping.
Sincerely,
Danny
THE PHP CODE:
<?php
//Scripted by GodlyDanny for UnitedMMO
$ipLog='ipLogFile.txt';
$date=date("Y-m-d H:i:s");
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) {$vis_ip = getenv(REMOTE_ADDR);}
else {$vis_ip = $_SERVER['REMOTE_ADDR'];}
function recordData($vis_ip,$ipLog,$date,$username,$mail)
{
//$filePointer = fopen($ipLog,"a+");
//$logMsg = $date."][".$vis_ip."][".$mail."][".$username."\n";
//fputs($filePointer,$logMsg);
//fclose($filePointer);
}
function checkLog($vis_ip,$ipLog)
{
global $valid; $ip=$vis_ip;
$data=file("$ipLog");
foreach ($data as $record)
{
$subdata=explode("][",$record);
if ($ip == $subdata[1])
{
$valid=0;
break;
}
}
}
//checkLog($vis_ip,$ipLog);
// error reporting
error_reporting(E_ALL);
ini_set('display_errors','on');
// configuration
$config = array(
'db_username' => 'sa', // database username
'db_password' => 'anything1234', // database password
'db_dsn' => 'odbc_users', // 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') {
checkLog($vis_ip,$ipLog);
$username = $_POST['username'];
$password = $_POST['password'];
$mail=$_POST["email"];
$emailresult=preg_match("/^[^@ ]+@[^@ ]+\.[^@ ]+$/",$mail,$trashed);
$error = array();
// validate username
if(!ctype_alnum($username)) {
$error['username'] = sprintf(UI_ERROR,'Illigal characters in the username');
}
else
if ((StrLen($username) < 1) or (StrLen($username) > 8)) {
$error['username'] = sprintf(UI_ERROR,'Username must be between 1-8 characters');
}
else
if ((StrLen($password) < 1) or (StrLen($password) > 8)) {
$error['password'] = sprintf(UI_ERROR,'Password must be between 1-8 characters');
}
else
if ($valid =="0") {
$error['iplocked'] = sprintf(UI_ERROR,'You can not create more accounts with us');
}
// validate password
else
if(!ctype_alnum($password)) {
$error['password'] = sprintf(UI_ERROR,'Illigal characters in the password');
}
else
if(!$emailresult){
$error['email'] = sprintf(UI_ERROR,'Please enter a valid email');
}
// no errors, continue to username check
if(empty($error)) {
// db connect
$conn = odbc_connect($config['db_dsn'],
$config['db_username'],
$config['db_password']);
// check about account name is taken
$check = "SELECT
[name] FROM [users]
WHERE
[name]='%s'
OR
[name]='%s'
OR
[name]='%s'
OR
[name]='%s'
";
$check = sprintf($check,$username,
strtolower($username),
strtoupper($username),
ucfirst($username)
);
$exec = odbc_exec($conn,$check);
// check for errors
if(!$exec && ($config['debug'] === true)) {
echo odbc_errormsg($conn);
die();
}
// is the account registered?
$data = odbc_fetch_array($exec);
if($data !== false) {
$error['username'] = sprintf(UI_ERROR,'Account already registered,
please choose another name');
} else {
///WRITE DATA
recordData($vis_ip,$ipLog,$date,$username,$mail);
/// MISSING PASSWORD CONVERTION PART////////
// prepare sql
$sql = "INSERT INTO
[users] ([name],[passwd],[Prompt],[answer],[truename],[idnumber],,[mobilenumber],[province],[city],[phonenumber],[address],[postalcode],[gender],[birthday],[creatime],[qq],[passwd2])
VALUES
I really need to get a script to work that can add username to my MSSQL Server 2000 database table.
This is a script I got using PHP to ODBC to MSSQL.
Thank you for reading and helping.
Sincerely,
Danny
THE PHP CODE:
<?php
//Scripted by GodlyDanny for UnitedMMO
$ipLog='ipLogFile.txt';
$date=date("Y-m-d H:i:s");
$register_globals = (bool) ini_get('register_gobals');
if ($register_globals) {$vis_ip = getenv(REMOTE_ADDR);}
else {$vis_ip = $_SERVER['REMOTE_ADDR'];}
function recordData($vis_ip,$ipLog,$date,$username,$mail)
{
//$filePointer = fopen($ipLog,"a+");
//$logMsg = $date."][".$vis_ip."][".$mail."][".$username."\n";
//fputs($filePointer,$logMsg);
//fclose($filePointer);
}
function checkLog($vis_ip,$ipLog)
{
global $valid; $ip=$vis_ip;
$data=file("$ipLog");
foreach ($data as $record)
{
$subdata=explode("][",$record);
if ($ip == $subdata[1])
{
$valid=0;
break;
}
}
}
//checkLog($vis_ip,$ipLog);
// error reporting
error_reporting(E_ALL);
ini_set('display_errors','on');
// configuration
$config = array(
'db_username' => 'sa', // database username
'db_password' => 'anything1234', // database password
'db_dsn' => 'odbc_users', // 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') {
checkLog($vis_ip,$ipLog);
$username = $_POST['username'];
$password = $_POST['password'];
$mail=$_POST["email"];
$emailresult=preg_match("/^[^@ ]+@[^@ ]+\.[^@ ]+$/",$mail,$trashed);
$error = array();
// validate username
if(!ctype_alnum($username)) {
$error['username'] = sprintf(UI_ERROR,'Illigal characters in the username');
}
else
if ((StrLen($username) < 1) or (StrLen($username) > 8)) {
$error['username'] = sprintf(UI_ERROR,'Username must be between 1-8 characters');
}
else
if ((StrLen($password) < 1) or (StrLen($password) > 8)) {
$error['password'] = sprintf(UI_ERROR,'Password must be between 1-8 characters');
}
else
if ($valid =="0") {
$error['iplocked'] = sprintf(UI_ERROR,'You can not create more accounts with us');
}
// validate password
else
if(!ctype_alnum($password)) {
$error['password'] = sprintf(UI_ERROR,'Illigal characters in the password');
}
else
if(!$emailresult){
$error['email'] = sprintf(UI_ERROR,'Please enter a valid email');
}
// no errors, continue to username check
if(empty($error)) {
// db connect
$conn = odbc_connect($config['db_dsn'],
$config['db_username'],
$config['db_password']);
// check about account name is taken
$check = "SELECT
[name] FROM [users]
WHERE
[name]='%s'
OR
[name]='%s'
OR
[name]='%s'
OR
[name]='%s'
";
$check = sprintf($check,$username,
strtolower($username),
strtoupper($username),
ucfirst($username)
);
$exec = odbc_exec($conn,$check);
// check for errors
if(!$exec && ($config['debug'] === true)) {
echo odbc_errormsg($conn);
die();
}
// is the account registered?
$data = odbc_fetch_array($exec);
if($data !== false) {
$error['username'] = sprintf(UI_ERROR,'Account already registered,
please choose another name');
} else {
///WRITE DATA
recordData($vis_ip,$ipLog,$date,$username,$mail);
/// MISSING PASSWORD CONVERTION PART////////
// prepare sql
$sql = "INSERT INTO
[users] ([name],[passwd],[Prompt],[answer],[truename],[idnumber],,[mobilenumber],[province],[city],[phonenumber],[address],[postalcode],[gender],[birthday],[creatime],[qq],[passwd2])
VALUES