Drift/Web

From Programvareverkstedet
Jump to navigation Jump to search

English

Denne siden inneholder diverse informasjon om webserveren for PVVs brukere.

PHP-konfigurasjon

Lasting av URLer med fopen() o.l.

Fordi lasting av filer fra en URL via fopen(), include() og tilsvarende funksjoner i PHP er en stor sikkerhetsrisiko er dette slått av på PVV fra og med 7. april 2006. Det vil si at du ikke lenger kan gjøre fing som

$fp = fopen("http://www.foo.com/data.txt", "r")

 eller

include("http://www.foo.net/include.html").

Dersom du er avhengig av å laste websider eller filer fra andre webservere må du heretter bruke funksjoner som fsockopen() e.l. for å hente filer fra andre maskiner, f.eks.:

<?php

function get_url($host, $path, $port = 80) {

  $fp = @fsockopen($host, $port, $errno, $errstr, 5.0);
  if (!is_resource($fp)) {
    return $errstr;
  }

  // Send request
  fputs($fp, "GET $path HTTP/1.0\nHost: $host:$port\n\n");

  // Skip HTTP-header
  while (!feof($fp)) {
    $line = fgets($fp, 1024);
    if (trim($line) == '') break;
  }

  // Read body
  $body = '';
  while (!feof($fp)) { $body .= fgets($fp, 1024); }

  fclose($fp);

  return $body;
}

print get_url("www.pvv.ntnu.no", "/");
?>

Visning av feilmeldinger

I utgangspunktet er ikke php-feilmeldinger vist. Til at feilmeldinger skal vises, lag filen .htaccess med følgende innhold:

php_flag display_errors on
php_value error_reporting E_ALL

Filen lages i katalogen til scriptet som skal kjøres.

Maintenance/Web

This pabe contains various information on the web-server for PVVs users.

PHP-configuration

Loading of URLs with fopen() and such

Because the loading of files from an URL by fopen(), include(), and similar functions in PHP is a huge security risc it is disabled at PVV from the 7. of April 2006. It means that you no longer can do things such as

$fp = fopen("http://www.foo.com/data.txt", "r")

 or

include("http://www.foo.net/include.html").

If you are dependent on loading webpages or files from other web-servers you hereafter have to use functions such as fsockopen() or similar to fetch files from other machines, to get files from other machines, for an instance:

<?php

function get_url($host, $path, $port = 80) {

  $fp = @fsockopen($host, $port, $errno, $errstr, 5.0);
  if (!is_resource($fp)) {
    return $errstr;
  }

  // Send request
  fputs($fp, "GET $path HTTP/1.0\nHost: $host:$port\n\n");

  // Skip HTTP-header
  while (!feof($fp)) {
    $line = fgets($fp, 1024);
    if (trim($line) == '') break;
  }

  // Read body
  $body = '';
  while (!feof($fp)) { $body .= fgets($fp, 1024); }

  fclose($fp);

  return $body;
}

print get_url("www.pvv.ntnu.no", "/");
?>

Displaying of error messages

By default php error messages are not shown. For error messages to be shown, make the file .htaccess with the following content:

php_flag display_errors on
php_value error_reporting E_ALL

The file must be made in the catalog of the script that is to be run.