PDA

View Full Version : [PHP] How do I...



xRoyal15
09-11-2006, 08:32 PM
Oki, this will take some explaining.

I have the code:

:ban xRoyal15

Now, :ban is the function, xRoyal15 is the username.

I want to extract the username from that code, and use it.

So, someone types

:ban xRoyal15

It extracts the username (xRoyal15) from that shout, and ban it.

How would I go about extracting the username from the code?

Mentor
09-11-2006, 08:38 PM
Well first you would need to set up somthing to match the :ban so the function first activates, then you can use preg replace to remove the ":ban " bit and be left with the use name, you could then hash that to an id, and do what ever you like "/

preg_match plus preg_replace usin kinda stuff... very vaige and random i know, but im lazy, if you want a more detailed exsplination just tell me, and if i have time ill actulay provide more helful info on the sort of code... if your already good with php, and it was just a conceptal prob, hopefuly my vage crap will have helped anyway :D

xRoyal15
09-11-2006, 08:43 PM
Yer, im good with php, but i still sorta confused.

Good you go into more detail, maybe show me an example :rolleyes:

Mentor
09-11-2006, 08:47 PM
How much of the shout box do you have working so far?

Basicly every time someone says somthing, you wana look at the code for adding that to the DB.

Then you want to use preg_match in an if statment around it.
aka *persudo code*
if preg_match finds the text "ban:" in the input

Do the ban stuff here, aka preg_replace the text "ban: " and get the username.
Then useing the usename, updated the mysql to ether set somthing in there account to banned, or add there ip to a blocked list or somthing

Else (if its not ban)

Normal code to add new shout here

end if

xRoyal15
09-11-2006, 08:50 PM
It all works so far, so what you mean is...


if(preg_match == :ban){
preg_replace(:ban)
}else{
STUFF
}

Heinous
09-11-2006, 11:04 PM
Tried and tested way:


<?php
$ban = ":ban xRoyal15";
echo $ban;
$ban = explode(" ", $ban);
$ban['0'] = "";
$ban = implode("", $ban);
echo "<br />$ban"; //In quotes so I can use <br />
?>


I guess you're not as good with php as I first thought. ;>

xRoyal15
09-11-2006, 11:08 PM
Ah no... what happens is...

Shoutbox > Admin types :Ban x (x being user) > preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x > bans x

So i need this bit preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x >

and i can do the rest :)

On the shoutbox:

$name = $logged[username];
$shout = $_POST[shout];

Heinous
09-11-2006, 11:11 PM
Ah no... what happens is...

Shoutbox > Admin types :Ban x (x being user) > preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x > bans x

So i need this bit preg_match finds :Ban, > preg_replace removes :ban to just give x > $banuser = x >

and i can do the rest :)

On the shoutbox:

$name = $logged[username];
$shout = $_POST[shout];
Do you wanna make yourself clearer? I just gave you something that gives the username from a string, what do you want exactly?

edit:
oh wait, gotcha, code in a minute.

xRoyal15
09-11-2006, 11:15 PM
User posts shout ($shout)
If($logged[level] == 12){
Does a preg_match to find if it has :ban in it
If it does, it removes the ban, to give the username
username can then be used to ban the user
}else{
Inserts into database as a post :)

Clear as i can be :)

Edit: Just seen ya edit, oki :)

Heinous
09-11-2006, 11:25 PM
<?php
if ($logged[level] == 12)
{
$shout = ":ban xRoyal15"; //Assume this is $_POST[shout]
if (stristr($shout, ":ban"))
{
$ban = explode(" ", $ban);
$ban['0'] = "";
$ban = implode("", $ban);
//Function or whatever to ban the user here.
}
}
?>


stristr > preg_match

(preg_match returns an array)

That *should* work.

Mentor
09-11-2006, 11:28 PM
if your useing a function your not familiur with i suggest checking php.net, very useful

http://uk.php.net/preg_match

Pretty much anything im gona say about its in there anyway, the preg functions are always a bit confusieng due to regex with still often shows itself to be a pain in the ****

$userinput = "ban: bob";

if (preg_match("/ban: /i",$userinput )) {
// invoke ban script,
$ban = explode(" ", $ban);
$Persontoban =$ban['1']

// Banning script here
} else {
// Add the info normaly

}


Hope that quick crap helps :D

Dentafrice1
10-11-2006, 02:44 PM
He is not good at php. He asked me to help him.. he had a code like this

echo my stuff here .. its text;

with no ""'s

xRoyal15
10-11-2006, 03:59 PM
Thanks.

Denta, what are you on about?

Dentafrice1
10-11-2006, 04:03 PM
Everytime you post for help.. its always simple stuff.. so your not that good at php..

xRoyal15
10-11-2006, 04:16 PM
Its not that im not good, its that i havent used this yet..

Just to cofirm $ban is the username in the code?

Edit:


