簡體   English   中英

如何將變量從 PHP 傳遞到 Javascript 重定向

[英]How to pass variables from PHP to Javascript redirect

我已經整理了這個簡短的小代碼,它應該從“url.txt”中隨機選擇一個 url,然后通過 javascript 重定向重定向它。 無論出於何種原因,我都無法讓它工作。 I'm aware of how to get it to work with other forms of redirection including meta refresh and php header, however I would like to know how to do with with javascript redirection.

<?php 
   $loadlist = explode("\n", file_get_contents('urls.txt'));
   $rand = rand(0,count($loadlist)-1);
   $picked = $loadlist[$rand];
?>
<html>
<head>
<script type='text/javascript'>
  window.location.href = '<?php echo $picked ?>'
</script>
</head>
</html>
<?php 
   $loadlist = explode("\n", file_get_contents('urls.txt'));
   $rand = rand(0,count($loadlist)-1);
   $picked = $loadlist[$rand];
?>
<html>
<head>
<script type='text/javascript'>
  window.location.replace("<?php echo $picked ?>");
</script>
</head>
</html>

嘗試這個

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM