CAIO WANDERLEY
CAIO WANDERLEY

Reputation: 313

echo command show all code of the php file

I am learning php, and get these file to change, but the echo command rather than show only the string, shows the entire code of the file.

I am using linux ubuntu and apache2.

<html>
<head>
<style type="text/css">
.tg  {border-collapse:collapse;border-spacing:0;margin:0px auto;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg .tg-0lax{text-align:left;vertical-align:top}
@media screen and (max-width: 767px) {.tg {width: auto !important;}.tg col {width: auto !important;}.tg-wrap {overflow-x: auto;-webkit-overflow-scrolling: touch;margin: auto 0px;}}</style>
</head>
<body>
Welcome to our awesome gallery!</br>
See recent uploaded pictures from our community, and feel free to rate or comment</br>
<?php
require '/var/www/html/lib.php';
$path = '/var/www/html/uploads/';
$ignored = array('.', '..', 'index.html');
$files = array();

$i = 1;
echo "<div class='tg-wrap'><table class='tg'>"."\n";

foreach (scandir($path) as $file) {
  if (in_array($file, $ignored)) continue;
  $files[$file] = filemtime($path. '/' . $file);
}
arsort($files);
$files = array_keys($files);

foreach ($files as $key => $value) {
  $exploded  = explode('.',$value);
  $prefix = str_replace('_','.',$exploded[0]);
  $check = check_ip($prefix,$value);
  if (!($check[0])) {
    continue;
  }
-- snip --
[...]
?>
</table></div>
</body>
</html>

Rather than get just the strings on echo, i get the php code:

look the image --> https://imgur.com/gallery/GCqUgQh

Upvotes: 0

Views: 54

Answers (1)

8ctopus
8ctopus

Reputation: 3237

The problem is that php is not recognized and therefore you see the source instead of the result of executing the php code.

  1. Did you install php on your machine?

    apt install php libapache2-mod-php

  2. Did you name the file with the .php extension?

Upvotes: 1

Related Questions