JavaScript变量未传入php标头脚本

时间:2019-05-30 06:23:52

标签: javascript php

我认为我已经接近了,但是,将javascript变量添加到我的PHP标头脚本中会导致页面暂停。我的php错误日志中只有警告。感谢您的帮助。

<script>   /*-GET DATE SCRIPT START */
var currentdate = new Date(); 
var local_year = "" + currentdate.getFullYear();   
var local_month = "" + ('0' + (currentdate.getMonth()+1)).slice(-2);
var local_day = "" + ('0' + (currentdate.getDate())).slice(-2);
var local_hours = "" + ('0' + (currentdate.getHours())).slice(-2);
var local_min = "" + ('0' + (currentdate.getMinutes())).slice(-2);
var local_sec = "" + ('0' + (currentdate.getSeconds())).slice(-2);

var local_year_var = document.getElementById("local_year").value;
var local_month_var = document.getElementById("local_month").value;
var local_day_var = document.getElementById("local_day").value;
var local_hours_var = document.getElementById("local_hours").value;
var local_min_var = document.getElementById("local_min").value;
var local_sec_var = document.getElementById("local_sec").value;

</script>

<?php

header("Location: https://my_php_page.php?p_shop_name=RCT+Estate+Sales
&cart_owner=" . $cart_owner . "&local_year="+local_year_var+"&local_month="+local_month_var+"&local_day="+local_day_var+"&local_hours="+local_hours_var+"&local_min="+local_min_var+"&local_sec="+local_sec_var+"&code_word=" . $code_word);

?>

1 个答案:

答案 0 :(得分:0)

尝试一下-

像这样

<script>   /*-GET DATE SCRIPT START */
var cart_owner = <?php echo $cart_owner; ?>;
var code_word = <?php echo $code_word; ?>;
var currentdate = new Date(); 
var local_year = "" + currentdate.getFullYear();   
var local_month = "" + ('0' + (currentdate.getMonth()+1)).slice(-2);
var local_day = "" + ('0' + (currentdate.getDate())).slice(-2);
var local_hours = "" + ('0' + (currentdate.getHours())).slice(-2);
var local_min = "" + ('0' + (currentdate.getMinutes())).slice(-2);
var local_sec = "" + ('0' + (currentdate.getSeconds())).slice(-2);

var local_year_var = document.getElementById("local_year").value;
var local_month_var = document.getElementById("local_month").value;
var local_day_var = document.getElementById("local_day").value;
var local_hours_var = document.getElementById("local_hours").value;
var local_min_var = document.getElementById("local_min").value;
var local_sec_var = document.getElementById("local_sec").value;


    window.location.href = 'https://my_php_page.php?p_shop_name=RCT+Estate+Sales
&cart_owner='+cart_owner+'
&local_year='+local_year_var+'
&local_month='+local_month_var+'
&local_day='+local_day_var+'
&local_hours='+local_hours_var+'
&local_min='+local_min_var+'
&local_sec='+local_sec_var+'
&code_word='+code_word+';
</script>