locked
How can I run 1 .php file on a ASP.NET MVC web application, with IIS7.5? RRS feed

  • Question

  • User747696199 posted

    HI,

    I'm supporting a MVC3 asp.net web application, and needed to integrate a sharrre plug in to the application - which adds Facebook, Google+, Twitter, etc. social icons to the site.

    All works but Google+, which requires a .php file to be placed under:  ../Dir1/Dir2/sharrre.php.

    This .php file will be called by a .js file, under the same directory:  ../Dir1/Dir2/jquery.sharrre.js.

    The application use the AppPool with Integrated Management Pipeline Mode, the asp.net v4.0 AppPool.

    Note: the site will be an asp.net site; it does not need to configured as a php site at all; I only need this 1 .php file to be ran.

    I need to make sure that this .php file can be called and ran on the web server (IIS 7.5).

    Is there anything I need to do in the IIS Manager? File Handler?

    Please let me know.

    Thanks,

    Claudia

    Update: I found this post: http://stackoverflow.com/questions/13254155/run-php-file-inside-asp-net-mvc-4-application-on-iis-7

    Please let me know if this is the right approach? If yes, how do I "configure the routing to ignore requests to this page"? Can anyone provide some sample code?

    Thanks!

    Wednesday, August 3, 2016 1:41 AM

Answers

  • User2053451246 posted

    If the PHP file has any server side code that needs to run to generate the output you need to setup PHP on your web server.  If it's just static HTML/Javascript/CSS, just change the file extension.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2016 5:30 PM
  • User2053451246 posted

    I would suggest downloading Web Platform Installer and using that to install the necessary stuff.  It does a good job and automates all of it for you.

    https://www.microsoft.com/web/downloads/platform.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 11, 2016 3:26 PM

All replies

  • Wednesday, August 3, 2016 5:24 AM
  • User747696199 posted

    Hi,

    I don't want to configure a PHP site.

    I just need to make sure that this 1 php file can run inside my asp.net site.

    Please clarify exactly what I need to do - I only want to make the minimal change to the exisiting asp.net site.

    Thanks,

    Claudia

    Wednesday, August 3, 2016 3:20 PM
  • User2053451246 posted

    If the PHP file has any server side code that needs to run to generate the output you need to setup PHP on your web server.  If it's just static HTML/Javascript/CSS, just change the file extension.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 3, 2016 5:30 PM
  • User-2057865890 posted

    Hi claudia,

    If yes, how do I "configure the routing to ignore requests to this page"? Can anyone provide some sample code?

    You could try using URL Rewrite like below.

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="RequestBlockingRule1" patternSyntax="Wildcard">
                    <match url="*" />
                    <conditions>
                        <add input="{URL}" pattern="*.php*" />
                    </conditions>
                    <action type="CustomResponse" statusCode="403" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>

    reference: http://stackoverflow.com/a/1539452 

    Best Regards,

    Chris

    Thursday, August 4, 2016 2:37 PM
  • User747696199 posted

    Thanks ryanbesko!

    I'm not sure what you meant by "change the file extension"? did you mean change the ".php" to something else? Other files need to call his .php file, I'm not sure if I can do that.

    Below is the whole content of the .php file - please let me know which situation this falls under, based on your previous comment:

    <?php
      header('content-type: application/json');
      //Sharrre by Julien Hany
      $json = array('url'=>'','count'=>0);
      $json['url'] = $_GET['url'];
      $url = urlencode($_GET['url']);
      $type = urlencode($_GET['type']);
     
      if(filter_var($_GET['url'], FILTER_VALIDATE_URL)){
        if($type == 'googlePlus'){  //source http://www.helmutgranda.com/2011/11/01/get-a-url-google-count-via-php/
          $contents = parse('https://plusone.google.com/u/0/_/+1/fastbutton?url=' . $url . '&count=true');

          preg_match( '/window\.__SSR = {c: ([\d]+)/', $contents, $matches );

          if(isset($matches[0])){
            $json['count'] = (int)str_replace('window.__SSR = {c: ', '', $matches[0]);
          }
        }
        else if($type == 'stumbleupon'){
          $content = parse("http://www.stumbleupon.com/services/1.01/badge.getinfo?url=$url");
          
          $result = json_decode($content);
          if (isset($result->result->views))
          {
              $json['count'] = $result->result->views;
          }

        }
      }
      echo str_replace('\\/','/',json_encode($json));
     
      function parse($encUrl){
        $options = array(
          CURLOPT_RETURNTRANSFER => true, // return web page
          CURLOPT_HEADER => false, // don't return headers
          CURLOPT_FOLLOWLOCATION => true, // follow redirects
          CURLOPT_ENCODING => "", // handle all encodings
          CURLOPT_USERAGENT => 'sharrre', // who am i
          CURLOPT_AUTOREFERER => true, // set referer on redirect
          CURLOPT_CONNECTTIMEOUT => 5, // timeout on connect
          CURLOPT_TIMEOUT => 10, // timeout on response
          CURLOPT_MAXREDIRS => 3, // stop after 10 redirects
          CURLOPT_SSL_VERIFYHOST => 0,
          CURLOPT_SSL_VERIFYPEER => false,
        );
        $ch = curl_init();
        
        $options[CURLOPT_URL] = $encUrl;  
        curl_setopt_array($ch, $options);
        
        $content = curl_exec($ch);
        $err = curl_errno($ch);
        $errmsg = curl_error($ch);
        
        curl_close($ch);
        
        if ($errmsg != '' || $err != '') {
          /*print_r($errmsg);
          print_r($errmsg);*/
        }
        return $content;
      }

    Thanks,

    Claudia

    Tuesday, August 9, 2016 9:39 PM
  • User2053451246 posted

    That has PHP server side code in it.  You will need to setup PHP on your server in order for it to execute.

    Tuesday, August 9, 2016 10:06 PM
  • User747696199 posted

    Thanks ryanbesko!

    Can you suggest what are the minimum steps that are required to "setup PHP" on our web server? We use Windows 2008 R2 + IIS 7.5.

    If you can list the steps, or point us to a post with the correct info - we appreciate it very much!

    Thanks,

    Claudia

    Thursday, August 11, 2016 3:02 PM
  • User2053451246 posted

    I would suggest downloading Web Platform Installer and using that to install the necessary stuff.  It does a good job and automates all of it for you.

    https://www.microsoft.com/web/downloads/platform.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 11, 2016 3:26 PM
  • User747696199 posted

    Thanks a lot ryanbesko!

    1 more question: if I use the Web Platform Installer - will that install MORE stuff than I needed? All I need to do is to run this 1 .php file; and we  would like to install as little as possible, and make as little change as possible on our web server.

    Thanks,

    Claudia

    Thursday, August 11, 2016 5:43 PM