2015-05-08 36 views
0

我想从一个页面获取一些数据到另一个页面,但我只需要加载一个页面。我试图使用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页?

+0

没有加载第2页这是不可能的。你是什​​么意思?没有提神或没有提交或其他什么。如果你的页面没有加载,你怎么能从它们得到任何值 –

+0

可以对页面2进行AJAX调用。但是由于页面1已经被执行,它不会重新加载该变量,所以你不能使用值页面1. – Twisty

+1

欢迎来到StackOverflow。请包括更多关于你想要完成的细节。你看到什么错误? – Twisty

回答

-2

反正有没有加载第2页从第2页到第1页的数据?

我不相信这是你想要的。它IS你问的问题的答案。

Just go directly to http://localhost/page1.php 
+0

我不能正确地回答问题的正面或反面,也不知道你认为他的问题到底是什么。 – ultranaut

+0

这不提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 –

+0

@HansZ。问题:是否有没有加载第2页的数据从第2页到第1页?答案: 直接转到'http:// localhost/page1.php' – Misunderstood

相关问题