if ($logged[level] == 12 && stristr($shout, ":ban"))
{
$shout = $_POST[shout]; //Assume this is $_POST[shout]
if (stristr($shout, ":ban"))
{
$ban = explode(" ", $ban);
$ban['0'] = "";
$result = mysql_query("UPDATE `users` SET `banned` = 'banned' WHERE `username` = '$ban'") or die ('Error during the execution of the MySQL query : ' . mysql_error());

$query = mysql_query("INSERT INTO `ban` (`id` , `username` , `time`) VALUES ('', '$ban', '$days-$date')") or die ('Error during the execution of the MySQL query : ' . mysql_error());

$alert = mysql_query("UPDATE `users` SET `alert` = 'You have been banned and can no longer use the Site' WHERE `username` = '$user'") or die ('Error during the execution of the MySQL query : ' . mysql_error());
}
}else{

Right or wrong?

Mentor
10-11-2006, 10:45 PM
Its not that im not good, its that i havent used this yet..

Just to cofirm $ban is the username in the code?

Edit:


if ($logged[level] == 12 && stristr($shout, ":ban"))
{
$shout = $_POST[shout]; //Assume this is $_POST[shout]
if (stristr($shout, ":ban"))
{
$ban = explode(" ", $ban);
$ban['0'] = "";
$result = mysql_query("UPDATE `users` SET `banned` = 'banned' WHERE `username` = '$ban'") or die ('Error during the execution of the MySQL query : ' . mysql_error());

$query = mysql_query("INSERT INTO `ban` (`id` , `username` , `time`) VALUES ('', '$ban', '$days-$date')") or die ('Error during the execution of the MySQL query : ' . mysql_error());

$alert = mysql_query("UPDATE `users` SET `alert` = 'You have been banned and can no longer use the Site' WHERE `username` = '$user'") or die ('Error during the execution of the MySQL query : ' . mysql_error());
}
}else{

Right or wrong?

o.0 your useing a varible before you set it, and then repateing the code uselessly.
Your also misuseing the explode impolded copy Heinous gave you...



Get shout imput.
$shout = $_POST[shout];
// Assuming your ban code is "ban: MrUser"
if ($logged[level] == 12 && stristr($shout, "ban: "))
{
//since they have banning permission (im guesing) and "ban: " is in the input, we must be banning someone

//Exsplode the space in shout
$ban = explode(" ", $shout);
// the explode implode is more for when concatinaginng an undefined string length, since the syntax of the input of known its far easy just to drag the second chunk, 1 in this case.
$usertoban = $ban['1'];

// SHOVE ALL YA MYSQL FOR BAN HERE

}else{
//no ban syntax found, just update post as normal

//CODE HERE

}

Heinous
11-11-2006, 05:13 AM
Its not that im not good, its that i havent used this yet..

Just to cofirm $ban is the username in the code?

Edit:


if ($logged[level] == 12 && stristr($shout, ":ban"))
{
$shout = $_POST[shout]; //Assume this is $_POST[shout]
if (stristr($shout, ":ban"))
{
$ban = explode(" ", $ban);
$ban['0'] = "";
$result = mysql_query("UPDATE `users` SET `banned` = 'banned' WHERE `username` = '$ban'") or die ('Error during the execution of the MySQL query : ' . mysql_error());

$query = mysql_query("INSERT INTO `ban` (`id` , `username` , `time`) VALUES ('', '$ban', '$days-$date')") or die ('Error during the execution of the MySQL query : ' . mysql_error());

$alert = mysql_query("UPDATE `users` SET `alert` = 'You have been banned and can no longer use the Site' WHERE `username` = '$user'") or die ('Error during the execution of the MySQL query : ' . mysql_error());
}
}else{Right or wrong?
You need the implode statement, like I posted, BEFORE sql queries. But yes, $ban is the username.

xRoyal15
11-11-2006, 10:11 AM
YAY thanks, it works :)

Jackboy
11-11-2006, 12:51 PM
Rofl i see ur doing what HabboRemix have done.

Good luck with it ;)

xRoyal15
11-11-2006, 01:02 PM
;o what have they done?

Jackboy
11-11-2006, 01:10 PM
Those functions.

They got:

:ban
:mute
:roommute

xRoyal15
11-11-2006, 02:16 PM
:roommute... mm good idea

But i would like to remind you, habbo also have them.. so why you say habboremix's idea i dont see....

Dentafrice1
11-11-2006, 02:19 PM
Go ahead and use their ideas.. I don't care anymore :P

xRoyal15
11-11-2006, 02:20 PM
Im not using their ideas....

Dentafrice1
11-11-2006, 02:22 PM
True.. but tbh they had everything like this before alot of you.

1. Habbbo
^
Habbo Remix

xRoyal15
11-11-2006, 02:37 PM
Yer, they had a usersystem before me, but just because they did doesnt mean i took their ideas....

Mentor
11-11-2006, 02:47 PM
Wth? quick code functions in chats are prehistoric.... msgplus has had them since it first came out, it was avaible on IRC since before half of you were probably even born....

None of you have any claim to the idea of useing blabla: or simlar to initate a function "/ nore does habbo

Dentafrice1
11-11-2006, 02:54 PM
Agreed bag.

Hmm... make it have a smiley parser :) or:

:ban Dentafrice 2 (Two being the hours)
You would prob need a cron for that tho

Mentor
11-11-2006, 11:06 PM
Agreed bag.

Hmm... make it have a smiley parser :) or:

:ban Dentafrice 2 (Two being the hours)
You would prob need a cron for that tho

not realy, ud just set a time two hours in the future in unix time stamp to there row in the db, then check its past that time if they try to access, if not say threre banned "/

Splinter
12-11-2006, 03:35 PM
just change thing string from :ban name

to ban { name or something... then you can just explode the string and get be able to check the function and then then name..

xRoyal15
12-11-2006, 06:20 PM
Yer.. .problems kinda solved now :P

Want to hide these adverts? Register an account for free!