Jump to content

|PHP| Interesting Scripts for your Website


Recommended Posts

Another update:

<?php
$realmd = array(
'db_host'=> 'localhost',        // Host IP
'db_username' => 'root',        // Database login-name
'db_password' => 'mangos',      // Database login-pass
'db_name_realm'=> 'realmd',     // Database name of realm
);

function check_for_symbols($string)
{
   $len=strlen($string);
   $allowed_chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
   for($i=0;$i<$len;$i++)if(!strstr($allowed_chars,$string[$i]))
       return TRUE;
   return FALSE;
}
function sha_password($user,$pass)
{
   $user = strtoupper($user);
   $pass = strtoupper($pass);
   return SHA1($user.':'.$pass);
}
if ($realmd[db_host] != "" && $realmd[db_username] != "" && $realmd[db_password] != "" && $realmd[db_name_realm] != "")
{
   $new_connect = mysql_connect($realmd[db_host],$realmd[db_username],$realmd[db_password]);
   if ($new_connect)
       $selectdb = mysql_select_db($realmd[db_name_realm],$new_connect);
   else
   {
       echo "Could NOT connect to db: Configs (Name/Pass/Port/IP) are incorrect";
       die;
   }

   if ($new_connect && !$selectdb)
   {
       echo "Could NOT connect to db: Database does not exist!";
       die; 
   }

   if ($_POST['registration'])
   {
       $username = $_POST['username'];
       $password = sha_password($username,$_POST['password']);
       $expansionnumber = $_POST['expansion'];

       $check_username = mysql_query("SELECT username FROM `account` WHERE username='$username'");
       if ($username == "")
       {
           echo "Field username is empty!";
       }
       else if ($password == "")
       {
           echo "Field password is empty!";
       }
       else if (check_for_symbols($_POST[password]) == TRUE)
       {
           echo "Error with creating account: password has invalid symbols in it.";
       }
       else if (check_for_symbols($username) == TRUE)
       {
           echo "Error with creating account: username has invalid symbols in it.";
       }
       else if (mysql_num_rows($check_username) != 0)
       {
           echo "Error with creating account: name is already in use.";
       }
       else
       {
           $username = mysql_real_escape_string($username);
           mysql_query("INSERT INTO account (username,sha_pass_hash,expansion) VALUES
('$username','$password','$expansionnumber')");
           if (mysql_error)
               echo mysql_errno($new_connect) . ": " . mysql_error($new_connect). "\\n";
           else
           {
               echo "Account created.";
               mysql_close($new_connect);
           }
       }
   }
   else
   {
       ?>
       <html>
       <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
       Username <input type="text" name="username">
       Password <input type="password" name="password">
       Expansion Selection<select name="expansion">
           <option value="1">Vanilla</option>
           <option value="2">TBC</option>
           <option value="3">WotLK</option>
       </select>
       <input type="submit" name="registration">
       </form>
       </html>
       <?php
   }
}
else
   echo "Config file either not present or connection variables are empty";
?>

added expansion selection dropdown menu, a better check for the pass and name and a check for empty variables in the connection array on the top

oh and display the mysql error number with feedback if, for whatever reason, there's an error during the query importing

Link to comment
Share on other sites

  • Replies 171
  • Created
  • Last Reply

Top Posters In This Topic

did you guys know any script that could help me to copy a character? i mean his items inventory achiev etc etc. why? well it seems that i have a player with a bug and cant find the fix, so my option 1 is to recreate his character with all what he have .

Erm no, that's not really something you should have on a website... you probably have to do it manually, the time that you took to post here could also be used to recreate his char

Link to comment
Share on other sites

  • 3 weeks later...
tnx :P, btw did any one know some web account manager? where the ppl can log in and change his expan,password, etc i found one project hungarian but its for TC http://wam.nwhost.hu/?p=55

I wanted to create a simple website for MaNGOS but im very stupid when it comes to design. If someone could work out some cool design i can work on php part and create small cms for mangos

Link to comment
Share on other sites

I'm trying to make this script work but it always keeps saying that the server is online even if it's not. :-|

Can someone give me a little help ?

How exactly are you checking if its "Online"?

<?php
$fp = @fsockopen("127.0.0.1","8085");
if($fp!==FALSE){
 echo "Online";
 fclose($fp);
}else{
 echo "Offline";
}
?>

Nothing fancy/pretty, but this seems to work alright for me

Edit: Personally I would just check if MaNGOS is running without trying to connect to it, (`ps | grep mangos` or something similar) as testing the connection could delay your script, but if your testing if the world is connect-able by a client than that fsockopen code should work

Link to comment
Share on other sites

So I tried this port : 3921038210931. And it says "Online".

The character "@" is used for mask errors on function.

The range of values accepted is 0/65535.

Set value to 65536 will raise an exception on function fsockopen and result of condition will be true => online

Link to comment
Share on other sites

ok removes "@" and paste here the error

There's no error.

The script just keep sayin that the server is always online, no matter what port I am using or if the server is online or offline.

<?php
if(($fp = fsockopen("my_ip","8085", $enumber, $evalue, 1)) !== FALSE){
echo "Online";
fclose($fp);
}else{
echo "Offline";
}
echo "

Enumber:".$enumber."

Evalue:".$evalue;
?>

Output

Online

Enumber:0

Evalue:

Link to comment
Share on other sites

mmm try to check yours php.ini configuration.

if it isn't set you must change the following settings.

; Common Values:

; Default Value: E_ALL & ~E_NOTICE

; Development Value: E_ALL | E_STRICT

; Production Value: E_ALL & ~E_DEPRECATED

error_reporting = E_ALL | E_STRICT

; Possible Values:

; Off = Do not display any errors

; stderr = Display errors to STDERR (affects only CGI/CLI binaries!)

; On or stdout = Display errors to STDOUT

display_errors = On

Path php.ini :: ex. C:\\Program Files\\PHP\\php.ini

Link to comment
Share on other sites

@adriann54 maybe fsockopen() is trying to connect to the port on UDP, which would return true/online even when it's offline (because UDP is connectionless)

Try specifying the Transport Protocol as TCP manually and see what happens

$fp = fsockopen("[b]tcp://[/b]127.0.0.1","8085", $enumber, $evalue, 1)

BTW when fsockopen() connects with UDP on an invalid port number, no errors are thrown and appears online even the the port is higher than 65535, so I really think this may be your issue.. although this is the first time i've seen/heard of fsockopen using UDP by default instead of TCP

Here's some expanded server checking code, its only a base example and can be altered to look pretty by someone with basic php/html knowledge

<?php
// BEGIN User Defined Variables
$locales = array(
 'enUS' => array(
   'OK' => "Accepting Connections",
   'TIMEOUT' => "Operation Timed Out",
   'REFUSED' => "Connection Refused",
   'PORTLIMIT' => "Can't Assign Requested Address"
 ),
 // Other languages would go here if desired
);

$use_locale = 'enUS';
$timeout = 1; // If testing a connection across the WAN, increase this value

// $servers Structure "IP address","Port","Description"
$servers = array(
 array("tcp://127.0.0.1","8085","mangosd"),  // MaNGOS mangosd
 array("tcp://127.0.0.1","3724","realmd"),  // MaNGOS realmd
 array("tcp://127.0.0.1","7878","RA Console"),  // MaNGOS RA console
 array("tcp://127.0.0.1","3443","SOAP"),  // MaNGOS SOAP
 array("tcp://127.0.0.1","80","Apache"),    // Webserver apache
 array("tcp://127.0.0.1","3306","MySQL"),  // Database mysql
);

$be_verbose = false;
// END User Defined Variables

$errno = NULL;
$errstr = NULL;

foreach($servers as $value){
 $fp = @fsockopen($value[0],$value[1],$errno,$errstr,1);
 if($fp!==FALSE){
   fclose($fp);
 }
 echo $value[2] . " - ";
 if($be_verbose===true){
   echo $value[0] . ":" . $value[1] . " - ";
 }
 switch($errno){
   case 0:
     echo $locales[$use_locale]['OK'];
   break;
   case 49:
     echo $locales[$use_locale]['PORTLIMIT'];
   break;
   case 60:
     echo $locales[$use_locale]['TIMEOUT'];
   break;
   case 61:
     echo $locales[$use_locale]['REFUSED'];
   break;
 }
 echo "
\\n";
 if($be_verbose===true && $errno!==0){
   echo "(" . $errno . ") " . $errstr . "
\\n";  //Be verbose about errors, set $be_verbose to false to disable, true to enable
 }
}
?>

Link to comment
Share on other sites

@adriann54 maybe fsockopen() is trying to connect to the port on UDP, which would return true/online even when it's offline (because UDP is connectionless)

Try specifying the Transport Protocol as TCP manually and see what happens

$fp = fsockopen("[b]tcp://[/b]127.0.0.1","8085", $enumber, $evalue, 1)

BTW when fsockopen() connects with UDP on an invalid port number, no errors are thrown and appears online even the the port is higher than 65535, so I really think this may be your issue.. although this is the first time i've seen/heard of fsockopen using UDP by default instead of TCP

Here's some expanded server checking code, its only a base example and can be altered to look pretty by someone with basic php/html knowledge

<?php
// BEGIN User Defined Variables
$locales = array(
 'enUS' => array(
   'OK' => "Accepting Connections",
   'TIMEOUT' => "Operation Timed Out",
   'REFUSED' => "Connection Refused",
   'PORTLIMIT' => "Can't Assign Requested Address"
 ),
 // Other languages would go here if desired
);

$use_locale = 'enUS';
$timeout = 1; // If testing a connection across the WAN, increase this value

// $servers Structure "IP address","Port","Description"
$servers = array(
 array("tcp://127.0.0.1","8085","mangosd"),  // MaNGOS mangosd
 array("tcp://127.0.0.1","3724","realmd"),  // MaNGOS realmd
 array("tcp://127.0.0.1","7878","RA Console"),  // MaNGOS RA console
 array("tcp://127.0.0.1","3443","SOAP"),  // MaNGOS SOAP
 array("tcp://127.0.0.1","80","Apache"),    // Webserver apache
 array("tcp://127.0.0.1","3306","MySQL"),  // Database mysql
);

$be_verbose = false;
// END User Defined Variables

$errno = NULL;
$errstr = NULL;

foreach($servers as $value){
 $fp = @fsockopen($value[0],$value[1],$errno,$errstr,1);
 if($fp!==FALSE){
   fclose($fp);
 }
 echo $value[2] . " - ";
 if($be_verbose===true){
   echo $value[0] . ":" . $value[1] . " - ";
 }
 switch($errno){
   case 0:
     echo $locales[$use_locale]['OK'];
   break;
   case 49:
     echo $locales[$use_locale]['PORTLIMIT'];
   break;
   case 60:
     echo $locales[$use_locale]['TIMEOUT'];
   break;
   case 61:
     echo $locales[$use_locale]['REFUSED'];
   break;
 }
 echo "
\\n";
 if($be_verbose===true && $errno!==0){
   echo "(" . $errno . ") " . $errstr . "
\\n";  //Be verbose about errors, set $be_verbose to false to disable, true to enable
 }
}
?>

Thank you for your response.

I tried your script on my server and all services were online even if there were for real offline.

Then I tried this script on a free webhosting service and I put my ip.

The Result :

mangosd - Operation Timed Out (Turned Off)
realmd - Accepting Connections
RA Console - Operation Timed Out
SOAP - Operation Timed Out
Apache - Accepting Connections
MySQL - Operation Timed Out (No Remote Access)

So I guess, is my server fold.

I will reinstall it.

Link to comment
Share on other sites

×
×
  • 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. Privacy Policy Terms of Use