?
Solved

Communication between PHP and ASP

Posted on 2005-03-31
20
Medium Priority
?
297 Views
Last Modified: 2013-11-19
Hello Fellow Experts:

Im looking for a solution that will give me some sort of communication between PHP and C# ASP.NET (cookies?). I have users which will log into our website and authenticate via forms, with an active directory user account. From within the C# ASP site, users will click on a hyperlink, and I need to redirect the user to a PHP site on our linux server running apache. I'd like some way to pass the current username/password used to authenticate the users on the ASP site to the PHP site. The username/passwords will be the same. The only thing I can think of is by using cookies, or possibly writing to some external file on the client side, and then reading it via PHP. But will PHP read ASP cookies?

I cannot migrate the PHP content from linux to the windows server, this is not an option. I need a solution for my existing layout. Thanks!
0
Comment
Question by:kristenhazard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 4
  • 4
  • +1
20 Comments
 
LVL 7

Expert Comment

by:maXXXeE
ID: 13677717
Yes u can use cookies to do it.
but, there r other ways too, like using web services.
u can just call the web service method via php to authenticate the user, and u can set the wenservice to return the username,password, and result of authentication.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13677781
It has nothing to do with whether ASP and PHP can read each other cookies.  IT is not going to work becaue you have two different domains. A page from one domain cannot access the cookie created by a page from another domain. It is a security limitation and it makes cookies anon-starter for this.

Cd&
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 13678084
You could probaby have the two to exchange data via WDDX have a look at openwddx.org
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

Author Comment

by:kristenhazard
ID: 13678510
maXXXeE:
Can you elaborate on how i can use web services and wenservice? I need a seamless transition from one platform to the other, w/o having the user re-type in his/her username/password. Possibly some code or examples to lead me in the right direction? Or maybe cookies will work?

Cd&:
The hosts will be different, but the domains will be the same, is that what you meant by two different domains?

Thanks.
0
 

Author Comment

by:kristenhazard
ID: 13678514
Tacobell777
Ill check it out.
0
 
LVL 7

Expert Comment

by:maXXXeE
ID: 13678544
wenservice->sorry, that was a typo ,it was webservice
0
 
LVL 7

Expert Comment

by:maXXXeE
ID: 13678563
if u want the basics, u can get all the info from here:
http://www.w3.org/2002/ws/
0
 
LVL 7

Expert Comment

by:maXXXeE
ID: 13678601
here u can find info on implementing webservices in asp.net
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconbuildingaspnetwebservices.asp

i havnt worked with web services on php, but i guess will get some help in the below link
http://webservices.xml.com/pub/a/ws/2004/03/24/phpws.html
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13679739
Okay, two different boxes on the same domain should be okay.  I thought you were tyring to go cross-domain.

Cd&
0
 

Author Comment

by:kristenhazard
ID: 13682739
Cookies sound the easiest at this point, but the cookie from C# is not being read by PHP.

I tried setting the cookies in c# two ways, both failed
      Response.Cookies["username"].Value = this.login_username.Text;
      Response.Cookies["password"].Value = this.login_password.Text;

And I try to read the cookies in php like so:
      $username = $_COOKIE['smp_username'];
      $password = $_COOKIE['smp_password'];

Suggestions?
0
 

Author Comment

by:kristenhazard
ID: 13682753
the second way i tried to set the cookies in C#:

HttpCookie smp_username = new HttpCookie("smp_username", this.login_username.Text);
HttpCookie smp_password = new HttpCookie("smp_password", this.login_password.Text);
Response.Cookies.Add(smp_username);
Response.Cookies.Add(smp_password);

And i shouldnt say they failed, just failed to be read by PHP.
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13683051
Are you getting an error message or is the code just being ignored?

Cd&
0
 

Author Comment

by:kristenhazard
ID: 13683188
Im not getting any errors, im pulling blank strings:

      $username = $_COOKIE['username'];
      $password = $_COOKIE['password'];

?>
<SCRIPT language="javascript">

alert( "username: <?echo $username;?> password: <?echo $password;?>" );

</SCRIPT>
<?php

this snippit returns blanks for my variables.
0
 

Author Comment

by:kristenhazard
ID: 13684783
I wanted to verify that asp was writing the cookie, so I go to FireFox, options, view cookies, and I dont see the two cookies im trying to write?! Any suggestions?
0
 

Author Comment

by:kristenhazard
ID: 13685153
I did some debugging, I watched the cookie get created and assigned the correct values, but I still dont know where the cookie is going on my local (client) computer. I checked out the cookies location, and I dont see the cookies. Ive also tried using this function, to give an expiration date to ensure persistance.

            private bool SetCookie(string cookiename, string cookievalue ,int iDaysToExpire)
            {
                  try
                  {
                        HttpCookie objCookie = new HttpCookie(cookiename);
                        Response.Cookies.Clear();
                        Response.Cookies.Add(objCookie);
                        objCookie.Values.Add(cookiename,cookievalue);
                        DateTime dtExpiry = DateTime.Now.AddDays(iDaysToExpire);
                        Response.Cookies[cookiename].Expires =dtExpiry;
                  }
                  catch( Exception e)
                  {
                        return false;
                  }
                  return true;
            }
0
 

Author Comment

by:kristenhazard
ID: 13685319
ok, another update. I've confirmed that the cookies are being created and are persistant. The function ive used to create the cookie follows:

private bool SetCookie(string cookiename, string cookievalue ,int iDaysToExpire)
{
      try
      {
            HttpCookie objCookie = new HttpCookie(cookiename, cookievalue);
            Response.Cookies.Add(objCookie);
            DateTime dtExpiry = DateTime.Now.AddDays(iDaysToExpire);
            objCookie.Expires =dtExpiry;
            Response.Cookies.Add(objCookie);
      }
      catch( Exception e)
      {
            return false;
      }
      return true;
}

But my problem still remains that PHP isnt reading the cookies. Help?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13685496
I don't know PHP so at this point I can' be much help; I'm afraid.

Cd&
0
 

Author Comment

by:kristenhazard
ID: 13700210
I think the problem is that cookies generated via c# asp are named differently that when generated via php. They are both put in the same folder, \Documents and Settings\user\Local Settings\Temporary Internet Files. How can I get php to read a manual filename/filepath for a cookie, or get c# to write to a manual filename/filepath that is standard to php?

c# asp generated cookiename:
Cookie:localusername@host.domainname.com/

php generated cookiename:
folder_path/

to clarify the php cookiename, a cookie is given the name folder_path/ from a site like so, www.domain.com/folder_path/ 

Someone throw me a bone ;)
0
 

Accepted Solution

by:
kristenhazard earned 0 total points
ID: 13732163
ive given up on cookies and solved this another way, for sake of posting this is what ive done.

Durring authentication against the AD, in c# I stored two session variables, first in clear text the username, the other was a md5 hash of the password. Then on the link that would be taking the users to the PHP site, I passed a username and hashed pw via $_GET and rewrote my authentication method on the PHP side to check if the md5 hash matched the SQL stored md5 password.

Moderator can you please close this, and thanks for guys for your posts and effort.
0

Featured Post

7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question