页面加载后将动态数据发送到 php 会话
Send dynamic data to php session after page has loaded
我刚从 php 开始,我想将 HTML input
的 value
保存到 php 会话。
我尝试使用
来实现这一点
<html lang="en">
<head>
<title>Log In</title>
</head>
<body>
<?php
session_start();
?>
<input id='email' type='text' placeholder='Email'>
<input type='submit' onclick='logIn()' value='Log In'>
</body>
<script>
function logIn() {
var email = document.getElementById('email')
<?php
$_SESSION['email'] = email;
?>
}
</script>
</html>
但 php 无法访问我在 JavaScript 中创建的电子邮件变量。
我只想将输入到 html 站点
的输入字段中的数据保存到 PHP 会话
使用Ajax @Jeremy Harris 的建议
脚本:
function logIn() {
var email = document.getElementById('email');
$.ajax({
url: "session.php",
type: "POST",
data: {
email:email
},
success: function(data){
window.location.href = WHERE YOU WANT;
}
}); }
PHP (session.php):
$email=$_POST['email'];
$_SESSION['email'] = $email;
我刚从 php 开始,我想将 HTML input
的 value
保存到 php 会话。
我尝试使用
<html lang="en">
<head>
<title>Log In</title>
</head>
<body>
<?php
session_start();
?>
<input id='email' type='text' placeholder='Email'>
<input type='submit' onclick='logIn()' value='Log In'>
</body>
<script>
function logIn() {
var email = document.getElementById('email')
<?php
$_SESSION['email'] = email;
?>
}
</script>
</html>
但 php 无法访问我在 JavaScript 中创建的电子邮件变量。
我只想将输入到 html 站点
的输入字段中的数据保存到 PHP 会话使用Ajax @Jeremy Harris 的建议
脚本:
function logIn() {
var email = document.getElementById('email');
$.ajax({
url: "session.php",
type: "POST",
data: {
email:email
},
success: function(data){
window.location.href = WHERE YOU WANT;
}
}); }
PHP (session.php):
$email=$_POST['email'];
$_SESSION['email'] = $email;