我想从一个页面获取一些数据到另一个页面,但我只需要加载一个页面。我试图使用SESSION,但它不起作用。如何从一个页面获取数据到另一个页面不需要运行php
<?php
session_start();
print $_SESSION["charge"];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/page2.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"username=admin&password=admin123");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
$server_output = curl_exec ($ch);
curl_close ($ch);
?>
页2
<?php
session_start();
$_SESSION["charge"]="Y";
$username=mysql_real_escape_string($_POST['username']);
$password=mysql_real_escape_string($_POST['password']);
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("test") or die("Cannot connect to database");
$query=mysql_query("SELECT * FROM users WHERE username='$username'");
$exists=mysql_num_rows($query);
$table_username = $table_password = $name = "";
if($exists>0){
while($row=mysql_fetch_assoc($query)){
$table_username=$row['username'];
$table_password=$row['password'];
}
if(($username==$table_username) && ($password==$table_password)){
if($password==$table_password){
print "Username & password is approved!";
}
}
else{
print "Incorrect Password!";
}
}
else{
print "Incorrect Username!";
}
?>
我不能没有加载页面加载2页1反正是有得到第2页第1页数据,而不加载第2页?
没有加载第2页这是不可能的。你是什么意思?没有提神或没有提交或其他什么。如果你的页面没有加载,你怎么能从它们得到任何值 –
可以对页面2进行AJAX调用。但是由于页面1已经被执行,它不会重新加载该变量,所以你不能使用值页面1. – Twisty
欢迎来到StackOverflow。请包括更多关于你想要完成的细节。你看到什么错误? – Twisty