Hello!
I want to purge cache of all my internal urls, for example PHP: Introduction - Manual … with Cloudflare, this is my php script , How can I solve my code?
(I tried to format the code but It failed)
Thanks in advance
> <?php
> class Custom_Tools_Cflare
> {
> $urlContent = file_get_contents('http://php.net/');
> public function clear($dir,$host,$uri) {
> $ch = curl_init();
>
> curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/xxxxx/purge_cache");
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"files\":[\"http://xxxxxxx/".$dir."/".$uri."\",{\"url\":\"xxxx.com/".$dir."/".$uri."\",\"headers\":{\"X-Forwarded-Host\":\"".$host."\",\"X-Host\":\"xxxxx\"}}]}");
> curl_setopt($ch, CURLOPT_POST, 1);
>
> $headers = array();
> $headers[] = "X-Auth-Email: xxxxxxxxxxxxx";
> $headers[] = "X-Auth-Key: xxxxxxxxxxxx";
> $headers[] = "Content-Type: application/json";
> curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
>
> $result = curl_exec($ch);
> if (curl_errno($ch)) {
> echo 'Error:' . curl_error($ch);
> }
> curl_close ($ch);
> }
>
> public function myfunction(){
> $html=file_get_contents('xxxxxxxxx');
> $dom=new DOMDocument();
> @$dom->loadHTML($html);
>
> $xpath=new DOMXPath($dom);
> $hrefs=$xpath->evaluate("/html/body//a");
> for($i=0;$i<$hrefs->length;$i++){
> $href=$hrefs->item($i);
> $url=$href->getAttribute('href');
> if (substr( $url, 0, 18 ) === "https://xxxxxxxxxxxxx") {
> echo $url.'<br />';
> clear($dir,$host,$url);
> }
>
> }
> }
> }