SphereCommunity
Auto account PHP web - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: General Help (/Forum-General-Help)
+--- Thread: Auto account PHP web (/Thread-Auto-account-PHP-web)

Pages: 1 2


Auto account PHP web - admin_teclis - 12-24-2012 11:03 PM

Hello and Merry Christmas!
For days, I'm trying to create a script in PHP to automatically create accounts ... Unfortunately I do not know where to start ... PHP and MYSQL know them but I do not understand how to interact with sphere ... There are ready-made scripts out there? I was able to make sure that I create the account via the web, but now I can not be postponed password if you lose ... Can you help?


RE: Auto account PHP web - admin_teclis - 12-28-2012 11:53 PM

help me please....


RE: Auto account PHP web - Shaklaban - 12-29-2012 01:00 AM

scripts side is this since you know mysql and php i think you can do the rest:

PHP Code:
[function create_new_accounts]
if <
db.connected>
    
DB.QUERY "SELECT * FROM accounts WHERE status='0' LIMIT 10"
    
if (<DB.ROW.NUMROWS> > 0)
        for 
R 0 <eval <DB.ROW.NUMROWS>-1>
            
serv.account add <DB.ROW.<eval <LOCAL.R>>.login> <DB.ROW.<eval <LOCAL.R>>.password>    
            
serv.account <DB.ROW.<eval <LOCAL.R>>.logintag.mail=<DB.ROW.<eval <LOCAL.R>>.email>
            
serv.account <DB.ROW.<eval <LOCAL.R>>.logintag.password=<DB.ROW.<eval <LOCAL.R>>.password>
            
serv.account <DB.ROW.<eval <LOCAL.R>>.loginplevel 1    
            DB
.EXECUTE "UPDATE accounts SET status='1' WHERE login='<DB.ROW.<eval <LOCAL.R>>.login>'"
        
endfor
    endif
endif 



RE: Auto account PHP web - escribano - 12-29-2012 03:34 PM

All u gotta do is a table, where u need to store ACCOUNT and PASSWORD of the new account

Create a Invis Stone that on=@Timer calls the db.query to execute a query and add the new accounts Smile

Code:
ON=@Timer
db.connect
db.query "select * from accounts where created=0"
if (<eval <db.row.numrows>> >= 1)
    for x 0 <eval <db.row.numrows>-1>
        serv.account add <db.row.<eval <dlocal.x>>.login> <db.row.<eval <dlocal.x>>.pass>
        serv.log Account created: <db.row.<eval <dlocal.x>>.login>
        db.query "update accounts set created=1 where id=<db.row.<eval <dlocal.x>>.id>"
    endfor
endif
timer 300
return 1

See yah!


RE: Auto account PHP web - Darkyhood - 12-31-2012 08:31 AM

(12-29-2012 03:34 PM)escribano Wrote:  Create a Invis Stone that on=@Timer calls the db.query to execute a query and add the new accounts Smile
I think better use function f_onserver_timer


RE: Auto account PHP web - admin_teclis - 01-02-2013 04:26 AM

Happy new year!!!Big Grin

tnx for the reply...

I was able to create accounts from web ... I used a script I found and modernized according to my needs ... Unfortunately, the script in question would also recover password recovery via pin and pin, but I do not know why I do not work ... If you want to place the code ...
Now I have another problem inherent in the web ...
Should I create a status page and let me know how to find some values ​​..
example:
Name pg - Race - Class - Gilda - Gold - Kills - Fama - Karma - connection time and the various skill above 100 ...
How do I? I have not the faintest idea how to do it ... I opened the spherestatus but honestly I have not figured out how to pass the values ​​...
Last thing .. I was also able to connect to a mysql sphere ... Eventulamente I could do this status, how do I pass it into another table?


RE: Auto account PHP web - admin_teclis - 01-05-2013 11:55 PM

help me pls Sad


RE: Auto account PHP web - Ultima One - 01-07-2013 01:04 PM

change sphere_serv_trigs.scp to contain this:

