Allow html tags and files only to particular page URL using php | 2my4edge

10 April 2015

Allow html tags and files only to particular page URL using php

We are mostly using header and footer as separate page. so that time when we are adding one in header or footer file it will affect all the files that, so for we have to take that files only to the particular url, then only it will works well. we can add css, javascript and jquery to particular page. so her we have only solution for that. simple php code will help you to do this. lets see the code.

all css and jquery javascript for particular files

To find server name
<?php
echo $_SERVER['SERVER_NAME'];
?>

The above code Output is like

www.something.com

i run this code in my demos site so my output will be like

demos.2my4edge.com

To know the current requsting URL
<?php
echo $_SERVER['REQUEST_URI'];
?>

It will show the current requesting page. if you are running this code in demos.2my4edge.com/url/url.php means the output will be like.

/url/url.php

Consider There are 3 files.
index.php
main.php
url.php

INDEX.PHP
<?php
    $currenturl = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    if($currenturl == 'demos.2my4edge.com/url/' || 
       $currenturl == 'demos.2my4edge.com/url/main.php' || 
       $currenturl == 'demos.2my4edge.com/url/index.php'  ) 
    {
    echo '<p> Welcome main pages <p>';
    echo '<title>Welcome page</title>';
    }
    else
    {
    echo '<p> Inner page </p>';
    echo '<title>Inner page</title>';
    }
?>
the above code is the index file code. this code will runs in all the pages.

MAIN.PHP
<?php 
include('index.php');
?>

URL.PHP
<?php 
include('index.php');
?>

so the above INDEX.PHP code runs in all the page.

$currenturl = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 

is getting the current url by the concatenation operator of both SERVER_NAME and REQUEST_URI.  We are checking that by using if(condition). if the url path is correct it will run. like the above index.php file code you can give if condition as you need. 

NOTE : Don't use HTTP:// or HTTPS:// it wont accept. i hope this is really helpful to you.




RELATED POST :

Basic of php and mysql ( insert coding )
Detect operating system and browser using Php
Comment system using php and MYSQL
live availability Check using php and Ajax
File download coding using PHP and MySql
Insert and view data without refresh using PHP, MySql and AJAX
Basic insert, view, edit, delete and update using PHP and Mysql
Add / SUM the table row values in database using PHP

3 comments:

  1. Great blog post. Very informative for developers. Looking for more posts like this!

    ReplyDelete
  2. Great post.

    ReplyDelete
  3. Quite handy information for PHP developers. This can be a very helpful for PHP developers for improving their knowledge and also for improving their work performance. Keep sharing like this.

    ReplyDelete

^