Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-17-2012, 08:34 PM   PM User | #1
bores
New Coder

 
Join Date: Feb 2012
Posts: 22
Thanks: 14
Thanked 0 Times in 0 Posts
bores is an unknown quantity at this point
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
bores is offline   Reply With Quote
Old 02-17-2012, 09:30 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 02-17-2012 at 09:32 PM..
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
bores (02-19-2012)
Old 02-17-2012, 10:02 PM   PM User | #3
bores
New Coder

 
Join Date: Feb 2012
Posts: 22
Thanks: 14
Thanked 0 Times in 0 Posts
bores is an unknown quantity at this point
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 ?
bores is offline   Reply With Quote
Old 02-17-2012, 10:14 PM   PM User | #4
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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)
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 02-17-2012, 10:14 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-17-2012, 10:40 PM   PM User | #6
bores
New Coder

 
Join Date: Feb 2012
Posts: 22
Thanks: 14
Thanked 0 Times in 0 Posts
bores is an unknown quantity at this point
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
bores is offline   Reply With Quote
Old 02-17-2012, 11:22 PM   PM User | #7
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,468
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by Old Pedant View Post
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.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 02-18-2012, 02:49 AM   PM User | #8
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
Quote:
Originally Posted by bores View Post
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
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Old 02-18-2012, 05:44 AM   PM User | #9
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by felgall View Post
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.)
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-18-2012, 05:47 AM   PM User | #10
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by bores View Post

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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
bores (02-19-2012)
Old 02-18-2012, 07:54 AM   PM User | #11
bores
New Coder

 
Join Date: Feb 2012
Posts: 22
Thanks: 14
Thanked 0 Times in 0 Posts
bores is an unknown quantity at this point
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.

Last edited by bores; 02-18-2012 at 07:56 AM..
bores is offline   Reply With Quote
Old 02-18-2012, 06:41 PM   PM User | #12
bores
New Coder

 
Join Date: Feb 2012
Posts: 22
Thanks: 14
Thanked 0 Times in 0 Posts
bores is an unknown quantity at this point
Cool

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="
bores is offline   Reply With Quote
Old 02-19-2012, 06:33 AM   PM User | #13
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-19-2012, 08:58 PM   PM User | #14
bores
New Coder

 
Join Date: Feb 2012
Posts: 22
Thanks: 14
Thanked 0 Times in 0 Posts
bores is an unknown quantity at this point
Hi again and thanks for your reply.
Quote:
Originally Posted by Old Pedant View Post
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

Last edited by bores; 02-19-2012 at 09:15 PM..
bores is offline   Reply With Quote
Old 02-20-2012, 01:06 PM   PM User | #15
bores
New Coder

 
Join Date: Feb 2012
Posts: 22
Thanks: 14
Thanked 0 Times in 0 Posts
bores is an unknown quantity at this point
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
bores is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:52 AM.


Advertisement
Log in to turn off these ads.