我一直在嘗試從這個javascript中使用「user」變量,以便我可以在我的php腳本中使用它。我想在php腳本中回顯用戶變量。我無法這樣做,因爲我一直在試圖echo $ user; 。我也無法在網上找到任何東西來幫助我。在PHP中使用javascript var
alert("Welcome again " + user);
相反警戒我想在屏幕上打印歡迎再次的用戶(用戶名) 謝謝
<!DOCTYPE html>
<html>
<head>
<script>
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function checkCookie() {
var user=getCookie("username");
if (user != "") {
alert("Welcome again " + user);
} else {
user = prompt("Please enter your name:","");
if (user != "" && user != null) {
setCookie("username", user, 30);
}
}
}
</script>
<?php echo "Welcome back : ".$user;?>
</head>
<body onload="checkCookie()">
</body>
</html>
請解釋一下你的迴音是什麼意思?回聲是一個PHP命令,警報是JavaScript。從來沒有兩個人會遇到 – RiggsFolly
對不起,我已編輯我的問題 – xenon