Helpful Information
 
 
Category: Other Programming Languages
Pass php sessions with ajax

Hi all,

Im 100% new to ajax i have it all working apart from one thing...

How the hell do i pass php sessions with ajax ?

Can some one please help me...

I have been at this all day but its killing me now! :chomp:

it is what i need to send it to


session_start();
$code = strtoupper($_SESSION['code']);
$securitycode = strtoupper($_POST['securitycode']);
session_destroy();

if (($code == $securitycode) && (strlen($code) > 4)) {
echo 'code is good';
}

so the session is $_SESSION['code']

Thanks

Well that's a (__!__) i thought i may get some one that knows about this :(

Well it now looks like i will have to pull it all out and forget about it :chomp:

Well that's a (__!__) i thought i may get some one that knows about this :(

Well it now looks like i will have to pull it all out and forget about it :chomp:
I just got it working ... now my framework might be different then yours but as long as you have the $_SESSION['MyVar'] = 'something'; stored, you will just need to use the session_start() and then $something = $_SESSION['MyVar'] in your scripted called by AJAX.

I use AJAX in much the same way I use roll overs ... it's a small script included at the top of my page that just swaps the content of an ID w/ a PHP script results. I haven't gotten deep into the forms side of things which I feel is where AJAX really excels. In fact w/ all the issues I'm seeing w/ PHP and AJAX I'm not really sure I want to change my whole architecture. AJAX doesn't play well w/ PHP OO, in my opinion. i personally like to write all my own code so using plug ins like XOAD are cool but not my style. I'm looking into XOAD now to see if it is something I really want to get into, but like I said it's a major change from a pure PHP site. My biggest Issue is how calling PHP scripts in AJAX works ... I store commonly used site configuration info in a single array, connection to DBs have to happen on each script call, that requires passing of connection info, decentralizing my connection scripts to each php script that talks to the DB, and if you have more then one DB you're talking to it becomes a nightmare. I have ZENDCORE running on an IBM system i and connect to DB2 and MySQL. I'm in the process of looking how to integrate AJAX into that mix.

I've been thinking lately of proposing the Question to other programmers to see if they really think AJAX is worth the fight w/ PHP ... I'm just not sure.

Here is some code that may help .. "echo"'s are included for debuging.
This is loaded in a PHP function script included at the top of my main script.


<?php
session_start();
echo "Session ID = ".session_id()."<br />\n";
$_SESSION['sql_host'] = $CFGVAR['sql_host'];
echo "SQL Host = ".$_SESSION['sql_host']."<br />\n";
$_SESSION['sql_user'] = $CFGVAR['sql_user'];
echo "SQL User = ".$_SESSION['sql_user']."<br />\n";
$_SESSION['sql_pass'] = $CFGVAR['sql_pass'];
echo "SQL Password = ".$_SESSION['sql_pass']."<br />\n";
$_SESSION['sql_database'] = $CFGVAR['sql_database'];
echo "SQL Database = ".$_SESSION['sql_database']."<br />\n";
?>

this a code snip it in the script called by AJAX


session_start();
$sql_host = $_SESSION['sql_host'];
$sql_user = $_SESSION['sql_user'];
$sql_pass = $_SESSION['sql_pass'];
$sql_database = $_SESSION['sql_database'];
echo "SQL host = ".$sql_host."<BR />\n";
echo "SQL user = ".$sql_user."<BR />\n";
$userGroup = new select_UserGroup();
$userGroup->dbOpen_MySQL($sql_host, $sql_user, $sql_pass, $sql_database);
$userGroup->make_select_group();
$userGroup->dbClose_MySQL($userGroup->db_con);










privacy (GDPR)