2012-08-22 11 views
0

我有一個用戶登錄會話運行在/級,這工作正常,然後我有一個JavaScript調用文件/ PHP/AJAX.PHP與數據庫後端。事情是我想從初始登錄/級別轉移到ajax.php會話數據,它沒有。有關於這個話題的任何合理的想法?PHP的子文件夾中的會話範圍與AJAX

頁檢查登錄:

<?php 
session_start(); 
echo session_id(); 
if(!isset($_SESSION['loggedin'])) 
{ 
    die("To access this page, you need to <a href='login.php'>LOGIN</a>"); 
} 

define('WP_USE_THEMES', false); //loads wordpress 
require('/home/content/70/9551370/html/alpha/wordpress/wp-blog-header.php'); 
query_posts('showposts=1'); 
?> 
<head> 
    <link href="css/style.css" rel="stylesheet" type="text/css"> 
    <link rel="stylesheet" type="text/css" href="css/page.css" /--> 
    <link rel="stylesheet" type="text/css" href="css/chat.css" /> 
<head> 
<body> 
<div class="background_container" style=""> 
<div style="text-align:center;"> 
<table style="text-align:center;"><!--three column division--> 
<tr> 
<td id="chat"> 
<div id="chatContainer"> 

    <div id="chatTopBar" class="rounded"></div> 
    <div id="chatLineHolder"></div> 

    <div id="chatBottomBar" class="rounded"> 
     <div class="tip"></div> 

     <form id="loginForm" method="post" action=""> 
      <input id="name" name="name" class="rounded" maxlength="16" /> 
      <input id="email" name="email" class="rounded" /> 
      <input type="submit" class="blueButton" value="Login" /> 
     </form> 

     <form id="submitForm" method="post" action=""> 
      <input id="chatText" name="chatText" class="rounded" maxlength="255" /> 
      <input type="submit" class="blueButton" value="Submit" /> 
     </form> 

    </div> 

</div> 
    <!--table> 
     <tr> 
      <td class="window_top"></td> 
     </tr> 
     <tr> 
      <td class="window_bottom"><div>chat form goes here</div></td> 
     </tr> 
    </table--> 
</td> 
<td class="lesson"><!--Wordpress posts--> 
    <?php while (have_posts()): the_post(); ?> 
     <h2><?php the_title(); ?></h2> 
     <?php the_excerpt(); ?> 
     <a href="<?php the_permalink(); ?>" class="text1">Read more...</a> 
    <?php endwhile; ?> 
    </td> 
<td><!--End Wordpress--> 
<h2>Tracking</h2> 
<p><?php Print_r ($_SESSION); ?></p> 

<form action="" method=""> 
<ul id="grade_list" style="list-style:none;"> 

    <li>1. <Input type = 'radio' Name ='lesson1' checked="checked" value= 'yes'>Yes</input> 
     <Input type = 'radio' Name ='lesson1' value= 'no'>No</input> 
    </li> 
    <li>2. <Input type = 'radio' Name ='lesson2' checked="checked" value= 'yes'>Yes</input> 
     <Input type = 'radio' Name ='lesson2' value= 'no'>No</input> 
    </li> 
    <li>3. <Input type = 'radio' Name ='lesson3' checked="checked" value= 'yes'>Yes</input> 
     <Input type = 'radio' Name ='lesson3' value= 'no'>No</input> 
    </li> 
</ul> 
    <Input type = "Submit" Name = "Submit1" Value = "Submit"> 
</form> 
</td> 
</tr> 
</table> 

</div> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script src="js/jScrollPane/jquery.mousewheel.js"></script> 
<script src="js/jScrollPane/jScrollPane.min.js"></script> 
<script src="js/script.js"></script> 
</body> 

Ajax.php:

<?php 

$dbOptions = array(

    'db_host' => 'ip', 
    'db_user' => 'user', 
    'db_pass' => 'password', 
    'db_name' => 'db_name' 
); 

/* Database Config End */ 

error_reporting(E_ALL^E_NOTICE); 

require "classes/DB.class.php"; 
require "classes/Chat.class.php"; 
require "classes/ChatBase.class.php"; 
require "classes/ChatLine.class.php"; 
require "classes/ChatUser.class.php"; 

session_start(); 

... 
?> 
+5

請寄一些代碼! –

+0

<?php session_start();?> ...等待 –

+0

@ TimZhukov-Khovanskiy在下面看到我的答案。 – Matt

回答

1

session_start()在需要訪問會話的所有文件的開始。

<?php //very first line of file (ajax.php, index.php, whatever.php) 
session_start(); 
// other PHP scripting here 
. 
. 
. 
?> 
<!-- HTML here if necessary --> 
. 
. 
. 
+0

這不起作用。事實上,在jscript調用ajax.php後,會話ID是不同的。 –

+0

會話開始 我有login.php: <?php session_start(); //獲取會話變量 > <標籤即JavaScript的職位,並從> 得到的東西然後ajax.php