[Release] PHP Reborn Script

10/08/2009 18:46 janvier123#1
Hi,

zombe and me where working on a reborn script for player to have there own reborn without the help of GM's
this allows them to reborn them when they want

just go to the page fill in your character name, and follow the steps

Here is the code:

reborn.php (FILE MUST BE REBORN.PHP !!!!)

[php]

and the mssql code:
RemoteReborn (MUST BE CALLED "RemoteReborn" OR IT WILL NOT WORK !)
1) Open/start: "Query Analyzer"
2) Login with your Login Name and password
3) Select "Character" db at the top !!!!!!!!!!!
4) Copy and paste the following line:


and again thx to zombe for helping me :D

PS:
PHP Code:
            // WARNING YOU NEED TO CHANGE "/50000000/" IF YOU CHANGED YOUR REQUIREMENTS             
//             } elseif(!preg_match("/50000000/", $_POST['new_dwMoney'])) { 
//            echo "<br><center>The dill does not match the requirements.<br><a href='javascript:history.back()'>Go Back</a></center>"; 
It does not work YET
cuz i dont know how to pergmatch for 50 mill or higher so ....
10/08/2009 18:59 PacoPG#2
gonna try it! thnx
10/09/2009 04:53 *JayKay*#3
janvier123 congratulations for the post but I have doubts whether I was for my server max lvl 200 and put my character to reset lv 170 if it passes it to lvl 171 + resets could not say as I do to put the reset lvl 170 to 200 and that if the player does not want to reset lvl 170 he can reset 180 or 190 ... can tell how to do?
10/09/2009 09:20 janvier123#4
Change in "RemoteReborn"

