Link to home
Start Free TrialLog in
Avatar of tim_shady
tim_shady

asked on

Accessing ASP sessions in PHP

I have a web based knowledgebase written in ASP, its my job to hack it a little bit and add to it. What I want to do is pass the session information in ASP into my PHP code. The reason that I want to add to it in PHP is that I have done a reasonable amount of php while I have never even touche ASP. I can pass the session id into my php script, so that SID corresponds with the ID set by the ASP, but i wanna get the rest of the info too. Anybody know an easy way to do this?

I should point out that the ASP code that sets the session is using ASP's own session management..
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Probably the easiest thing to do is in ASP, compile a string which looks like the output of a serialize function in PHP and then unserialize it in PHP.

If you intend to have PHP AND ASP on the same machine, you have to be VERY careful about the sequence in which code is examined.

ASP first, then PHP.


e.g
<?php

$sStringInPHP = '<%

aspString = 'a:1:{s:4:"Name";s:5:"Value";}'
print aspString
%>';

$aArrayInPHP = unserialize($a);
print_r($aArrayInPHP);
?>

This idea is no different to ...


<html>
<head>
<title><?php echo $sTitle; ?></title>
</head>
...

Richard.
Avatar of tim_shady
tim_shady

ASKER

Cut and pasted your code, but I got "Parse error: parse error, unexpected T_STRING ...". The filename is test.php, do i want it to be test.asp? I dont understand how the web server knows to send some bits to be interpreted by ASP and others by PHP. Is it really possible to do?
Yes.

I don't know anything about ASP. So my code may be junk.

You will need to tell your webserver that extensions .xxx are to be parsed by both PHP AND ASP.

The sequence SHOULD be controllable.

You have to determine which way round you want it.

If you want the PHP code to do some stuff which ASP will then work with, you need to parse PHP first then pass the output onto ASP.

If you want the ASP code to do some stuff and then get PHP to deal with that, then ASP first then PHP.

At each stage, the tags appropriate for each parser are removed and the results left.

e.g.

Parsing ASP first and than PHP.

Start with.
<?php

$sStringInPHP = '<%

aspString = 'a:1:{s:4:"Name";s:5:"Value";}'
print aspString
%>';

$aArrayInPHP = unserialize($a);
print_r($aArrayInPHP);
?>

Parse ASP leaves ...

<?php

$sStringInPHP = 'a:1:{s:4:"Name";s:5:"Value";}';

$aArrayInPHP = unserialize($a);
print_r($aArrayInPHP);
?>


which is now standard PHP.

You are going to need to alter the extensions used by ASP/PHP so that the file is parsed by both.

You MAY want to produce an extension like ...


APH = ASP -> PHP -> HTML
PAH = PHP -> ASP -> HTML

You MAY want to layer them. If you can add extensions and then dictate what handles them ...


APH is handled by ASP
APH, PAH is handled by PHP
PAH is handled by ASP

Remember, at each parse, the tags are removed.

So.

If you had ASP code actually creating PHP code which created ASP code ...

APAH as an extension would be fine.

APAH is handled by ASP (handles initial ASP which produces PHP code)
APAH is handled by PHP (handles PHP code created above and produces more ASP code)
APAH is handled by ASP (handles PHP created ASP code).

I've not tried this. You MAY find that your server talks about the parser and not the extensions, in which case you MAY have some sort of sequence you can define them in, but you will PROBABLY not be able to use one language to produce code for another which in turn produces code for the first.

Richard.
ASKER CERTIFIED SOLUTION
Avatar of andreshm
andreshm
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial