با سلام . . .
دوستان کدی می خواهم از php باشه ، که اجازه کاربرد از یک کلمه یا حرف مانند @ رو نده و اگر کسی برای مثال @ را در فیلد خالی تایپ یا کپی ، پِیست کند ، اجازه اجرا آن را ندهـــد . . .
با تشکـــر . . .
با سلام . . .
دوستان کدی می خواهم از php باشه ، که اجازه کاربرد از یک کلمه یا حرف مانند @ رو نده و اگر کسی برای مثال @ را در فیلد خالی تایپ یا کپی ، پِیست کند ، اجازه اجرا آن را ندهـــد . . .
با تشکـــر . . .
این جور چیزها رو معمولاً با جاوا اسکریپت انجام میدن. خیلی هم کاربر پسند تر هست و باعث کاهش فشار رو سرور هم میشه.
با php کاربر باید فرم رو ثبت کنه ، فرم به سرور ارسال بشه ، بررسی بشه و درصورت وجود خطا به کاربر اعلام بشه
اما با جاوا اسکریپت به محض اینکه کاربر اقدام به ثبت فرم کنه ، قبل از ارسال به سرور ، داده وارد شده کاربر بصورت کلاینت ساید بررسی میشه و بصورت آنی نتیجه آن (درصورت وجود خطا) به کاربر اعلام میشه.
و البته این برای مواردی بود که بخواهید به کاربر اخطار داده شود ، درصورتی که بخواهید کلاً کاربر نتواند حرف مورد نظرش را داخل کادر وارد کند (حرف مورد نظر اصلاً تایپ نشود) حتماً نیاز به جاوا اسکریپت هست...
برای php هم می تونید از این کد استفاده کنید :
این کد تمام حروف غیر از a تا z و اعداد رو از ورودی کاربر حذف می کنه ، خودتون این عبارت رو می تونید بصورت دلخواه تغییر بدید.کد:$var = preg_replace("/[^A-Za-z0-9]/", "", $var);
با ســلام . . .
جاوا رو که می دانیم اما در مرورگر موزیلا جاوا رو میشه غیر فعال کرد ، پس به درد نمی خورد . . .
اما php عالی است ، بنده نمی خواهم اصلا نشه تایپ کرد ؛ اصلا شخصی بیاید کلمه ای را که بنده ***** کرده ام را تایپ کند اما در زمان تایید آن کلمه اجرا نشود و یا خطا را نشان دهد . . .
برای برنامه نویســان حرفه ای فــکر نکنم سخـــت باشــد . . .
با تشــکر . . .
...
با ســلام . . .
جاوا رو که می دانیم اما در مرورگر موزیلا جاوا رو میشه غیر فعال کرد ، پس به درد نمی خورد . . .
اما php عالی است ، بنده نمی خواهم اصلا نشه تایپ کرد ؛ اصلا شخصی بیاید کلمه ای را که بنده ***** کرده ام را تایپ کند اما در زمان تایید آن کلمه اجرا نشود و یا خطا را نشان دهد . . .
برای برنامه نویســان حرفه ای فــکر نکنم سخـــت باشــد . . .
با تشــکر . . .
با سلام عالی است اما میشه الان شما در این کد خودتان کاری کنید تا از @ جلوگیری بشه ؟! . . .
با تشکر . . .
2- اینکه شاید بخواهیم کلمه a را جلوگیری کنیم آن موقع چی ؟
با تشکر . . .
در php با preg_replace معمولا انجام میدن
مثلا :
اینجا
a , b ,c , d با * عوض میشن
خروجی :کد PHP:
<?php
$text = "salam Chetori?";
$bad = array(
"!a!i",
"!b!i",
"!c!i",
"!d!i",
);
$text = preg_replace($bad,"*",$text);
echo $text;
?>
کد:s*l*m *hetori?
از دوستان که کد دادند خواهش دارم در کد خودشان @ را ف ی ل ت ر نمایند تا کاربر هنگام تایید ، @ اجــرا نشود . . . و در فایل زید به صورت صحیح قرار دهند تا کار بکند . . .
با تشکر :
کد PHP:
<?php
require( ".".DIRECTORY_SEPARATOR."app".DIRECTORY_SEPARATOR."boot.php" );
require_once( MODEL_PATH."msg.php" );
class GPage extends securegamepage
{
var $showList = NULL;
var $selectedTabIndex = NULL;
var $errorText = NULL;
var $receiver = NULL;
var $subject = NULL;
var $body = NULL;
var $messageDate = NULL;
var $messageTime = NULL;
var $showFriendPane = NULL;
var $friendsList = NULL;
var $viewOnly = NULL;
var $isInbox = NULL;
var $sendMail = NULL;
var $dataList = NULL;
var $pageSize = 10;
var $pageCount = NULL;
var $pageIndex = NULL;
var $seckeyB = NULL;
var $time = 0;
var $seckey;
public function GPage( )
{
parent::securegamepage( );
$this->viewFile = "msg.phtml";
$this->contentCssClass = "messages";
}
public function load( )
{
parent::load( );
$this->pageSize = $this->data['active_plus_account'] ? $this->data['per_page'] : 10;
mysql_connect($this->appConfig['db']['host'],$this->appConfig['db']['user'],$this->appConfig['db']['password']);
mysql_select_db($this->appConfig['db']['database']);
$q = mysql_query("SELECT last_msg from p_players where id='{$this->player->playerId}'");
$q = mysql_fetch_array($q);
$this->time = $q['last_msg'];
@$this->seckeyB = $_SESSION['security'];
$this->sendMail = TRUE;
$this->isInbox = TRUE;
$this->viewOnly = FALSE;
$this->showFriendPane = FALSE;
$this->errorText = "";
$this->showList = !( isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) && intval( $_GET['t'] ) == 1 );
$this->selectedTabIndex = isset( $_GET['t'] ) && is_numeric( $_GET['t'] ) && 1 <= intval( $_GET['t'] ) && intval( $_GET['t'] ) <= 2 ? intval( $_GET['t'] ) : 0;
$this->friendList = array( );
$friends_player_ids = trim( $this->data['friend_players'] );
if ( $friends_player_ids != "" )
{
$friends_player_ids = explode( "\n", $friends_player_ids );
foreach ( $friends_player_ids as $friend )
{
list( $playerId, $playerName ) = explode( " ", $friend );
$this->friendList[$playerId] = $playerName;
}
}
$m = new MessageModel( );
if ( !$this->isPost( ) )
{
if ( isset( $_GET['uid'] ) && is_numeric( $_GET['uid'] ) && 0 < intval( $_GET['uid'] ) )
{
$this->receiver = $m->getPlayerNameById( intval( $_GET['uid'] ) );
$this->showList = FALSE;
$this->selectedTabIndex = 1;
}
else if ( isset( $_GET['id'] ) && is_numeric( $_GET['id'] ) && 0 < intval( $_GET['id'] ) )
{
$result = $m->getMessage( $this->player->playerId, intval( $_GET['id'] ) );
if ( $result->next( ) )
{
$this->viewOnly = TRUE;
$this->showList = FALSE;
$this->isInbox = $result->row['to_player_id'] == $this->player->playerId;
$this->sendMail = !$this->isInbox;
$this->receiver = $this->isInbox ? $result->row['from_player_name'] : $result->row['to_player_name'];
$this->subject = $result->row['msg_title'];
$this->body = $this->getFilteredText( $result->row['msg_body'] );
$this->messageDate = $result->row['mdate'];
$this->messageTime = $result->row['mtime'];
$this->selectedTabIndex = $this->isInbox ? 0 : 2;
if ( $this->isInbox && !$result->row['is_readed'] && !$this->player->isSpy )
{
$m->markMessageAsReaded( $this->player->playerId, intval( $_GET['id'] ) );
--$this->data['new_mail_count'];
}
}
else
{
$this->showList = TRUE;
$this->selectedTabIndex = 0;
}
$result->free( );
}
}
else if ( isset( $_POST['sm'] ))
{
$this->receiver = trim( $_POST['an'] );
$this->subject = trim( $_POST['be'] );
$this->seckey = trim($_POST['seckey']);
$this->body = $_POST['message'];
if ( trim( $this->receiver ) == "" )
{
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->errorText = messages_p_noreceiver."<p></p>";
$m->dispose( );
} else if($this->message_ban == 1 && strtolower ( trim( $this->receiver ) ) != 'admin'){
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->errorText = msg_blocked."<p></p>";
$m->dispose( );
}
else
{
if ( trim( $this->body ) == "" )
{
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->errorText = messages_p_nobody."<p></p>";
$m->dispose( );
} elseif(empty($this->seckey)){
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->errorText = messages_p_secempty."<p></p>";
$m->dispose( );
}
elseif($this->seckey != $this->seckeyB){
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->errorText = messages_p_sec."<p></p>";
$m->dispose( );
}
else
{
if ( strtolower( trim( $this->receiver ) ) == "[sendtomem]" && 0 < intval( $this->data['alliance_id'] ) && $this->hasAllianceSendMessageRole( ) )
{
$pids = trim( $m->getAlliancePlayersId( intval( $this->data['alliance_id'] ) ) );
if ( $pids != "" )
{
if ( $this->subject == "" || preg_match( "/[>,\\. \\n\\r\\t\\s]+/", $this->subject ) || preg_match( "/[<,\\. \\n\\r\\t\\s]+/", $this->subject ))
{
$this->subject = messages_p_emptysub;
}
$arr = explode( ",", $pids );
foreach ( $arr as $apid )
{
if ( $apid == $this->player->playerId )
{
continue;
}
if($this->message_ban == 0 & $this->time < time()){
$time = time()+(1*60);
mysql_query("UPDATE p_players SET `last_msg`='$time' WHERE `id`='{$this->player->playerId}'");
$m->sendMessage( $this->player->playerId, $this->data['name'], $apid, $m->getPlayerNameById( $apid ), $this->subject, $this->body );
}
}
$this->showList = TRUE;
$this->selectedTabIndex = 2;
}
}
else
{
$receiverPlayerId = $m->getPlayerIdByName( $this->receiver );
if ( 0 < intval( $receiverPlayerId ) )
{
if ( $receiverPlayerId == $this->player->playerId )
{
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->errorText = "<b>".messages_p_noloopback."</b><p></p>";
}
else
{
if ( $this->subject == "" || preg_match( "/[>,\\. \\n\\r\\t\\s]+/", $this->subject ) || preg_match( "/[<,\\. \\n\\r\\t\\s]+/", $this->subject ))
{
$this->subject = messages_p_emptysub;
}
if($this->message_ban == 0 & $this->time < time()){
$time = time()+(0.5*60);
mysql_query("UPDATE p_players SET `last_msg`='$time' WHERE `id`='{$this->player->playerId}'");
$m->sendMessage( $this->player->playerId, $this->data['name'], $receiverPlayerId, $this->receiver, $this->subject, $this->body );
}
$this->showList = TRUE;
$this->selectedTabIndex = 2;
}
}
else
{
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->errorText = messages_p_notexists." <b>".$this->receiver."</b><p></p>";
}
}
}
}
}
else if ( isset( $_POST['fm'] ) )
{
$this->receiver = trim( $_POST['an'] );
$this->subject = trim( $_POST['be'] );
$this->body = $_POST['message'];
$this->showList = FALSE;
$this->selectedTabIndex = 1;
$this->showFriendPane = TRUE;
if ( $_POST['fm'] != "" && is_numeric( $_POST['fm'] ) )
{
$playerId = intval( $_POST['fm'] );
if ( 0 < $playerId && isset( $this->friendList[$playerId] ) )
{
unset( $this->friendList[$playerId] );
}
}
else if ( isset( $_POST['mfriends'] ) )
{
foreach ( $_POST['mfriends'] as $friendName )
{
$friendName = trim( $friendName );
if ( $friendName == "" )
{
continue;
}
$playerId = intval( $m->getPlayerIdByName( $friendName ) );
if ( 0 < $playerId && !isset( $this->friendList[$playerId] ) && $playerId != $this->player->playerId )
{
$this->friendList[$playerId] = $friendName;
}
}
}
$friends = "";
foreach ( $this->friendList as $k => $v )
{
if ( $friends != "" )
{
$friends .= "\n";
}
$friends .= $k." ".$v;
}
$m->saveFriendList( $this->player->playerId, $friends );
}
else if ( isset( $_POST['rm'] ) )
{
$this->receiver = trim( $_POST['an'] );
$this->subject = trim( $_POST['be'] );
$this->body = PHP_EOL.PHP_EOL."_________________________________".PHP_EOL.text_from_lang." ".$this->receiver.":".PHP_EOL.PHP_EOL.$_POST['message'];
preg_match( "/^(RE)\\^?([0-9]*):([\\w\\W]*)\$/", $this->subject, $matches );
if ( sizeof( $matches ) == 4 )
{
$this->subject = ( "RE^".( $matches[2] + 1 ) ).":".$matches[3];
}
else
{
$this->subject = "RE: ".$this->subject;
}
$this->showList = FALSE;
$this->selectedTabIndex = 1;
}
else if ( isset( $_POST['dm'] ) && isset( $_POST['dm'] ) )
{
foreach ( $_POST['dm'] as $messageId )
{
if ( $m->deleteMessage( $this->player->playerId, $messageId ) )
{
--$this->data['new_mail_count'];
}
}
}
if ( $this->showList )
{
$rowsCount = $m->getMessageListCount( $this->player->playerId, $this->selectedTabIndex == 0 );
$this->pageCount = 0 < $rowsCount ? ceil( $rowsCount / $this->pageSize ) : 1;
$this->pageIndex = isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) && intval( $_GET['p'] ) < $this->pageCount ? intval( $_GET['p'] ) : 0;
$this->dataList = $m->getMessageList( $this->player->playerId, $this->selectedTabIndex == 0, $this->pageIndex, $this->pageSize );
if ( 0 < $this->data['new_mail_count'] )
{
$this->data['new_mail_count'] = $m->syncMessages( $this->player->playerId );
}
}
$m->dispose( );
}
public function getFilteredText( $text )
{
require_once( MODEL_PATH."wordsfilter.php" );
$filter = new FilterWordsModel( );
return $filter->FilterWords( $text );
}
public function _hasAllianceRole( $role )
{
$alliance_roles = trim( $this->data['alliance_roles'] );
if ( $alliance_roles == "" )
{
return FALSE;
}
list( $roleNumber, $roleName ) = $alliance_roles;
return $roleNumber & $role;
}
public function hasAllianceSendMessageRole( )
{
return $this->_hasAllianceRole( ALLIANCE_ROLE_SENDMESSAGE );
}
public function preRender( )
{
parent::prerender( );
if ( isset( $_GET['uid'] ) )
{
$this->villagesLinkPostfix .= "&uid=".intval( $_GET['uid'] );
}
if ( isset( $_GET['id'] ) )
{
$this->villagesLinkPostfix .= "&id=".intval( $_GET['id'] );
}
if ( isset( $_GET['p'] ) )
{
$this->villagesLinkPostfix .= "&p=".intval( $_GET['p'] );
}
if ( 0 < $this->selectedTabIndex )
{
$this->villagesLinkPostfix .= "&t=".$this->selectedTabIndex;
}
}
public function getNextLink( )
{
$text = "»";
if ( $this->pageIndex + 1 == $this->pageCount )
{
return $text;
}
$link = "";
if ( 0 < $this->selectedTabIndex )
{
$link .= "t=".$this->selectedTabIndex;
}
if ( $link != "" )
{
$link .= "&";
}
$link .= "p=".( $this->pageIndex + 1 );
$link = "msg.php?".$link;
return "<a href=\"".$link."\">".$text."</a>";
}
public function getPreviousLink( )
{
$text = "«";
if ( $this->pageIndex == 0 )
{
return $text;
}
$link = "";
if ( 0 < $this->selectedTabIndex )
{
$link .= "t=".$this->selectedTabIndex;
}
if ( 1 < $this->pageIndex )
{
if ( $link != "" )
{
$link .= "&";
}
$link .= "p=".( $this->pageIndex - 1 );
}
if ( $link != "" )
{
$link = "?".$link;
}
$link = "msg.php".$link;
return "<a href=\"".$link."\">".$text."</a>";
}
}
$p = new GPage( );
$p->run( );
?>
ویرایش توسط warpro : October 20th, 2013 در ساعت 02:07
کمپین یاد آوری زبان فارسی به وب هاستینگ تالک !
چگونه از هاست / سرور مجازی خود شکایت کنیم؟ (طنز) http://www.webhostingtalk.ir/f118/92986/----------------------------------------------------------
در حال حاضر 1 کاربر در حال مشاهده این موضوع است. (0 کاربران و 1 مهمان ها)