The file_get_contents() function in PHP is an inbuilt function that is used to read a file into a string. The function uses memory mapping techniques that are supported by the server and thus enhance the performance making it a preferred way of reading the contents of a file. The path of the file to be read, which is sent as a parameter to the function and it returns the data read on success and FALSE on failure.
Example:
PHP
<!DOCTYPE html>
<body>
<?php
// Reading contents from the
// geeksforgeeks homepage
$homepage = file_get_contents(
"https://horje.com/");
echo $homepage;
?>
</body>
</html>
PHP cURL is a PHP Function which request an URL to view the page sources.
Example:
PHP
<?php
$urlssss1='https://horje.com';
// Step 1
$cSession = curl_init();
// Step 2
curl_setopt($cSession,CURLOPT_URL,''.$urlssss1.'');
curl_setopt($cSession,CURLOPT_RETURNTRANSFER,true);
curl_setopt($cSession,CURLOPT_HEADER, false);
// Step 3
$d221=curl_exec($cSession);
echo $d221;
?>
A way to load xml sitemap its url
Example:
PHP
<?php
$affectedRow = 0;
$url1 = 'https://wordpress.org/plugins/sitemap-2.xml';
$xml = simplexml_load_file("$url1") or die('Sorry');
foreach ($xml->children() as $row) {
$link = $row->loc;
echo $link;
echo '</br>';
if (! empty($result)) {
$affectedRow ++;
} else {
$error_message = mysqli_error($conn) . "\n";
}
}
if ($affectedRow > 0) {
$message = $affectedRow . " URLs have been crawled. It will index in the next crawl date";
} else {
$message = "No records inserted";
}
?>
<div class="affected-row"><?php echo $message; ?></div>
<?php if (! empty($error_message)) { ?>
<div class="error-message"><?php echo nl2br($error_message); ?></div>
<?php } ?>
Here I make a simple code.
Example:
PHP
<?php
function fsize($path) {
$fp = fopen($path,"r");
$inf = stream_get_meta_data($fp);
fclose($fp);
foreach($inf["wrapper_data"] as $v) {
if (stristr($v, "content-length")) {
$v = explode(":", $v);
return trim($v[1]);
}
}
return 0;
}
?>
<?php
$file = "https://downloads.wordpress.org/plugin/wordpress-seo.22.6.zip";
$inbytes = fsize($filesize);
echo $inbytes;
?>
Example:
PHP
<?php
# define file array
$files = array(
'https://www.google.com/images/logo.png',
'https://en.wikipedia.org/static/images/project-logos/enwiki-2x.png',
);
# create new zip object
$zip = new ZipArchive();
# create a temp file & open it
$tmp_file = tempnam('.', '');
$zip->open($tmp_file, ZipArchive::CREATE);
# loop through each file
foreach ($files as $file) {
# download file
$download_file = file_get_contents($file);
#add it to the zip
$zip->addFromString(basename($file), $download_file);
}
# close zip
$zip->close();
# send the file to the browser as a download
header('Content-disposition: attachment; filename="my file.zip"');
header('Content-type: application/zip');
readfile($tmp_file);
unlink($tmp_file);
?>
You can set our 404 page that surely fetch to Google as a 404 status.
Paste following codes which Page You want to show 404.
Example:
PHP
<?php
http_response_code(404);
?>
<!DOCTYPE html>
<html lang="en">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background-color: #D3D3D3;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.error-container {
text-align: center;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 5rem;
color: #ff5733;
}
p {
font-size: 1.5rem;
color: #333;
margin-bottom: 20px;
}
a {
text-decoration: none;
background-color: #ff5733;
color: #fff;
padding: 10px 20px;
border-radius: 3px;
font-weight: bold;
transition: background-color 0.3s ease;
}
a:hover {
background-color: #e6482e;
}
</style>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<title>
404 Page Not Found
</title>
<link rel="stylesheet"
href="style.css">
</head>
<body>
<div class="error-container">
<h1> 404 </h1>
<p>
Oops! The page you're
looking for is not here.
</p>
<a href="https://horje.com">
Go Back to Home
</a>
</div>
</body>
</html>
<?php
exit;
?>
Just copy and paste following your pages where you want to show 404 page near Search Engine.
Example:
PHP
<?php
http_response_code(404);
?>
<?php
exit;
?>