/    Sign up×
Community /Pin to ProfileBookmark

If and echo question

I am using this syntax, but it is not working, any ideas?

[code=php]
<?php
if ($_SERVER[‘SCRIPT_NAME’] == “index.php”)
{
echo “<div class=’home-nav’>”;
}
else
{
echo “<div class=’inner-nav’>”;
}
?>

[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Nov 17.2010 — Can you define "not working"?
Copy linkTweet thisAlerts:
@comptech520authorNov 17.2010 — Sorry, that would help!

If script name is = to index.php

do this: [FONT=Courier New][COLOR=#007700]echo [/COLOR][COLOR=#dd0000]"<div class='home-nav'>"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New];[/FONT]

[COLOR=black]else do this:[/COLOR] [FONT=Courier New]echo [COLOR=#dd0000]"<div class='inner-nav'>"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New];[/FONT]

[/COLOR]
[/COLOR]
[COLOR=#007700][COLOR=#007700][/COLOR][/COLOR]

[COLOR=black]The not working part,[/COLOR]

[COLOR=#007700][COLOR=#007700][/COLOR][/COLOR]

[COLOR=black]WHEN the script name = contact.php[/COLOR]

[COLOR=#007700][COLOR=#007700][COLOR=black]it still does this [/COLOR][FONT=Courier New]echo [COLOR=#dd0000]"<div class='home-nav'>"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New];[/FONT]

[/COLOR]
[COLOR=black]it does not [FONT=Courier New][COLOR=#007700]echo [/COLOR][COLOR=#dd0000]"<div class='inner-nav'>"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New];[/FONT]

[/COLOR]
[COLOR=#007700][COLOR=#007700][/COLOR][/COLOR][/COLOR]


[/COLOR]
[/COLOR]
Copy linkTweet thisAlerts:
@criterion9Nov 17.2010 — Try this to see if you are getting the results you want:
[code=php]
echo "Script name: ".$_SERVER['SCRIPT_NAME']."<br />";
if ($_SERVER['SCRIPT_NAME'] == "index.php")
{
echo "<div class='home-nav'>";
}
else
{
echo "<div class='inner-nav'>";
}
[/code]
Copy linkTweet thisAlerts:
@NogDogNov 17.2010 — I believe $_SERVER['SCRIPT_NAME'] will be from the web root directory, so it might have a value like "/directory_name/file_name.php", in case that's your issue.

PS: Maybe use the basename() function?
[code=php]
if(basename($_SERVER['SCRIPT_NAME']) == index.php) {
[/code]
×

Success!

Help @comptech520 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...