0

when the link http://127.0.0.1:8080/example.php?id=38 will be executed I can't see the content of this page php... chrome will download this file !!

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>test</title>
       
        <script src="public/jquery-1.11.2.min.js" type="text/javascript"></script>
    </head>

    <body>
    <?php
     // check the input
            //is_numeric($_GET['id']) or die("invalid URL");
           
  ?>
    </body>
    <script type="text/javascript">
     console.log(<?php $_GET['id'] ?>);
    </script>
    </html>
Fredj
  • 59
  • 2
  • 9
  • Seems like your html above is incomplete? You're at least missing the
    tag.
    – Pat Mar 15 '17 at 11:34
  • same problem without form ! – Fredj Mar 15 '17 at 11:36
  • So when you're trying to access this page, it's being downloaded directly instead of the PHP engine being activated? My best guess is that your web server is not configured correctly to trigger the PHP server. Are you using the built-in web server in PHP, or something else like Apache or nginx? – Pat Mar 15 '17 at 11:41
  • yes I'm using Apache v 2.4.23 – Fredj Mar 15 '17 at 11:47
  • Is it Laravel Project? – matinict Mar 15 '17 at 11:53
  • no Im using angularJS just i want to open the content of this file in modal – Fredj Mar 15 '17 at 11:56
  • If it's trying to download the file it's because the server doesn't know how to handle php extensions, you'll need to ensure you have .php as a type and also that php module is loaded in the apache config file. I presume your HTML files all work ok? – PhilS Mar 15 '17 at 11:56

1 Answers1

0

This is normally due to an improper handler code. In the .htaccess file, you will want to ensure the handler code matches your version of php. If it does not, the php files may try to download instead of process.

To use the default php version on the server, use the following code:

Use system PHP5 as default

AddHandler application/x-httpd-php5 .php

You may also specify different php versions, depending on your need:

Use system PHP5.2 as default

AddHandler application/x-httpd-php52 .php

Use system PHP5.3 as default

AddHandler application/x-httpd-php53.php

Use system PHP5.4 as default

AddHandler application/x-httpd-php54 .php

Use system PHP5.5 as default

AddHandler application/x-httpd-php55 .php

Also try:

The correct AddType for php is application/x-httpd-php

AddType  application/x-httpd-php         .php
AddType  application/x-httpd-php-source  .phps

Also make sure your php module is loaded

LoadModule php5_module        modules/mod_php55.so

When you're configuring apache then try to view the page from another browser - I've had days when chrome stubbornly caches the result and it keeps downloading the source code while in another browser it's just fine. Refer for more - here

Community
  • 1
  • 1
Ravistm
  • 2,163
  • 25
  • 25