1

Is there anyway to pass values from ASP.NET to PHP easily using Session or any other? I tried in the below way but it didn't work for me. Anybody either correct the below code or suggest me a way to pass values from ASP.NET to PHP without using URL query string.

ASP.NET code.

protected void Button1_Click(object sender, EventArgs e)
    {
        HttpCookie cookie = new HttpCookie("myvalue1");
        cookie.Value = "[email protected]";
        Response.Redirect("Default.php");
    }

PHP code.

<?php
session_start();
$_COOKIE['myvalue1'];
$cookies = getCookies();
$sessionId = $cookies['myvalue1'];
?>
5
  • You can (obvoisly) do it using standard html form posts, and using the querystring. Commented Jan 13, 2012 at 20:38
  • @DavidStratton - Both are not secured! Doing so, users can modify their values. Commented Jan 13, 2012 at 20:40
  • 1
    So are cookies. If you need to verify, encrypt on ASP.NET and decrypt on PHP (AES/base64 works perfect) Commented Jan 13, 2012 at 20:41
  • @EugenRieck - Thanks for your suggestion. Will make use of this in exceptional case. Commented Jan 13, 2012 at 20:43
  • 1
    There is even the possibility of blah/[base64encodedcookie]/stuff.html with a custom 404 handler in PHP. Same thing applies concerning security Commented Jan 13, 2012 at 21:07

3 Answers 3

2

You can create WSDL/REST API on the PHP side and simply send data from .Net to this API

Sign up to request clarification or add additional context in comments.

Comments

1

There are a few ways to do this, but none are particularly sexy.

  1. Post the data from asp.net using an httpwebrequest to a php page, all done server side.
  2. A cookie with an encrypted value.
  3. If php and .net are both run on the same server, save to file system.
  4. A database server.
  5. ASP.NET supports multiple forms of persisting session state. State Server and Sql being 2 of them. I'm sure php could be configured to read them. You'd have to research how to do that. An article for sharing session between ASP.NET and classic ASP. Conceptually the same, and has the ASP.NET configuration part in the article. http://msdn.microsoft.com/en-us/library/aa479313.aspx

EDIT: You could even roll your own state server. Create a webservice that stores data from asp.net and php retrieves it when needed.

2 Comments

Good answer! Seeking for syntax :(
msdn.microsoft.com/en-us/library/debx8sh9.aspx Is an article on how to send data using httpwebrequest. You could retrieve the data posted and save to php session using normal get/post parameter handling in php.
-2
Response.Redirect("Default.php?myparam=myvalue");

1 Comment

Please read my question again. I clearly mentioned not to use URL query string method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.