CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   ASP (http://www.codingforums.com/forumdisplay.php?f=8)
-   -   Translate this php code (http://www.codingforums.com/showthread.php?t=251896)

bores 02-17-2012 08:34 PM

Translate this php code
 
Hi

I am nob in ASP, can someone please translate to me this php code into asp ?

Code:

$var1 = $_POST['userAge'];
$var2 = $_POST['userBirth'];
$url = 'http://externalwebsite.com/script.php?temp1=' . $var1 . '&temp2=' . $var2;
$content = file_get_contents($url);

Thank you

Old Pedant 02-17-2012 09:30 PM

Code:

<%
var1 = Trim(Request.Form("userAge"))
var2 = Trim(Request.Form("userBirth"))
url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1) _
    & "temp2=" & Server.URLEncode(var2)

Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", url, FALSE
http.Send

content = http.ResponseText
%>

The TRIMs may not be needed, esp. if the PHP code wasn't doing equivalent.

Ditto the use of Server.URLEncode.

But neither will hurt.

Hope you noticed the close resemblance of the code to AJAX in JavaScript. Microsoft actually was doing it like this way back in about 1997, long before AJAX came along.

bores 02-17-2012 10:02 PM

Thank so mush for your clear help. Yes not really in need for Trim and Server.URLEncode but because it don't harm anyone so I leave it as is. Still a simple question is that code can be inserted in any asp or aspx file ? I want the code for both ASP 3.0 as well as ASP.NET ?

alykins 02-17-2012 10:14 PM

asp is very differnt than asp.net (.asp .aspx) asp uses vbscript and while it may be close to vb.net (aspx/asp.net) it still is different in a lot of ways... you also have more options in .net such as C# (and then there are the obscure ones like J# and F#) - vb will prob be the easiest for you since you are moving from vbscript (well provided that is what you are doing)

Old Pedant 02-17-2012 10:14 PM

That is for ASP, only.

ASP.NET code would be completely different.

If you don't know how to write ASP.NET code, then you should avoid this stuff until you understand ASP.NET a *LOT* better. Even if this code worked with ASP.NET (and it could work, with only a few changes), what would you then do with the contents? With ASP.NET that won't be a simple answer.

bores 02-17-2012 10:40 PM

I was confused and thinking that ASP/ASP.NET is a single language. That true that it need serious knowledge and not translating like that, the situation is that I am working with php "You can see that the url is pointing to a php script" that I have experience with but this is a single process that must be run from server running ASP that is all the story :)

It would be awesome if someone post to me the code translation for both VB and C#.

Is it :
url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1) _SPACE &SPACE "temp2=" & Server.URLEncode(var2)
OR
url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1)NOSPACE_&NOSPACE"temp2=" & Server.URLEncode(var2)

Thank You

felgall 02-17-2012 11:22 PM

Quote:

Originally Posted by Old Pedant (Post 1194514)
Hope you noticed the close resemblance of the code to AJAX in JavaScript. Microsoft actually was doing it like this way back in about 1997, long before AJAX came along.

Ajax was introduced by Microsoft in Internet Explorer 4 in 1997 - it was only the name Ajax that came along later. The activeX object that many people still test for in setting up Ajax calls was the way that IE4 through 6 provided for doing Ajax calls.

alykins 02-18-2012 02:49 AM

Quote:

Originally Posted by bores (Post 1194532)
I was confused and thinking that ASP/ASP.NET is a single language. That true that it need serious knowledge and not translating like that, the situation is that I am working with php "You can see that the url is pointing to a php script" that I have experience with but this is a single process that must be run from server running ASP that is all the story :)

It would be awesome if someone post to me the code translation for both VB and C#.

Is it :
url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1) _SPACE &SPACE "temp2=" & Server.URLEncode(var2)
OR
url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1)NOSPACE_&NOSPACE"temp2=" & Server.URLEncode(var2)

Thank You

I still don't know what you are trying to do... are you trying to do asp or aspx? you seem to contradict your definitions... C# does not exist in classic asp- it is (for all tense and purpose) vbscript which is extremely similar to vb but not exactly the same

Old Pedant 02-18-2012 05:44 AM

Quote:

Originally Posted by felgall (Post 1194543)
Ajax was introduced by Microsoft in Internet Explorer 4 in 1997 - it was only the name Ajax that came along later. The activeX object that many people still test for in setting up Ajax calls was the way that IE4 through 6 provided for doing Ajax calls.

Yes, my only point was that the ActiveX object was available *SERVER SIDE* in 1997, for use in ASP, at the same time it appeared in MSIE. (microsoft.XMLHTTP was later refined to provide the msxml2.ServerXMLHTTP, but most of the usage remained the same.)

Old Pedant 02-18-2012 05:47 AM

Quote:

Originally Posted by bores (Post 1194532)

Is it :
url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1) _SPACE &SPACE "temp2=" & Server.URLEncode(var2)
OR
url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1)NOSPACE_&NOSPACE"temp2=" & Server.URLEncode(var2)

NEITHER.

When you put it all on one line, you REMOVE the underline characters.

VBScript uses an underline at the end of a line to mean that the code is continued on the next line.

Look, you clearly should *NOT* be doing this, even in ASP code. It's obvious that you don't know enough about ASP to even use the code I gave you in creating the rest of the page.

If you aren't willing to take the time to learn ASP (or ASP.NET) then hire somebody to do it for you.

bores 02-18-2012 07:54 AM

Thank You for clarification about underline. I need this code that I have posted in the first post only to be converted into C# and Visual Basic. If I make programs by those languages then I will learn them so please just this code above, and I will not post further codes because this is the only code I am in need for translation.

bores 02-18-2012 06:41 PM

Hi bro, regarding your code as well You know that the & symbol should be present in the url so I guess you forget the & to be included so the line should be "I suppose the url is in a single line okay"

url = "http://externalwebsite.com/script.php?temp1=" & Server.URLEncode(var1) & "&temp2=" & Server.URLEncode(var2)

I just changed "temp2=" to "&temp2="

Old Pedant 02-19-2012 06:33 AM

Correct.

I'm not going to attempt to translate that to VB.NET or C# until you can explain why you *possibly* would need it it *BOTH* those languages. Choose one. No reason to use both.

bores 02-19-2012 08:58 PM

Hi again and thanks for your reply.
Quote:

Originally Posted by Old Pedant (Post 1194909)
Choose one. No reason to use both.

You're right, After googling it is easy as doing that :

<script runat="server" language="C#">
...
</script>

So you can tell me the code only for C# that's enough :thumbsup:

bores 02-20-2012 01:06 PM

There is no need for you to past to me the neither the C# or VB conversion of this source code. Fortunately I succeed to establish it my self after a little learning. I am glad for that so the only hard thing that remain for me and the last thing I can ask someone for help is to convert this code to Java Server Pages code. Unfortunately there is a few few documentation about JSP on the web in comparison to MS .NET.

Thank you for your help and hope to hear you.
PS : I wouldn't like to create a new topic in the JSP forum to not pollute the forums with the seem topic.

Regards


All times are GMT +1. The time now is 08:06 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.