Php

Afficher une variable en format "pretty print"

Pour cela il suffit d'encadrer le code de <pre> </pre>

echo "<pre>";
foreach ($seg->points as $point)
{
    echo print_r($point, true);
}
echo "</pre>";

Récupérer le contenu d'une url

// fonction à utiliser
// on suit les redirections
function getUrlContent($url){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)');
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
	curl_setopt($ch, CURLOPT_TIMEOUT, 5);
	$data = curl_exec($ch);
	$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);
	return ($httpcode>=200 && $httpcode<300) ? $data : false;
}


Autoriser l'accès https

;fichier php.ini ajouter la ligne
extension=php_openssl.dll


Renvoyer un fichier à télécharger

<?
header("Content-disposition:filename=tempEtudiant.txt");
header("Content-type:application/octetstream");
?>
#après lister le fichier
readfile("tempEtudiant.txt");

Renvoyer une url

<?php
echo '<script language="Javascript">
<!--
document.location.href="visualiser_news_frame.php?id_news=' . $last_new . '";
// -->
</script>';
?>



Liens Externes