رفتن به مطلب

درخواست یک آرایه php خیلی ساده


پست های پیشنهاد شده

سلام و خسته نباشید

من نیاز به یک کد دارم که کارش این باشه

مثلا اگر توی آدرس سایت کلمه پدر باشه انتقال داده بشه به یک صفحه دیگه

مثلا من بیام یک آرایه این جوری بسازم :


$FILTERWORDS = array('پدر',مادر');

حالا بیام آدرس سایت رو چک کنم با یه شرط که اگر کلمه هایی که تو آرایه گذاشتم مثلا پدر و مادر و ... ، اگر اینا تو آدرس بودن ریدایرکت بشه به یه جا دیگه

مثلا آدرس سایت تو مرورگر اگر این بود :


site.ir/post/پدر.html

انتقال داده بشه به site.com/khata.html

یعنی هر کلمه ای که تو آرایه من گذاشتم اگر تو آدرس بار مرورگر بود انتقال داده بشه

میشه این کارو کرد ؟

لینک به ارسال

<?php
$FILTERWORDS = array('پدر','مادر');
$redirect = 'http://site.com/khata.html';

$target = explode ( '.' , end ( explode( '/', $_SERVER['REQUEST_URI']) ) );
if ( in_array( $target[0] , $FILTERWORDS )) {

if ( ! headers_sent() ) {
header('Location: ' . $redirect ); exit;
}
else {
echo "<script type='text/javascript'>window.onload = function () { top.location.href = '" . $redirect . "'; };</script>"; exit;
}


}

  • امتیاز 6
لینک به ارسال
 window.onload = function () { top.location.href = '" . $redirect . "'; };"; exit; } } 

تشکر

ولی هیچ تغییری نمیکنه و اون کلمه ها اگر تو آدرس باشن بازم سایت میاد و انتقال پیدا نمیکنه

لینک به ارسال

خب بستگی داره چطور و کجا استفاده کرده باشید کد رو ؟

برای وردپرس اگه هستش بزارید به اکشن init هوکش کنید .

  • امتیاز 1
لینک به ارسال

میتونین از کد زیر استفاده کنید

$FILTERWORDS = array('پدر','مادر');
$redirect = 'http://site.com/khata.html';

$targets = $_SERVER['REQUEST_URI'] ;
foreach($FILTERWORDS as $WORDS)
{
if ( strpos($WORDS, $targets) !== FALSE)
header('Location: ' . $redirect ); exit;
}

  • امتیاز 1
لینک به ارسال

خب بستگی داره چطور و کجا استفاده کرده باشید کد رو ؟

برای وردپرس اگه هستش بزارید به اکشن init هوکش کنید .

نه وردپرس نیست

میتونین از کد زیر استفاده کنید

$FILTERWORDS = array('پدر','مادر');
$redirect = 'http://site.com/khata.html';

$targets = $_SERVER['REQUEST_URI'] ;
foreach($FILTERWORDS as $WORDS)
{
if ( strpos($WORDS, $targets) !== FALSE)
header('Location: ' . $redirect ); exit;
}

تشکر کار نکرد و صفحه سفید میشه و اگر اون exit رو حذف کنم سایت میاد و هیچ تغییری نکرده با قبل

ببینید من سایتم مثلا یک صفحه الان میاره به این شکل :


http://site.ir/post/ژل+لاغری

حالا میخوام اگر کلمه ژل یا لاغری تو آدرس بار بود انتقال داده بشه

صفحه ایندکس من اینه ببینید :


<?php

ob_start();
include 'dataload.php';
/********/
ini_set("display_errors","0");
ini_set("register_globals","0");

/********/
$pageid = isset($_GET['pageid'])?intval($_GET['pageid']):'1';

$servername = strtolower($_SERVER['SERVER_NAME']);
$servername = (substr($servername,0,4) == 'www.')?substr($servername,4):$servername;
/*
//visit
$res=mysql_query("update `amar` set `count`=count+1 where `date`='".date("Y-m-d")."' limit 1;");
if(mysql_affected_rows()!=1){
mysql_query("INSERT INTO `amar` (`id`, `date`, `count`, `click`) VALUES (NULL, '".date("Y-m-d")."', '1', '0');");
}
*/
#------
if(preg_match('#([a-z0-9-]+?)\.site\.ir#i', $servername, $blogname)){
if(isset($_GET['id']) ){
$res=mysql_query("select id,username from `feeds` where `id`=(select fid from `news_tmp` where `id`=$_GET[id]) limit 1");
if(mysql_num_rows($res)>0){
list($id,$username)=mysql_fetch_array($res);
if($blogname[1]!=$username){
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://$username.site.ir/index-$_GET[id]" );
exit;
}
}
}
$username=$blogname[1];
$res=mysql_query("select id,title from `feeds` where `username`='{$blogname[1]}'");
if(mysql_num_rows($res)>0){
list($id,$title)=mysql_fetch_array($res);
$res=mysql_query("select `title`,`text`,`date`,`keywords` from `news_tmp` where `fid`=$id ".(isset($_GET['id'])?"and `id`=$_GET[id] ":'')." /*order by `date` DESC*/");
while($row=mysql_fetch_assoc($res)){
if(isset($_GET['id']))$title=$row['title'];
?>
<div class="post-title">
<div class="post-title-space">
<h1><span lang="fa"><?=$row['title'];?></span></h1>
</div>
<div id="post-content">
<div class="post-content-text">
<div class="style2">
<span lang="fa"><?=$row['text'];?></span>
</div>
<div class="clear"></div>
<div class="clear"></div>
</div>
</div>
<div id="post-footer"></div>
</div>
<?
}
}else{
echo 'user not found in feed.';
}
}
else
{
if(isset($_GET['id']) ){
$res=mysql_query("select id,username from `feeds` where `id`=(select fid from `news_tmp` where `id`=$_GET[id]) limit 1");
if(mysql_num_rows($res)>0){
list($id,$username)=mysql_fetch_array($res);
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://$username.site.ir/index-$_GET[id]" );
exit;
}
}
$res=mysql_query("select `title`,`id` from `news_tmp` order by `date` DESC limit 200");
if(mysql_num_rows($res)>0){
echo '<ul>';
while($row=mysql_fetch_assoc($res)){
echo "<li><a href=\"index-$row[id]\" target=\"_blank\">$row[title]</a></li>\n";
}
echo '</ul>';
}
echo 'user not found.';
}
$out_html=ob_get_clean();
include 'tmp.php';
?>

ویرایش شده توسط beh9am
لینک به ارسال

این کد تست شده

$FILTERWORDS = array('پدر','آرایه');
$redirect = 'http://site.com/khata.html';
$targets = rtrim($_SERVER['REQUEST_URI']) ;
$targets = urldecode(substr($targets,strrpos($targets, '/')+1));
foreach($FILTERWORDS as $WORDS)
{
if ( strpos($targets,$WORDS) !== FALSE)
die(header("Location: $redirect"));
}

  • امتیاز 2
لینک به ارسال
  • 3 هفته بعد...

این کد تست شده

$FILTERWORDS = array('پدر','آرایه');
$redirect = 'http://site.com/khata.html';
$targets = rtrim($_SERVER['REQUEST_URI']) ;
$targets = urldecode(substr($targets,strrpos($targets, '/')+1));
foreach($FILTERWORDS as $WORDS)
{
if ( strpos($targets,$WORDS) !== FALSE)
die(header("Location: $redirect"));
}

تشکر عالی بود و دارم استفاده میکنم

حالا یک مشکل

این کد برای بعد از دامین هست و برای ساب دومین کار نمیکنه

الان اگر بخوام مثلا اینارم بزارم باید چیکار کنم ؟


http://ali.site.com
http://hasan.site.com
http://sohrab.site.com
http://rostam.site.com

مثلا وقتی رفتیم به آدرس sohrab.site.com هم مثل کد بالا انتقال داده بشه به اون آدرس

لینک به ارسال

لطفا برای ارسال دیدگاه وارد شوید

شما بعد از اینکه وارد حساب کاربری خود شدید می توانید دیدگاهی ارسال کنید



ورود به حساب کاربری
×
×
  • اضافه کردن...