如何使用referer检查将重定向放在php模板前面?
我的(wordpress)子主题文件夹中有一个模板,用于我创建的自定义帖子类型。看起来是这样的:如何使用referer检查将重定向放在php模板前面?,php,wordpress,http-referer,referer,Php,Wordpress,Http Referer,Referer,我的(wordpress)子主题文件夹中有一个模板,用于我创建的自定义帖子类型。看起来是这样的: <head> … <style> … </style> <script> … </script> </head> <header> … </header> <?php … ?> <div id=
<head>
…
<style>
…
</style>
<script>
…
</script>
</head>
<header>
…
</header>
<?php
…
?>
<div id="content">
<?php xx_page_header($post->ID); ?>
…
</div>
<?php get_footer(); ?>
假设(过滤)起始页是:www.mywebpage.com/startpage/
我必须如何组合这些片段以及将其放在何处(我猜是在模板的开头)
我想避免吃饼干。(使用referer)从技术上讲,您可以执行类似于下面代码的操作。起始页之后的每个页面必须具有唯一的URL和在每个页面上传递的令牌。您需要将此代码放在模板的最顶端 类似的东西:
<?php
$url='url_redirect';
if((is_page('template2') || is_page('template3') || is_page('template4')) && $_POST['token'] == '') {
header('Location: '.$url);
}
?>
在起始页上是否传递了POST变量?坦白说,我不知道。知道这一点很重要吗?是的,因为您需要一个变量来检查起始页中的变量是否已设置。您是指cookie吗?否。这4个页面中的每个页面是否都有自己唯一的URL?在起始页上有一个表单?在这个概念中,我仍然在为如何创建和传递令牌而挣扎。我读到了wordpress的新闻。他们在这里有用吗?我使用一个模板为4个不同的页面。
ref.match(/^http?:\/\/([^\/]+\.)?mywebpage\.com(\/|$)/i)
<?php
$url='url_redirect';
if((is_page('template2') || is_page('template3') || is_page('template4')) && $_POST['token'] == '') {
header('Location: '.$url);
}
?>