php can not load js css solution: 1, check the correct path to load; 2, prohibit the use of absolute path; 3, use relative path to load the file can be.

What if php can't load js css?

The solution of php can not load js css:

1.The path must be absolutely correct, based on the project after the js, css file location path must be an absolute path

   For example, if the project location is under D://studys/aa/bb, the project name is cc, and the js file path is D://studys/aa/bb/cc/public/js/dd.js, then the load path should be aa/public/js/dd.js

2.Don't use absolute paths

   Because of the absolute path, after the files are placed on other computers, the js and css files will not be loaded, because the system disk where we store the php files is very likely to be different

3.When we use relative paths, we have to be good at using $_SERVER as a global variable to get them, generally loading these files using dirname($_SERVER['SCRIPT_NAME'])

     $_SERVER['SCRIPT_NAME'] gets the relative location of the inde.php entry file, where dirname() means relative to a path on inde.php

    For example $_SERVER['SCRIPT_NAME'] gets the result: aa/bb/cc/index.php, then dirname($_SERVER['SCRIPT_NAME'] gets the result: aa/bb/cc, this result is generally intercepted to the frame name location - -Index.php final location in the framework folder, at this time, we then according to the results obtained, and we place js, css file location, a splice, we can get access to js, css file relative path

Related articles

php how to check user ip

php query user ip method: 1, get user ip by "$_SERVER["REMOTE_ADDR"]" way; 2, get user ip by "($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];" to get the user ip and so on.

How to invert a string by word in php

Inversion methods: 1. use "explode(' ',$str)" statement to convert string to array; 2. use "array_reverse($arr)" statement to invert the array and return the array in the reverse order of elements; 3. use "implode(' ',$arr)" statement to convert the inver

php get maximum value in several numbers

In php, you can use the max() function to get the maximum value among several numbers. The function works by calculating and returning the maximum value among several specified values, with the syntax "max(value1,value2,...) ;".

How to convert php image to base64

php image to base64 method: 1, get an image address; 2, through the "chunk_split(base64_encode($gambar));" method to convert the image to base64 string format can be.

How to merge arrays in PHP

How to merge arrays in PHP? To do this we need to use the array_merge function and the array_merge_recursive function. Here we will introduce these two functions separately.

How to compare strings in PHP?

String is an important data type in PHP, which how to compare strings is also very common in our development work, there are many kinds of comparison methods to compare strings, here we will introduce the more commonly used several comparison methods.

The difference between jumps and redirects in PHP

Difference: 1. Jump is the current URL request success, re-request a new URL; while redirect is the current URL is invalid, was redirected to a new URL. 2. In the jump, the browser will record the current URL and the new URL to the history; while redirect

How to merge elements of different arrays in php

php merge different array elements method: 1, create a PHP sample file; 2, by "array_keys(array_flip($a) + array_flip($b) + array_flip($c));" way to multiple arrays can be merged and de-weighted.

The php exec function does not work

The solution for the php exec function not taking effect: 1. Open the /etc/php.ini file, delete the exec, then save and restart php-fpm; 2. Change the value of "safe_mode" to off.