Code:
// Update accounts from database
[function f_acc_update]
if ( <DB.connected> )
    DB.QUERY "SELECT * FROM accounts WHERE status='0'"
    if (<DB.ROW.NUMROWS> > 0)
        for R 0 <eval <DB.ROW.NUMROWS>-1>
            serv.account add <DB.ROW.<eval <LOCAL.R>>.login> <DB.ROW.<eval <LOCAL.R>>.password>
            DB.EXECUTE "UPDATE accounts SET status='1' WHERE login='<DB.ROW.<eval <LOCAL.R>>.login>'"
            serv.log MySQL Debug: #<eval <LOCAL.R>> Account <DB.ROW.<eval <LOCAL.R>>.login> has been created!
        end
    endif
endif


[FUNCTION f_onserver_timer]
serv.f_acc_update
ACCOUNT.UPDATE

In Sphere.ini set the TimerCall to 10, and activate SQL if not already done:

Code:
// MySql configuration.
MYSQL=1
MySqlHost=127.0.0.1
MySqlUser=username
MySqlPassword=password
MySqlDatabase=dbNAme

// Amount of minutes to call f_onserver_timer (0 disables this, default)
TimerCall=10


Create a file called db.php (to connect to your database):

PHP Code:
<?php

$username 
"yourUserNAme";
$password "yourPAssword";
$hostname "localhost";
$db "theDbName";

try {
    
$con = new PDO("mysql:host=$hostname;dbname=$db"$username$password);
     }
    catch(
PDOException $e)
    {
        echo 
$e->getMessage();
    }
?>


Then, create a file called register.php :

PHP Code:
<?php

session_start
();
include(
'db.php');
$account $_POST['account'];
$password $_POST['password'];
$email $_POST['email'];
$ip $_SERVER['REMOTE_ADDR'];
    if (!empty(
$_SERVER['HTTP_CLIENT_IP'])) {
        
$ip $_SERVER['HTTP_CLIENT_IP'];
    } elseif (!empty(
$_SERVER['HTTP_X_FORWARDED_FOR'])) {
        
$ip $_SERVER['HTTP_X_FORWARDED_FOR'];
    }

$sql "SELECT * FROM accounts WHERE login = '".$account."'";
$rows $con->prepare($sql);
$rows->execute();
if(
$rows->rowCount() > 0){
    
header('Location: signup.php?regError=Username%20already%20in%20use');
}else{
    
$sql2 "INSERT INTO accounts (`login`, `password`, `email`, `ip`) VALUES ('".$account."','".$password."','".$email."','".$ip."')";
    
$rows2 $con->prepare($sql2);
    
$rows2->execute();
    
$_SESSION['account'] = $account;
    
header('Location: signup.php');
}
?>


Then, create signup.php:


PHP Code:
<?php
session_start
();
if(isset(
$_SESSION['account'])){
echo 
"Thank you for Registering. Your account will be activated within 10 minutes.";
}else{
?>
<h1>Fill in the form below to sign up!</h1>
<form id="regForm" action="register.php" method="post">
            <?php if(isset($_GET['regError'])){ echo "<span class='error'>".$_GET['regError']."</span><br />"; } ?>
            <label for="accountr">Account:</label>
            <input id="accountr" type="text" value="" name="account" />
            <label for="passwordr">Password:</label>
            <input id="passwordr" type="password" value="" name="password" />
            <label for="emailr">Email:</label>
            <input id="emailr" type="email" value="" name="email" />
            <input id="register" type="submit" value="Register" />
        </form>
<?php




This is a simplified version of the script I wrote for our server (can see it at theuoproject.co.uk)

Hope that helps.


RE: Auto account PHP web - Sharlenwar - 01-07-2013 08:34 PM

Thanks for that basic PHP implementation. Helps out for anyone looking to do the same. Big Grin


RE: Auto account PHP web - Ultima One - 01-07-2013 10:35 PM

NP.

The one thing I hate about these forums is people asking for simple things never getting a simple answer. Sad