2016-11-20 172 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> 
相關問題