【发布时间】:2016-02-12 11:11:41
【问题描述】:
在发现为什么我的网站没有通过 header 命令重定向后,我发现了另一个问题。问题是我想将一些变量放入 url 重定向中,即在 javascript 中。这是我的代码的一部分:
<?php
$cost = 200
$name = 'Bill'
$url_endpoint = 'https://example.com/item1='.$cost.'&n='.$name.'.html';
if( !headers_sent() ) {
header("Location: $url_endpoint");
}
else {
?>
<script type="text/javascript">
document.location.href="$url_endpoint"; //That's just example what I want
</script>
Redirecting to <a href="$url_endpoint">site.</a> //Same here
<?php
}
die();
exit;
} // ?
?>
对初学者有什么想法/提示吗?
【问题讨论】:
-
您需要将 php 变量回显到 javascript 中。
document.location.href='<?php echo $url_endpoint;?>';
标签: javascript php html variables url