douwen9534 2012-11-28 05:25
浏览 21

PHP:IF域等于[x]然后是[actions]而不是子目录/文件

I am trying to execute code with PHP but only IF the URL is EXACTLY at the entry point of the website: http://mywebsite.com. So specifically ONLY on that URL, nothing after. I am stumped after trying multiple PHP IF ELSE statements to try gaining it, very close I feel.

<?php $host = $_SERVER['HTTP_HOST']; if($host == "www.mywebsite.com" or $host == "mywebsite.com") { ?> MYHTML1SHOWS <?php } else { ?> MYHTML2SHOWS <?php } ?>

This has given me success in appearing on the domain when most visitors will come to mywebsite.com, but continues to work on all subsequent sub files/pages/directories. Which is 100% not wanted.

So I thought of a work around like ELSEIF's to show MYHTML2 to target all my pages, as they are handily all within country allocated directories: /au/ , /asia/ , /nz/ , /uk/ etc.

<?php } elseif (stripos($_SERVER['REQUEST_URI'],'/au/') !== false) { ?> HTML3 <?php } ?>

This didn’t work, but it was worth a try (works on its own IF statement in previous websites I’ve done, but I figure its clashing with the first IF statement which is more prioritized in the PHP). Appreciate any help guys, this has me stumped but would be ever useful. There were no similar questions on the net for only showing code this way.

(Background: I am implementing a 'Country Selector' that shows only on the entry point of mywebsite.com. I have already set up each country within their own sub-directories, thus no purpose of showing the country selector for them if a customer goes directly to one of those addresses).

  • 写回答

1条回答 默认 最新

  • dongtie0929 2012-11-28 05:35
    关注

    You're probably doing some magic with Apache's mod_rewrite ... if not, that might be a good place to start looking. It sounds like the problem you're trying to solve is best done via Apache, either in your httpd.conf or (if enabled) via .htaccess.

    http://httpd.apache.org/docs/current/mod/mod_rewrite.html

    Otherwise, the $_SERVER variables $_SERVER['PHP_SELF'] and $_SERVER['REQUEST_URI'] are probably of use to you.

    http://www.php.net/manual/en/reserved.variables.server.php

    $_SERVER['HTTP_HOST'] will only check the domain name, not the requested path. This is as you describe, but doesn't seem to be what you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line