当前位置: 动力学知识库 > 问答 > 编程问答 >

Include my PHP api on each websites

问题描述:

Hi how can I include my PHP API on each site without touching there codes and no javascript will be used.

Here is what my api does.

when they visit a page the first to show is my api(the interface that ask a user to share it's location) then after that it will redirect to the main page how can I include my api without touching there codes or touching the index.tpl/main.tpl because they used a different frameworks?

网友答案:

One option is to tell the HTTP server to serve your file instead of the normal index file, and then your script will redirect to the original index file or home page when you are done.

This is usually done through redirection in the .htaccess file. Add this line to get your custom script to run first:

DirectoryIndex pre-index-script.php
网友答案:

The question is a little unclear, here is how I understood it:

When a new user arrives at your site, you want to display a page before they see the page they requested. But you want to do this without modifying to code of the site.

And with that assumption, my answer:

You can automatically "include" a php script at the start (or end) of any request by using the "auto_prepend_file" configuration directive. If you have access to your configuration, or possibly in a .htaccess file you should be able to add something like:

php_value auto_prepend_file /path/to/your/script.php

Now that script will be added at the start of every request.

In that script you can check if the user is a new visitor, possibly by using a cookie or sessions, and show them to your "intro" page either with a header redirect or by just displaying it and then exiting to prevent the normal page loading.

Hopefully that points you in the right direction.

分享给朋友:
您可能感兴趣的文章:
随机阅读: