Sunday, August 2, 2009

Using the same variables between php and visual basic and serveral webpages?

Where can I find documentation on using the same variables between webpages and php and visual basic.

Using the same variables between php and visual basic and serveral webpages?
You can't share session variables between PHP and ASP.NET (I assume you mean ASP.NET when you speak of "Visual Basic").





Sessions in both PHP and ASP.NET are instantiated at the application level; since they are different applications, you can't share the values between the two.





You could, in theory, save the session key from PHP and attempt to retrieve it with ASP.NET and vice-versa. However, you'll likely find that there is significant corruption of the variables between the two, especially as you attempt to "hand them off" repeatedly.





It's far wiser to use a stated (written) method of storing variables. You can do it a number of ways:





1. Pass variables between pages via GET (querystring) or POST (submitted form).





2. Save the information in a cookie and get it that way. ASP and PHP can read cookies set by one another provided the cookies are in the same domain (for that matter, JavaScript can also read cookies set by PHP and ASP.NET in the same domain).





3. Save the variables to a database, XML or flat file and read them back in for each page.
Reply:Short of a third-party session-sharing solution, the only way is to use a common data store (like a database) and querystring variables, or cookies.





[If any term is unfamiliar, just look it up on Google]





To share data across PHP or VB pages, you should use Session.





To share a variable from a PHP page to a VB page, you need to pass a key. Let's say you have a User object in PHP. Give that a unique ID, like a GUID. Store the User object and the GUID in a database that PHP and VB can access, then redirect to the VB page like so:





page.asp?uid=3F2504E0-4F89-11D3-9A0C-0...





Then in the VB script, use that key to look up the user object in the database and restore it.
Reply:That's the answer. A session variable can be an array. So you could hold 50 things on an object and pass it into it without anyone knowing what your passing.





Another way is to pass each variable at the top of the page, but if any of it is sensitive like a user id the session id is the way to go.





Thirdly, use a Database. PHP and databases are great.





I threw 2 ways to help you learn below.


No comments:

Post a Comment