user3026548
user3026548

Reputation: 11

php using filename as a condition for if/else statement

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.

Upvotes: 0

Views: 496

Answers (2)

cornelb
cornelb

Reputation: 6066

<iframe src="<?php echo basename($_SERVER['PHP_SELF']) == 'index.php' ? $HOMEPAGEURL : $SITEPAGESURL ?>" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe>

Upvotes: 0

AbraCadaver
AbraCadaver

Reputation: 78994

Try:

if(strpos($_SERVER['PHP_SELF'], 'index.php') !== false) {

Or:

if(basename($_SERVER['PHP_SELF']) == 'index.php') {

Upvotes: 1

Related Questions