PHP Code:
(wlevel >= 170
to your needs

and change in reborn.php

PHP Code:
$req = array(  
'level' => "170"
); 
and disable this you can put // at the beginning or remove it
i still havend found out to to set it to 170+

PHP Code:
            // WARNING YOU NEED TO CHANGE "/170/" IF YOU CHANGED YOUR REQUIREMENTS
             
} elseif(!preg_match("/170/"$_POST['new_wLevel'])) {
            echo 
"<br><center>The level does not match the requirements.<br><a href='javascript:history.back()'>Go Back</a></center>"
10/09/2009 20:40 caper#5
Quote:
Originally Posted by janvier123 View Post
Change in "RemoteReborn"

PHP Code:
(wlevel >= 170
to your needs

and change in reborn.php

PHP Code:
$req = array(  
'level' => "170"
); 
and disable this you can put // at the beginning or remove it
i still havend found out to to set it to 170+

PHP Code:
            // WARNING YOU NEED TO CHANGE "/170/" IF YOU CHANGED YOUR REQUIREMENTS
             
} elseif(!preg_match("/170/"$_POST['new_wLevel'])) {
            echo 
"<br><center>The level does not match the requirements.<br><a href='javascript:history.back()'>Go Back</a></center>"
I'm scratching my head on a few things here. Seems the
PHP Code:
$req = array(  
'level' => "170"
); 
should be
PHP Code:
$req = array(  
'level' >= "170"
); 
to do a greater than or equal comparison and why are you using preg_match?


What I would do since you are already pulling info from the db is:

-ask for the character name
-pull the data from db based on the name (as you already are)
-do the level comparison right from the data pulled, something like ($row4[2] >= '170') assuming $row4[2] is wlevel, instead of using the preg_match

Doing it like that should allow any level over 170 to be true, instead of the literal match preg_match is giving you.
10/14/2009 03:43 *JayKay*#6
so how can i replace the preg_match for another function to compare $row4[2]>='170'?
is there a way? thats my main problem here now. as i changed the
$req = array(
'level' >= "190",
);
when someone try to do a reborn at lvl 180(for exemple) it will complete(only on the website) the step2 and go to step 3 but the char will not be reborned.

how can i change it in favor to keep the
echo "<br><center>The level does not match the requirements.<br><a href='javascript:history.back()'>Go Back</a></center>";
10/14/2009 03:54 *JayKay*#7
i tried
} elseif($row2[3] >= '190') {
echo "<br><center>The level does not match the requirements.<br><a href='javascript:history.back()'>Go Back</a></center>";

but it keeps passing to step 3 but not reboring the char. i would like instead it go to step3 it send the msg its supossed to sends. "The level does not match the requirements."
10/14/2009 03:56 Decima#8
Quote:
$req = array(
'level' >= "170",
);
last time i checked u cannot set and array variable this way *rolls eyes*

the '=>" does not mean 'greater than or equal to' in this case, its actually setting the $req['level'] variable to 170

u can then check

if ($req['level'] >= 170) {
*put some code here;*
} else {
*put some statement to the effect that they cannot here*
}

sometimes i feel as if only jan and zombe know php, altho cape seems to know his shit, php apparently is not part of his expertise . . . .
10/14/2009 04:35 *JayKay*#9
if ($req['level'] >= 170) {
*put some code here;*
} else {
*put some statement to the effect that they cannot here*
}


what code should i put there so it can go to step3?
10/14/2009 04:57 Decima#10
Quote:
Originally Posted by arthurvalenca View Post
if ($req['level'] >= 170) {
*put some code here;*
} else {
*put some statement to the effect that they cannot here*
}


what code should i put there so it can go to step3?
sorry man, im the kind of guy that wants you to figure that out for urself, that way u learn, and know what to do next time . . . give a man a fish . . . .
10/14/2009 05:03 *JayKay*#11
oh.. oks man.. great help.. if i knew anything about php i wouldnt be here asking for help would i?
can someone else try to help me?
if ($req['level'] >= 170) {
*put some code here;*
} else {
*put some statement to the effect that they cannot here*
}

what code should i put there so it go to step3?
10/14/2009 05:17 caper#12
Quote:
Originally Posted by Decima View Post
last time i checked u cannot set and array variable this way *rolls eyes*

the '=>" does not mean 'greater than or equal to' in this case, its actually setting the $req['level'] variable to 170

u can then check

if ($req['level'] >= 170) {
*put some code here;*
} else {
*put some statement to the effect that they cannot here*
}

sometimes i feel as if only jan and zombe know php, altho cape seems to know his shit, php apparently is not part of his expertise . . . .


You are right I am a perl man and have been learning php in leisure time, but like you I was just trying to offer a quick hint that there would be a better way to do the comparison and not so much a working example. I based that off of a quick glance of the code he was already using.

I agree the syntax should be better written and should be based from the data he was already querying, instead of using preg_match.

I never claim to be an expert because someone will always prove you wrong.
10/14/2009 06:08 saweet#13
Sorry for intruding, just poking my head in here. If you plan on having other people access this script other than yourself, you really need to validate and escape the user input. As this script has 4 queries that are potentially vulnerable to SQL injection. These days people normally use PDO or prepared statements. However, with MSSQL you only need to escape single quotes. In MSSQL this is done by using ''. Such as: str_replace("'", "''", $string);

Also, there's several integer comparisons where the operand is a string. This causes PHP to cast the string back into an integer. ie: if ($count1 < '1') should be just 1 not '1'. Just pointing it out as it is littered throughout the script, even though PHP will correct it and you'll never notice. However, if $count1 in the example happened to be a string that didn't contain a number, it would not behave as expected.

If new_wLevel is only a number, there's no reason to preg_match.
PHP Code:
} elseif (!preg_match("/170/"$_POST['new_wLevel'])) { 
You could effectively just do the following:
PHP Code:
if (intval($_POST['new_wLevel']) != 170) { 
The reason you use intval here is that it will strip any non-numerical characters in the comparison. ie: 170abc will turn into just 170

PHP Code:
$result3 mssql_query(
            USE character; 
            EXEC RemoteReborn '"
.$_POST['new_name']."' 
        "
,$ms_con); 
Multiple statements with mssql_query() is not allowed.

You can also use or die('Error here'); at the end of mssql_connect, mssql_query, etc so that it if the function fails, it will halt execution of the script. ie: mssql_connect(...) or die('Could not connect to database.');

I hope my criticizing helps with your script and to write better PHP. Good luck!
10/14/2009 06:29 Decima#14
Quote:
Originally Posted by caper View Post
You are right I am a perl man and have been learning php in leisure time, but like you I was just trying to offer a quick hint that there would be a better way to do the comparison and not so much a working example. I based that off of a quick glance of the code he was already using.

I agree the syntax should be better written and should be based from the data he was already querying, instead of using preg_match.

I never claim to be an expert because someone will always prove you wrong.
agreed

preg_match is prolly not the best way to go, i like to use IF statements and switches myself, keep the code easily understood, and preg_match has been known to make a bad day worse ;)
10/14/2009 08:54 bengals#15
Could you do a reborn script for coins instead of stats?