[英]Redirect to another page PHP
what i should do to redirect to another page? 我应该怎么做才能重定向到另一个页面? what i have in comments are failed tries.
我评论中的内容是失败的尝试。
case 6:
//$redirectLocation = "http://www.productionportugal.com/blog";
// header'Location: ' . $redirectLocation); assume it like homepage
//include '/blog/index.php';
//include 'blog/index.php'; database error
//ini_set('include_path', '/blog');
//set_include_path('/blog');
// include_path=".:/blog" white page
// include="/blog/index.php"
// $redirectLocation = "http://www.productionportugal.com/blog";
require_once dirname(__FILE__) . '/Blog.php';
$_blog = new Blog();
$menuL = $_blog->getMenu();
$conteudo = "<div class='container' id='blogMenu'>
<div class='titulo'>$nome
<div class='btn-group'>
<a href='#' data-toggle='dropdown' id='dropdownBlog'>
<span class='caret'></span>
</a>
<ul class='dropdown-menu' aria-labelledby='dropdownBlog' role='menu'>
$menuL
</ul>
</div>
<a class='sprite leftS' id='prevLatestBlog'></a><a class='sprite rightS' id='nextLatestBlog'></a></div>
</div>";
$conteudo .= $_blog->getALL();
break;
use 采用
header("Location: ".$website);
to redirect to other pages. 重定向到其他页面。
see: http://php.net/manual/en/function.header.php 参见: http : //php.net/manual/en/function.header.php
Edit: After you explain that you want a button that will do it onclick. 编辑:解释完后,您需要一个可以在onclick上执行的按钮。
You can add this code: 您可以添加以下代码:
window.location.href = "http://www.productionportugal.com/blog";
to the button onclick command to redirect when you click on button. 到按钮onclick命令,以在您单击按钮时重定向。
You send a header, with your destination url
. 您将发送标头以及目标
url
。
<?php
$newUrl = "http://www.productionportugal.com/blog";
header('Location: '.$newURL);
?>
It's as easy as that. 就这么简单。
Note it will give an error if the headers are already send. 请注意 ,如果已发送标头,则会出现错误。 Here is a detailed answer to how that works: headers
这是如何工作的详细答案: 标头
If I have understood your question correctly than the below code will help: 如果我对您的问题的理解正确,那么以下代码将有所帮助:
header("Location: http://www.example.com/");
You can submit any url 您可以提交任何网址
Reference: http://php.net/manual/en/function.header.php 参考: http : //php.net/manual/en/function.header.php
Also please note that header must appear in code before any output 还请注意,标头必须在任何输出之前出现在代码中
This should solve your problem. 这应该可以解决您的问题。
When pressing the button, the url will open as a new tab, without closing the current page you pressed the button on. 按下按钮时,URL将作为新标签页打开,而不会关闭您按下按钮时所在的当前页面。
<!--HTML-->
<button type="submit" onclick="openExt('URL GOES IN HERE')"></button>
<!--JavaScript-->
<script type="text/javascript">
function openExt(url) {
window.open(url, "_blank");
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.