1
對不起,我幾乎拼命解決問題。我一直在尋找解決方案2周。如何使用PHP從HTML獲取表單內容?
我有一個JavaScript語法來查找IP地址。輸入文本的內容來自javascript,我想將它定義爲PHP中的變量。
window.onload = function() {
findIP(addIP);
}
function findIP(onNewIP) { // onNewIp - your listener function for new IPs
var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; //compatibility for firefox and chrome
var pc = new myPeerConnection({iceServers: []}),
noop = function() {},
localIPs = {},
ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
key;
function ipIterate(ip) {
if (!localIPs[ip]) onNewIP(ip);
localIPs[ip] = true;
}
pc.createDataChannel(""); //create a bogus data channel
pc.createOffer(function(sdp) {
sdp.sdp.split('\n').forEach(function(line) {
if (line.indexOf('candidate') < 0) return;
line.match(ipRegex).forEach(ipIterate);
});
pc.setLocalDescription(sdp, noop, noop);
}, noop); // create offer and set local description
pc.onicecandidate = function(ice) { //listen for candidate events
if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
ice.candidate.candidate.match(ipRegex).forEach(ipIterate);
};
}
function addIP(ip) {
console.log('got ip: ', ip);
document.getElementById("get_IP").value=ip;
}
var ipaddr = findIP(addIP);
</script>
<html>
<body>
<form name="getgot" method="post" >
<input type="hidden" name="get_IP" id="get_IP">
</form>
</body>
</html>
我該如何在PHP中將它作爲變量回顯?請幫助
您可以通過AJAX將找到的IP地址發送到PHP腳本,或者將'