2016-11-20 174 views
0

我应该做重定向到另一个网页?我在评论中有失败的尝试。重定向到另一个页面PHP

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; 

回答

1

使用

header("Location: ".$website); 

重定向到其他页面。

看到:http://php.net/manual/en/function.header.php

编辑:后你解释,你想要一个按钮,将做到这一点的onclick。到按钮的onclick命令当你点击按钮来重定向

window.location.href = "http://www.productionportugal.com/blog"; 

您可以添加该代码。

+0

我试过这个,但它指派的功能,如主页$ website =“http://www.productionportugal.com/blog”; header(“Location:”。$ website); –

+0

尝试写这样的:标题(“位置:http://www.productionportugal.com/blog”);你会得到什么错误? – itay

+0

它会假设像一个网页的链接,我要的就是按一下按钮,然后转到外部页面。 –

0

你发送一个报头,与您的目标url

<?php 
$newUrl = "http://www.productionportugal.com/blog"; 
header('Location: '.$newURL); 
?> 

就这么简单。

注意它会给出一个错误,如果头已经发送。这里是一个详细的答案是如何工作的:headers

+0

这个显示em空白页。 –

+0

比你的'url'只是一个空白页。 – Nytrix

0

如果我理解正确你的问题比下面的代码将有助于:

header("Location: http://www.example.com/"); 

您可以提交任何URL

参考:http://php.net/manual/en/function.header.php

另请注意,标题必须出现在任何输出之前的代码

+0

它会假设链接像一个主页,我想要的只是按一个按钮,并转到外部页面.. –

0

这应该sol有你的问题。
按下按钮时,该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> 
相关问题