+ Reply to Thread
Results 1 to 5 of 5

Thread: Sessions via AMFPHP just don't stick

  1. Join Date
    Mar 2009
    Posts
    1

    Sessions via AMFPHP just don't stick

    I've been scouring the net for days and still no luck solving this problem. The amfphp counter example doesn't even work (on either my local server or external hosting) so I'm starting to wonder where the problem lies.

    To clarify: I can send and return vars to and from AMFPHP, so the services are working, but I just can't get the sessions to stick.

    The deal is this: I can set and get sessions with straight PHP files, so long as I put a session_start() up the top before either setting or reading the session var. That's fine.

    The problem arises when I try to do the above via AMFPHP. I've created a service with 2 functions - write() and read(). In the write function, I set the session var, in the read function I return it to amfphp. I can access the session var after setting it (in the write function it still contains the string) but as soon as I try to access it with a second call from AMFPHP the session var appears to contain nothing.

    I've tried putting the session_start() outside the class, inside the class, everywhich way to no effect.

    If anyone can steer me in the right direction on this it would be much appreciated.

    Code:
    <?php 
    
    session_start();
    
    class TestExchange
    { 
        function TestExchange(){
    
        }
        
        function write($in) 
        { 
    	$_SESSION['sessvar'] = $in;
        	return "setting session to " . $_SESSION['sessvar'];
        }  
       
        function read() 
        { 
        	return "returning session: " .  $_SESSION['sessvar'];
        } 
    } 
    
    ?>
    Here is the AS3 code if that helps, although I believe the problem lies at the PHP end.

    Code:
    var gw:NetConnection = new NetConnection();
    gw.connect("http://localhost:8888/amfphp/gateway.php");
    var res:Responder = new Responder(onResult, onFault);
    
    function onResult(responds:Object):void {
    	trace(responds);
    	for (var i in responds) {
    		trace (responds[i]);
    	}
    }
    
    function onFault(responds:Object):void {
    	for (var i in responds) {
    		trace (responds[i]);
    	}
    }
    
    //set session var
    gw.call("TestExchange.write",  res, "test");
    
    
    //retrieve session var
    
    butt.addEventListener(MouseEvent.CLICK, onClicker);
    
    function onClicker(e:MouseEvent):void {
    	gw.call("TestExchange.read",  res);
    }
    Last edited by palaceofrock; 24th March 2009 at 01:50.

  2. JonoB is offline Newborn member little-flashed member JonoB is on a distinguished road
    Join Date
    Oct 2008
    Posts
    4
    Your code looks fine.

    I just used created exact same file and copy pasted your code. Works fine in amfphp browser. So, something wrong with your php installation most likely.

    By the way, not that it makes a difference, but I believe that amfphp starts sessions automatically.

  3. Join Date
    Oct 2009
    Age
    50
    Posts
    1
    Quote Originally Posted by palaceofrock View Post
    I've been scouring the net for days and still no luck solving this problem. The amfphp counter example doesn't even work (on either my local server or external hosting) so I'm starting to wonder where the problem lies.

    To clarify: I can send and return vars to and from AMFPHP, so the services are working, but I just can't get the sessions to stick.

    The deal is this: I can set and get sessions with straight PHP files, so long as I put a session_start() up the top before either setting or reading the session var. That's fine.

    The problem arises when I try to do the above via AMFPHP. I've created a service with 2 functions - write() and read(). In the write function, I set the session var, in the read function I return it to amfphp. I can access the session var after setting it (in the write function it still contains the string) but as soon as I try to access it with a second call from AMFPHP the session var appears to contain nothing.

    I've tried putting the session_start() outside the class, inside the class, everywhich way to no effect.

    If anyone can steer me in the right direction on this it would be much appreciated.

    Code:
    <?php 
    
    session_start();
    
    class TestExchange
    { 
        function TestExchange(){
    
        }
        
        function write($in) 
        { 
    	$_SESSION['sessvar'] = $in;
        	return "setting session to " . $_SESSION['sessvar'];
        }  
       
        function read() 
        { 
        	return "returning session: " .  $_SESSION['sessvar'];
        } 
    } 
    
    ?>
    Here is the AS3 code if that helps, although I believe the problem lies at the PHP end.

    Code:
    var gw:NetConnection = new NetConnection();
    gw.connect("http://localhost:8888/amfphp/gateway.php");
    var res:Responder = new Responder(onResult, onFault);
    
    function onResult(responds:Object):void {
    	trace(responds);
    	for (var i in responds) {
    		trace (responds[i]);
    	}
    }
    
    function onFault(responds:Object):void {
    	for (var i in responds) {
    		trace (responds[i]);
    	}
    }
    
    //set session var
    gw.call("TestExchange.write",  res, "test");
    
    
    //retrieve session var
    
    butt.addEventListener(MouseEvent.CLICK, onClicker);
    
    function onClicker(e:MouseEvent):void {
    	gw.call("TestExchange.read",  res);
    }


    It happend to me after PHP update/upgrade.

    Try setting
    session.auto_start = 1 in your PHP INI

  4. Join Date
    Apr 2008
    Posts
    2
    anyone found a solution yet? I cannot access the session.auto_start since I'm on a hosting environment. I have exactly the same problem, with the same things palaceofrock described. Sessions work fine, but not when used through amfphp. It almost looks like every call is made in a scopeless environment or something like that :/

    Worked fine earlier, until I moved to a new virtual server hosting php 5.2.6.

  5. Join Date
    Oct 2009
    Location
    Germany
    Posts
    10

    Sessions via AMFPHP just dont stick

    Hey Arcwhite,Thank you for your help. I am able to see the html content but when I place the amfphp folder, I do see it at all. Even the folder permissions is set to 755. Do you happen to have any hosting provider that support AMFPHP?Thanks a lot.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts