PHP Question: how to make include(); depending on URL?
PHP programming question:
Is it possible to tell a PHP page to include one or another file depending on URL location? For example: if URL is http://mysite.com/something.php, then include(file_for_something.php); if URL is http://mysite.com/something_else.php, then include(file_for_something_else.php); What is the syntax for this kind of includes if that exists? Thanks. |
You could try this:
Code:
<?php |
Thanks a lot for your kind help. I see the idea.
I wanted to use this kind includes to include different meta tags for different pages. It should be readable first of all for search engines. I was eventually thinking about fopen(). I.e., first check whether the file exists and is opened, and then include the necessary meta tags. There is just one template on the site, and lots of inserts: index.php?page=1, index.php?page=2 etc. HTTP_REFERER works exactly the way you told, but it can't be used for calling meta tags, because it calls wrong meta tags for wrong pages. I did not realize it before I tested it on my localhost. |
Now I am trying this:
PHP Code:
:confused: |
Hm, seems to me you're testing a String and this will always return true.
Imho both files would have to be included if you do it like that. |
nephilim has a good point
Code:
if ($_SERVER['URL_ROOT']."/index.php?page=main") It should be Code:
if ($_SERVER['URL_ROOT']."/index.php?page=main" == something) If the page URL is exactly the same until the ?page= GET statement why not test Code:
if ($page == "main") {statement} |
returning the favor: Andy@DP has a good point too ;)
The name of your page is indeed an url parameter, so it would be in the $page variable. |
Hi Nephilim & Andy@DP,
Thanks for all your comments! This, of course, works: PHP Code:
I am happy to have learnt so much in just a couple of days! THANKS A LOT! :D |
All times are GMT -5. The time now is 11:03 AM. |