I was asked by my client to use the same remote file HTML file for both the WordPress blog based on php (which i was working on) and the ASP.net Website (that my team mate was on). We were at first thinking if we had heard him right or not. Later in a while we understood that he wanted it that way because he need to update the data by updating it in one single place.
Which was very cool idea. And we have to find a way.
I did a big search and returned with much ideas. Trying each of them had made me more sad. Some that doesn’t give the required output, some that might not work on the remote files and some which needed a security loophole to be opened.
The ideas were ‘include’ function from php, ‘require’ function, a JQuery load method to populate the data, and there was also an html include from w3school (here is the link to it).
Solution in php way (remote file call)
My fellow team-mate solved it in another way and i wanted to share it to everyone who is looking for it.
$content = file_get_contents(‘http://example.com/header.html’);
Note : this may have security issues. Please check with a security expert for clarifications.
How i finished the WordPress site (WordPress way – not the remote file methord)
Now in a short while, i read an article on Quora about how bad can things go if we get remote files in our documents by using include and require (here is the quora link). I asked the client if we need it that way and passed the link. In a short while he replied me that he just needs us to get the header file to be replaceable by just a copy paste so that when a change on header comes in, it can be solved easily.
I was waiting for that reply. 🙂 I quickly had to search the WP Codex to get the get_page_tempalte() to do the job. We could easily attain the similar effect by keeping the header in a .php file and calling it easily using the function. Also we kept the resources in a static domain location so that we could easily call them irrespective of the websites.
I’m looking for more ideas and your comments. Thanks!