Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    14
    Thanked 0 Times in 0 Posts

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,208
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.
    Last edited by Old Pedant; 02-17-2012 at 09:32 PM.
    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.

  • Users who have thanked Old Pedant for this post:

    bores (02-19-2012)

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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 ?

  • #4
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,725
    Thanks
    41
    Thanked 191 Times in 190 Posts
    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

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,208
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.

  • #6
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,631
    Thanks
    0
    Thanked 648 Times in 638 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,725
    Thanks
    41
    Thanked 191 Times in 190 Posts
    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

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,208
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,208
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    bores (02-19-2012)

  • #11
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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.

  • #12
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    14
    Thanked 0 Times in 0 Posts

    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="

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,208
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.

  • #14
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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.

  • #15
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    14
    Thanked 0 Times in 0 Posts
    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


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •