2017-01-18 24 views
0

我的網站有一個像不同國家的網站佈局不同的選項。它在會話的基礎上運行,如果沒有設置會話,用戶將被重定向到索引以選擇一個國家,然後將從他原來來自的頁面重定向。這裏是包含在每個文件除了指數javascript在重定向期間缺少一個url參數

<?php 
session_start(); 
if(!isset($_SESSION['country'])) 
{ 
    $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 
    header("location:index.php?return_uri=$actual_link"); 
} 
?> 

現在發生了什麼代碼

session_check_client.php文件,當我回到主頁我想檢查該請求是否有一些返回參數或只是用戶第一次訪問他的網站。有兩個按鈕可供我顯示代碼的兩個國家/地區使用。

function canada(){ 
    $.ajax({ 
     type: 'post', 
     url: 'ajax_country.php?country=canada', 
     success: function (data) { 
      var $_GET = <?php echo json_encode($_GET);?>; 
      if($_GET){ 
      //window.location.href=$_GET['return_uri']; 
      alert($_GET['return_uri']); 
      } 
      else { 
       window.location.href = "home.php"; 
      } 
     } 
    }); 
} 
function us(){ 
    $.ajax({ 
     type: 'post', 
     url: 'ajax_country.php?country=us', 
     success: function (data) { 
      var $_GET = <?php echo json_encode($_GET);?>; 
      if($_GET){ 
       //window.location.href=$_GET['return_uri']; 
       alert($_GET['return_uri']); 
      } 
      else { 
       window.location.href = "home.php"; 
      } 
     } 
    }); 
} 

現在的問題是,當我提醒的$_GET['return_uri']價值它給我一個假值

如我return_uri值http://localhost/interfold/products2.php?category=Aprons&id=57725599688它實際上表明在return_uri在索引頁一樣http://localhost/interfold/products2.php?category=Aprons&id=57725599688整體價值,但當使用JavaScript獲取url值時,它只會給我值http://localhost/interfold/products2.php?category=Aprons它缺少$和之後的部分!任何建議?

+1

在一個旁註,你應該避免重複的代碼通過合併加拿大()和我們()功能爲一個可能的參數爲國 –

+0

完全同意的一個功能!一旦問題得到解決,我將重新修改它 –

+0

您是否真的需要$ actual_link作爲$ _GET參數?它也可能是另一種解決方案嗎? –

回答

0

既然你只使用超級全局變量,可以直接打印功能之上的JS變量你所描述的:

var actual_link = "<?php echo "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>"; 

function postCountry(country){ 
    $.ajax({ 
     type: 'post', 
     url: 'ajax_country.php?country=' + country, 
     success: function (data) { 
      if(actual_link){ 
       //window.location.href=actual_link; 
       alert(actual_link); 
      } 
      else { 
       window.location.href = "home.php"; 
      } 
     } 
    }); 
} 

postCountry('us'); 
postCountry('canada'); 
+0

空指令! !有兩個文件讓想我從正在添加FileA.php到index.php我設置我的超級全球在FileA.php然後返回網址索引,PHP你正在做的是獲取URL中的index.php這不正確 –