How to rewrite head to inject JS and or Css – Php

You can 'inject' javascript or css code into a page by either using the <script> and <style> tags within the page, or by generating a dynamic .js and/or .css file using PHP.
I mostly use the first option, for example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" xml:lang="en">


        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

        <link rel="stylesheet" href="/css/main.css" />
        <style type="text/css">

                echo 'body { background: url("'.$some_image_path_from_database.'"); }';


        <script type="text/javascript" src="/js/main.js"></script>
        <script type="text/javascript">

                echo 'var userid = '.$some_user_data_from_database.';';






Tinggalkan Balasan

Please log in using one of these methods to post your comment:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s