views:

183

answers:

3

hi, i am using form authentication for my website which is written in ASP.Net, but i have a PHP script that i need to run. Is it possible to get the value of User.Identity.Name in PHP ?

thanks.

+2  A: 

Yes, if you pass it on to the PHP page using POST or GET (Querystring or Form), meaning getting the value from an ASP page first and then sending it to you PHP page. You can also take a look at this question on Stack Overflow, which offers a different solution.

*Edit: Possible solutions:

The second one could work for PHP as well with a bit of creativeness.

Mr. Smith
im not sure that the answer im looking for. the php page will be loaded in an iframe after the login page.
khalil
If that's the case, it's probably a good idea to add that to your question's text. To get specific answers, you need to be specific with your questions.
Mr. Smith
Updated my answer with some additional information that might be useful.
Mr. Smith
i think ill use php GET from an ashx page which will display the value of user.identify.name. is that good enough ?
khalil
I can't say Khalil, I haven't tried this myself, yet. Good luck! Anyone else have some advice for Khalil?
Mr. Smith
i guess in terms of security, it does not have any problem.
khalil
+1  A: 

why don't you just store the User.Identity.Name from the ASP.NET page in a session, and then when you call the PHP page you can just retrieve it from that session? As long as its the same site, it should work.

waqasahmed
meaning i will need to use $_SESSION ?
khalil
However, the native methods of storing session information differ in PHP and ASP.NET. But you can force both to store the needed information in a database.
Ignas R
any examples ? thanks
khalil
@Ignas - Yes I was unsure if sessions would be same in asp.net as php. I considered DB but I consider DB to be a form of longterm persistant storage over shortterm simply passing variables across
waqasahmed
A: 

Since you mentioned loading the PHP script in an iframe, you want to do something like this:

 <iframe src="myscript.php?username=<%= User.Identity.Name %>" />

This passes the Identity name along as a GET parameter, as suggested by Boekwurm.

Then, in your PHP script, grab it like so:

 username = $_GET["username"];

Depending on what you're doing with it, you may need some security in place to prevent people from running the PHP script with arbitrary username parameters.

JoshJordan
when everyone sees the html code, they can just cheat the system by changing username.
khalil
Yes, that's why you need some security (as noted in my post). Try generating a token in your database, and matching that token up in the PHP script, for example.
JoshJordan
Really, you should use an ASP.NET (aspx) page in your iframe, and make an AJAX call to the PHP script using a POST request, thereby obscuring the fact that you are passing the username around, but **you will still need a security token** or equivalent.
JoshJordan