Search code examples
phpsessionasp-classic

Access Session-Vars over multiple languages


Maybe my understanding of a session is off, but isn't a session stored in the browser? More like, as long as the browser is open, the session should be active, right? (If you don't change the default behaviour).

We have multiple languages in our project, which we are trying to get rid off. Currently, 90% of our code is running in classic asp and will be replaced with PHP.

If I try to access my variables in the asp-part, it works fine:

<%= session("name") %> 

This outputs "Jon" for instance.

If I try to get this output via PHP like so:

<? var_dump($_SESSION); ?> 

i simply get NULL. Needlessly to say, that <?= $_SESSION["name"] ?> doesn't work as well, then.

I'm never leaving the site, only the paths are different:

mysite.com/default.asp works fine

mysite.com/phptest/session.php only returns NULL when trying to access the session. Why is that? Both languages are running on an IIS. Do I have to somehow tell PHP to access the existing session?

I'm fairly certain, that I combined accessing Session-Vars in PHP + JavaScript before and that worked fine.


Solution

  • The session object is specific to Active Server Pages. If you have a mixed site that runs both PHP and ASP, you won't be able to use ASP session variables in your PHP pages. The objects and variables in Session are managed by ASP; the only thing the browser is involved with is keeping a reference to that session in a cookie.

    What you could do is save the content of the session variables to a cookie, which could then be read by your PHP pages (with a little twist, apparently: Read classic ASP's cookies with PHP )

    Hope this helps!