'How can I add CDN in php using require_once()?
I'm trying to insert my CSS which is in github repo but when I call it in my php file using require_once() it's not working.
Here is my code:
<?php
require_once("https://nishant5harma.github.io/Ctools/Ctools__CSS/navbar.css");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p>Hello</p>
</body>
</html>
Anyone help me out with this that is it possible? to do this someting like this or I have to store my file in my local system to do this?
Solution 1:[1]
The CSS needs to be inside a <style>
tag, which should be in <head>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
<?php
require_once("https://nishant5harma.github.io/Ctools/Ctools__CSS/navbar.css");
?>
</style>
</head>
<body>
<p>Hello</p>
</body>
</html>
You also need to enable URLs in include/require
with
allow_url_include = On
in your php.ini
.
Although normally you would have the client do this using a <link>
tag.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://nishant5harma.github.io/Ctools/Ctools__CSS/navbar.css" rel="stylesheet">
</head>
<body>
<p>Hello</p>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |