【发布时间】:2017-06-13 03:17:04
【问题描述】:
我创建了一个脚本,该脚本将用作 Wordpress 的插件,其目的是获取页面视频的数据(视频标题、视频 url、拇指 url 和找到的总视频)。 我的插件有效,但脚本位于加载结果的同一页面上,因此它保留在 Wordpress 中。但是我想将负责搜索的脚本外部化,因为我真的不希望他们能够可视化我的 php 源代码。
所以我尝试将我的脚本分开,只放置 html 并使用“动作”表单调用脚本。 但我不知道如何将外部脚本的循环传递给本地表单,也不知道如何传递变量的值。我尝试使用“return”和“Header Location”,但它不起作用。
这是我目前拥有的:
索引.php:
<?php
if (isset($_POST['search'])){
$url = $_POST['keyword'];
$parse = "http://example1.com/?k=".$url;
$counter = 0;
$html = dlPage($parse); //dlPage is a function that uses "simple_html_dom"
include("form_results_footer.php"); // I include the header of the page with the results (this part is outside the loop because I do not want it to be repeated).
foreach ($html->find('something') as $values) {
//Here I run a series of searches on the page and get the following variables.
$counter++;
$title = //something value;
$linkvideo = //something value;
$thumburl = //something value;
include("form_results.php"); //The results of the "foreach" insert them into a separate php in "fieldsets".
}
$totalvideos = $counter;
include("form_results_footer.php"); //Close the form results
} else {
?>
<html>
<form action="" method="post">
<input id="keyword" name="keyword" type="text">
<button id="search" name="search">Search</button>
</form>
</html>
<?php
}
?>
好的,上面的代码可以正常工作,但我需要将获取变量的部分外包出去,我将收到它们的部分,如下所示:
->http://example.com/script.php
<?php
if (isset($_POST['search'])){
$url = $_POST['keyword'];
$parse = "http://example.com/?k=".$url;
$counter = 0;
$html = dlPage($parse); //dlPage is a function that uses "simple_html_dom"
foreach ($html->find('something') as $values) {
//Here I run a series of searches on the page and get the following variables.
$counter++;
$title = //something value;
$linkvideo = //something value;
$thumburl = //something value;
}
$totalvideos = $counter;
return $title;
return $linkvideo;
return $thumburl
}
?>
index.php
<html>
<form action="http://example.com/script.php" method="post">
<input id="keyword" name="keyword" type="text">
<button id="search" name="search">Search</button>
</form>
</html>
必须以与初始示例相同的方式在同一页面上收集循环结果。 希望大家能理解,先谢谢了。
【问题讨论】:
-
只是为了清除我的困惑,这两者都在您的插件目录中。对?还是在根文件夹中?
-
实际上,它们在插件目录中。是的,我所说的外部文件将位于不同的域中。
-
您可以为此使用 cURL,
-
我的脚本已经在使用 cURL 从“example1.com/?k=”页面获取数据。问题是如何获取托管在“example.com/script.php”的脚本生成的变量的值
标签: php wordpress forms plugins simple-html-dom