I need help with a php if/else statement - I am placing an iframe with tracking pixel on a site and I want a certain iframe to appear for the index.php page, but a different iframe for all other pages.
Here is what I have so far:
<?php if($_SERVER['PHP_SELF'] == 'index.php'){?>
<iframe src="HOMEPAGEURL" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe>
<?}else{?>
<iframe src="SITEPAGESURL" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe>
<?}?>
Any help would be greatly appreciated.
Thank you.
Try:
if(strpos($_SERVER['PHP_SELF'], 'index.php') !== false) {
Or:
if(basename($_SERVER['PHP_SELF']) == 'index.php') {
<iframe src="<?php echo basename($_SERVER['PHP_SELF']) == 'index.php' ? $HOMEPAGEURL : $SITEPAGESURL ?>" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.