/    Sign up×
Community /Pin to ProfileBookmark

PHP_SELF Question

How can I make this code work”

[code=php]
<?php
if $_SERVER[‘PHP_SELF’] = index.php echo “This IS Index”;
else echo “This IS NOT Index”;
?>[/code]

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 25.2008 — You need to quote "index.php", plus put the conditional within parens, and use "==" not "=" to do the comparison:
[code=php]
<?php
if($_SERVER['PHP_SELF'] == "index.php") echo "This IS Index";
else echo "This IS NOT Index";
?>
[/code]
Copy linkTweet thisAlerts:
@comptech520authorJul 25.2008 — I tried adding " around index.php, still nothing
Copy linkTweet thisAlerts:
@comptech520authorJul 25.2008 — I am using this for navigation. If the self = songs.php the navigation line will have a css tag in it.

For some reason this isn't working. I am on index.php and the php_self thinks that I am not, any clue on this?


[code=php]
<?php
if ($_SERVER['PHP_SELF'] == "/index.php") echo '<li><div><a href="index.php" id="current">Home</a></div></li>';
else echo '<li><div><a href="index.php">Home</a></div></li>';
?>
[/code]
Copy linkTweet thisAlerts:
@roscorJul 25.2008 — [code=php]if ($_SERVER['PHP_SELF'] == 'index.php'){
echo "<li><div><a href='index.php' id='current'>Home</a></div></li>";
} else {
echo "This is not index";

}
[/code]
Copy linkTweet thisAlerts:
@comptech520authorJul 25.2008 — I am running php on my windows box.

I used a phpinfo.php file to check the variables, on this box.

PHP_SELF is not listed, does anyone know why that may be?
Copy linkTweet thisAlerts:
@bokehJul 26.2008 — does anyone know why that may be?[/QUOTE]Running in CGI mode is one reason.
Copy linkTweet thisAlerts:
@comptech520authorJul 26.2008 — how can I not run in CGI mode?
Copy linkTweet thisAlerts:
@bokehJul 26.2008 — Well first you need to know whether or not you are. If it is a shared server CGI offers much better security characteristics. How not to run in CGI mode? Host on a server that doesn't use this configuration.
Copy linkTweet thisAlerts:
@NogDogJul 26.2008 — Is $_SERVER['SCRIPT_NAME'] set?
Copy linkTweet thisAlerts:
@comptech520authorJul 26.2008 — When I load the phpini.php file, this is what comes up:

SCRIPT_NAME /seg may 08/includes/phpinfo.php
Copy linkTweet thisAlerts:
@NogDogJul 26.2008 — So it looks like that works. If you just want the file name and don't care about the directory stuff, you can filter it through 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 4.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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...