Drift/Web: Difference between revisions

From Programvareverkstedet
m (5 revisions)
 
(Added English translation)
 
Line 1: Line 1:
[[#Maintenance/Web|English]]
Denne siden inneholder diverse informasjon om webserveren for PVVs brukere.
Denne siden inneholder diverse informasjon om webserveren for PVVs brukere.


Line 57: Line 59:
Filen lages i katalogen til scriptet som skal kjøres.
Filen lages i katalogen til scriptet som skal kjøres.


* [http://php.net/error_reporting Liste hva slags verdier error_reporting kan ha]
* [http://php.net/error_reporting Liste over hva slags verdier error_reporting kan ha]
 
= 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  <pre><nowiki>
$fp = fopen("http://www.foo.com/data.txt", "r")
 
or
 
include("http://www.foo.net/include.html").
</nowiki></pre>
 
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:
<pre><nowiki>
<?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", "/");
?>
</nowiki></pre>
 
== 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:
 
<pre><nowiki>
php_flag display_errors on
php_value error_reporting E_ALL
</nowiki></pre>
 
The file must be made in the catalog of the script that is to be run.
 
* [http://php.net/error_reporting List of what kind of values error_reporting can have]


__NOTOC__
__NOTOC__

Latest revision as of 16:31, 12 August 2014

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.