Php
De whats Wiki
Instal·lar noves extencions
pecl install imagick
Executar un script amb un altre php.ini
php -c /etc/php.insecure.ini script.php
Per fer una redirecció d'una web
<?php
header("Location: http://www.wekk.net/index2.php");
?>
Per fer que el php no pugui obrir arxius que tenen un uid diferent del propietari de l'arxiu php, cal afegir al php.ini
safe_mode = On
safe_mode_include_dir = /usr/bin
Per veure info sobre el server
print_r($_SERVER); echo $_SERVER["HTTP_HOST"];
Contingut |
CAPÇALERES DE CACHÉ
Per a que no cachegi mai res
header("Content-type: text/plain");
header("Expires: Sat, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: Thu, 09 Feb 2006 10:05:57 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
Per a que cachegi durant un temps (en aquest cas 3h)
$offset = 60*60*3;
Header("Cache-Control: must-revalidate");
//Header("Cache-Control: proxy-revalidate");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
Header($ExpStr);
eaccelerator
Optimitzador i cachejador dels scripts php un cop ja "compilats"
Instal·lar-lo
phpize ./configure make make install
Actualitzar el php
- Desactivar el eaccelerator (comentar el .ini)
- Actualitzar el php
- make clean
- phpize
- ./configure
- make
- make install
- Activar el eacelerator
- iptables -A INPUT -p tcp --dport 80 -s la_teva_ip -j ACCEPT
- iptables -A INPUT -p tcp --dport 80 -j DROP
- Fer un reload de l'apache i veure si tot funciona ok
- iptables -D INPUT -p tcp --dport 80 -s la_teva_ip -j ACCEPT
- iptables -D INPUT -p tcp --dport 80 -j DROP
Canviar charset d'una Base de dades
$COLLATION_TO = "utf8_unicode_ci"; $COLLATION_BINARY_TO="utf8_bin"; $COLLATION_FROM = "latin1_spanish_ci"; $COLLATION_BINARY_FROM="latin1_bin"; $CHARACTER_SET_TO = "utf8";
$db = mysql_connect( "climisql", 'promeba_2009', 'prMB159' ); mysql_select_db( 'promeba_db', $db);
$result = mysql_query( "SHOW TABLES;" );
while ($table = mysql_fetch_array($result, MYSQL_NUM)) {
//$query = "ALTER TABLE ".$table[0]." COLLATE ".$COLLATION_TO;
//printf("%s\n", $query);
//$row = mysql_query($query);
//if (!$row) echo "ERROR: ". mysql_error();
$query ="SHOW FULL COLUMNS FROM $table[0] WHERE Collation = '".$COLLATION_FROM."'";
printf("%s\n", $query);
$row = mysql_query($query);
while ($column = mysql_fetch_array($row, MYSQL_NUM)) {
//printf("\t%s(%s)\n", $column[0], $COLLATION_FROM);
$query ="ALTER TABLE $table[0] CHANGE $column[0] $column[0] $column[1] CHARACTER SET $CHARACTER_SET_TO COLLATE $COLLATION_TO";
echo " => $query\n";
$a = mysql_query($query);
if (!$a) echo "ERROR: ". mysql_error();
}
} echo "done!";
Proxy amb PHP
<?php
# NOTE: The idea is that your url will be the same as us, but with a new parameter like "requestid" to test if the request is valid
# Config
$PROXY_BASE="/proxy";
$IMAGE_BASE="/webviewer";
$IMAGE_SERVER="10.84.130.17";
# Check that is a valid request (sample)
if (! check($_SERVER[REQUEST_URI]) ){
echo "This isn't a validated request!";
exit();
}
# Here we'll remove the garbage (proxy base and your requestid)
$from = str_replace($PROXY_BASE, "", $_SERVER[REQUEST_URI]);
# We generate the url to connect
$to = "http://" . $IMAGE_SERVER . $IMAGE_BASE . $from;
# Send the response of the IMAGE_SERVER to the client
$file = fopen ( $to, "r");
while (!feof($file)) {
echo fread($file, (1*(1024*1024)));
flush();
}
?>
