Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress插件重定向_Php_Wordpress - Fatal编程技术网

Php Wordpress插件重定向

Php Wordpress插件重定向,php,wordpress,Php,Wordpress,所以我有一个wordpress插件,它可以像 [randomurl] 变成 <a href="/wp-content/plugins/randomurl/random.php">Random</a> 标签。由于我是wordpress插件编程新手,我不知道是否有更好的方法,但我对其他解决方案持开放态度。在random.php文件中,选择一个随机url,并将用户引用该url。(我无法将url直接放入a标签中,因为它每次都需要加载一个列表)。random.php的外观如

所以我有一个wordpress插件,它可以像

[randomurl]
变成

<a href="/wp-content/plugins/randomurl/random.php">Random</a>

标签。由于我是wordpress插件编程新手,我不知道是否有更好的方法,但我对其他解决方案持开放态度。在random.php文件中,选择一个随机url,并将用户引用该url。(我无法将url直接放入a标签中,因为它每次都需要加载一个列表)。random.php的外观如下所示:

<?php
$content = file_get_contents('http://example.com/urls.php');
$urls = json_decode($content);
$theURL = $urls[rand(0,10)];
header('Location: '.$theURL);
?>


问题是由于wordpress的重写规则,我无法访问random.php。有没有更好的方法来完成这一切?是否必须禁用重写引擎?

重写规则不会阻止您访问该文件(如果该文件确实存在)。但是,我强烈建议不要在插件中提供文件的url。取而代之的是,在插件中将该功能带到您的站点中,并调用该功能。链接的作用是什么?random.php的目的/内容是什么?您如何处理这些链接?显示它们?请讲清楚。您的意思是:(1)从random.php加载信息,它(2)使用header()将用户重定向到url?你为什么不首先在元素中显示随机链接,而不是这个旋转?然后这样做:(1)在你的插件中,让链接加载博客url,url中有一个参数:
www.myblog.com/?random=true
-然后(2)在你的插件中,在
init
操作中,注意
$\u GET['random']
,如果已设置,则(3)执行您在random.php中正在执行的工作(不要调用/加载random.php,将函数移动到此处执行工作,包括header()重定向)