« Php » : différence entre les versions

Aucun résumé des modifications
Aucun résumé des modifications
 
Ligne 21 : Ligne 21 :
return ($httpcode>=200 && $httpcode<300) ? $data : false;
return ($httpcode>=200 && $httpcode<300) ? $data : false;
}
}
</syntaxhighlight>
</syntaxhighlight><br>
 
== Autoriser l'accès https ==
== Autoriser l'accès https ==
<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
;fichier php.ini ajouter la ligne
;fichier php.ini ajouter la ligne
extension=php_openssl.dll
extension=php_openssl.dll
</syntaxhighlight>
</syntaxhighlight><br>
 


== Renvoyer un fichier à télécharger ==
== Renvoyer un fichier à télécharger ==
Ligne 47 : Ligne 49 :
</script>';
</script>';
?>
?>
</syntaxhighlight>
</syntaxhighlight><br>
 


== Liens Externes ==
== Liens Externes ==

Dernière version du 6 février 2023 à 08:41

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