Results 1 to 14 of 14

Thread: [RESOLVED] need to port ASP to PHP

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Resolved [RESOLVED] need to port ASP to PHP

    I have some really simple code that I need to port to PHP because a customer has a linux server and needs this code to run on it.

    All the code does is check the USER_AGENT string sent by the browser to determine if the .NET framework is present. This info is ONLY sent in the USER_AGENT string if the webbrowser being used is IE, otherwise its not there.

    So there are 3 possible outcomes.

    1) User is using IE and .NET framework is present
    2) User is using IE and .NET framework is NOT present
    3) User is not using IE and .NET framework can not be determined

    The code is not fool proof, but all it is supposed to do is give the user a suggestion on which of the 2 files they shoudl download, one that has the .NET framework (25+MB file) or the one that is just the program (~2MB file)

    since the end users of this software are not computer savvy, this helps them to get the right one (and I would say 85% are using IE)

    anyway, here is some of the ASP code so you can see the actual checks I am doing (basically just looking for keywords in the USER_AGENT string)

    VB Code:
    1. if instr(1, Request.ServerVariables("HTTP_USER_AGENT"), "1.1.4322") <> 0 or instr(1, Request.ServerVariables("HTTP_USER_AGENT"), "2.0.40607") <> 0 then
    2. 'WRITE OUT SOME HTML
    3. elseif instr(1,Request.ServerVariables("HTTP_USER_AGENT"),"MSIE") <> 0 then
    4. 'WRITE OUT SOME HTML
    5. else
    6. 'WRITE OUT SOME HTML
    7. end if

    I also call a sub that is in the same page
    VB Code:
    1. Sub DisplayDownloads(LargeFirst)
    2.     If LargeFirst then
    3.        'WRITE OUT SOME HTML
    4.     else
    5.        'WRITE OUT SOME HTML
    6.     end if
    7. End Sub

    Thanks!

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: need to port ASP to PHP

    Here you go

    PHP Code:
    if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") != false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") != false)
    {
        
    //stuff here
    }
    elseif(
    strpos($_SERVER['HTTP_USER_AGENT'],"MSIE") != false)
    {
        
    //stuff here
    }
    else
    {
        
    //stuff here


    And


    PHP Code:
    function DisplayDownloads($LargeFirst)
    {
        if(
    $LargeFirst)
        {
            
    //stuff here
        
    }
        else
        {
            
    //stuff here
        
    }


  3. #3

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: need to port ASP to PHP

    thanks John.

    I knew it was pretty simple, but since I don't do any PHP it would take me a bit longer to get all the syntax right and I am swamped at the moment..

    I will take a look at this and post back with any further questions

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: need to port ASP to PHP

    I make a typo, just changed so if you tried it and it didn't work then that will be why.

  5. #5

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: need to port ASP to PHP

    no prob. I won't get around to making a mock up PHP page to test the code until later today

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: need to port ASP to PHP

    Quote Originally Posted by john tindell
    Here you go

    PHP Code:
    if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") != false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") != false)
    {
        
    //stuff here
    }
    elseif(
    strpos($_SERVER['HTTP_USER_AGENT'],"MSIE") != false)
    {
        
    //stuff here
    }
    else
    {
        
    //stuff here


    And


    PHP Code:
    function DisplayDownloads($LargeFirst)
    {
        if(
    $LargeFirst)
        {
            
    //stuff here
        
    }
        else
        {
            
    //stuff here
        
    }

    You need to use !== as the strpos function can return if the string is found at the beginning at position; you've guessed it, 0.
    PHP Code:
    if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") !== false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") !== false)
    {
        
    //stuff here

    Don't you also need to check for CRL / CLR in the useragent?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: need to port ASP to PHP

    Quote Originally Posted by visualAd
    You need to use !== as the strpos function can return if the string is found at the beginning at position; you've guessed it, 0.
    PHP Code:
    if(strpos($_SERVER['HTTP_USER_AGENT'],"1.1.4322") !== false || strpos($_SERVER['HTTP_USER_AGENT'],"2.0.40607") !== false)
    {
        
    //stuff here

    Don't you also need to check for CRL / CLR in the useragent?

    Its been a long couple of days

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: need to port ASP to PHP

    well I know I am going to need to install PHP on my system to test this locally.

    Is PHP easy to UNINSTALL if I decide later on that I do not want it on my system anymore?

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: need to port ASP to PHP

    also does PHP run on IIS? since that is the only dev web server install on my box

    I am guessing yes, but you guys are the PHP pros

  10. #10
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: need to port ASP to PHP

    Yes - technically you do not NEED to run the PHP installer. Just download the ZIP file off their site and extract it to a directory. You can either run PHP as an IIS ISAPI module or a CGI.

    Which OS are you running on, the configuration is quite easy.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  11. #11

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: need to port ASP to PHP

    XP Pro SP2 is the one I was going to load it on. I have several PCs in the office (including a 2003 server machine) but for dev I would like to use the XP pro box.

  12. #12

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: need to port ASP to PHP

    I was able to install PHP5 and I got the code ported over and its working fine.

    Thanks.

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [RESOLVED] need to port ASP to PHP

    Great... now start porting all your other code. It'll be worth it. Promise
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [RESOLVED] need to port ASP to PHP

    I do little code in ASP anymore.. I do everything new in ASP.NET

    This was for some legacy code that needs to go on a clients own webserver, which is linux/php

Posting Permissions

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



Click Here to Expand Forum to Full Width