By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,178 Members | 2,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,178 IT Pros & Developers. It's quick & easy.

PHP equivalent?

P: n/a
Don
What's the PHP equivalent for the following?

if(window.location == "http:/site.com/page1.html")
{

}
else
{

}

Thanks,
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Don <no@adr.com> wrote:
What's the PHP equivalent for the following?

if(window.location == "http:/site.com/page1.html")


see:
http://www.php.net/manual/en/reserve...riables.server
and construct the requested URI from the available elements.
Jul 17 '05 #2

P: n/a
Don <no@adr.com> wrote:
What's the PHP equivalent for the following?
if(window.location == "http:/site.com/page1.html") {

} else {

}


$my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if ($my_page == "http:/site.com/page1.html") {

} else {

}

if your page location is : http:/site.com/test/my_first/page1.php
$_SERVER['HTTP_HOST'] return : site.com
$_SERVER['PHP_SELF'] return : /test/my_first/page1.php

--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Jul 17 '05 #3

P: n/a
Don
On 04 Mar 2005 23:16:42 GMT, Daniel Tryba <sp**@tryba.invalid> wrote:
Don <no@adr.com> wrote:
What's the PHP equivalent for the following?

if(window.location == "http:/site.com/page1.html")


see:
http://www.php.net/manual/en/reserve...riables.server
and construct the requested URI from the available elements.

Thanks Daniel.

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #4

P: n/a
Don
On Sat, 5 Mar 2005 00:18:38 +0100, ne***@no-log.org (denisb) wrote:
Don <no@adr.com> wrote:
What's the PHP equivalent for the following?
if(window.location == "http:/site.com/page1.html") {

} else {

}


$my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
if ($my_page == "http:/site.com/page1.html") {

} else {

}

if your page location is : http:/site.com/test/my_first/page1.php
$_SERVER['HTTP_HOST'] return : site.com
$_SERVER['PHP_SELF'] return : /test/my_first/page1.php

Thanks much. That works just great.
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #5

P: n/a
.oO(denisb)
Don <no@adr.com> wrote:
What's the PHP equivalent for the following?
if(window.location == "http:/site.com/page1.html") {

} else {

}


$my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];


$_SERVER['PHP_SELF'] contains the name of the currently running script,
but that doesn't necessarily have to be the requested URI as seen in the
browser's address bar. $_SERVER['REQUEST_URI'] will be more accurate.

Micha
Jul 17 '05 #6

P: n/a
if("{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}" ===
'mysite.com/pageWhatever.php')
{
echo "We're here with pageWhatever.php at mysite.com, reporting live!
Now it's time for a commercial break";
}
else
{
echo "Standby for signal...";
}

Untested, I'm not actually sure if you need a slash between the two
variables. Try it yourself and see what you get.

-jb

"Don" <no@adr.com> wrote in message
news:s2********************************@4ax.com...
What's the PHP equivalent for the following?

if(window.location == "http:/site.com/page1.html")
{

}
else
{

}

Thanks,
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption
=----

Jul 17 '05 #7

P: n/a
Michael Fesser <ne*****@gmx.net> wrote:
.oO(denisb)
Don <no@adr.com> wrote:
What's the PHP equivalent for the following?
if(window.location == "http:/site.com/page1.html") {
} else {
}

$my_page = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$_SERVER['PHP_SELF'] contains the name of the currently running script,
but that doesn't necessarily have to be the requested URI as seen in the
browser's address bar. $_SERVER['REQUEST_URI'] will be more accurate.


yes, it's true.
you are right.

--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Jul 17 '05 #8

P: n/a
Michael Fesser wrote:
$_SERVER['PHP_SELF'] contains the name of the currently running script,
Please, no! Words like 'name' and 'script' only keep the
confusion alive. PHP_SELF is simply the path part of the
current resource's URI. There can be all sorts of rewriting
going on backstage which lead to an address bearing no
resemblance to the name of the script it identifies.
but that doesn't necessarily have to be the requested URI as seen in the
browser's address bar.
True, since an address bar normally shows a URI, the one the
browser parsed to make the request.
$_SERVER['REQUEST_URI'] will be more accurate.


Accuracy doesn't come in to it. You can build the current
URI with REQUEST_URI or PHP_SELF, but they are not the same.

Typically, Request-URI is an absolute-path reference,* that
is, it begins with a single slash. Then, if there is no
query part, REQUEST_URI and PHP_SELF are identical; they are
both the path part of the current resource's URI. If there
is a query part, however, then

PHP_SELF + '?' + QUERY_STRING = REQUEST_URI

The Manual happens to be wrong. It says, without a
semblance of uncertainty, that PHP_SELF is 'the filename of
the currently executing script', which is inexcusable coming
from an authority of its stature.

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

Have a good weekend, Micha!
* But it can also be, among other things, a URI, which
REQUEST_URI should mirror. For example, a Request-line:

GET http://host.invalid/path?query HTTP/1.1

should give a REQUEST_URI of
<http://host.invalid/path?query>.

--
Jock
Jul 17 '05 #9

P: n/a
Don
On Fri, 04 Mar 2005 15:45:23 -0700, Don <no@adr.com> wrote:
What's the PHP equivalent for the following?

if(window.location == "http:/site.com/page1.html")
{

}
else
{

}

Thanks,
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Thanks much for all of your help.
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #10

P: n/a
.oO(John Dunlop)
Michael Fesser wrote:
$_SERVER['PHP_SELF'] contains the name of the currently running script,
Please, no! Words like 'name' and 'script' only keep the
confusion alive. PHP_SELF is simply the path part of the
current resource's URI.


Not necessarily.
True, since an address bar normally shows a URI, the one the
browser parsed to make the request.
And the one the OP asked for.
Typically, Request-URI is an absolute-path reference,* that
is, it begins with a single slash. Then, if there is no
query part, REQUEST_URI and PHP_SELF are identical;
If the browser requested '/', PHP_SELF with contain '/index.php'. I
don't consider that identical.

And it gets even more complicated with server-side URI rewriting. In my
current testing scripts PHP_SELF will always contain the same value,
regardless of the requested URI.
Typically, Request-URI is an absolute-path reference,* that
is, it begins with a single slash.
Yep.
Then, if there is no
query part, REQUEST_URI and PHP_SELF are identical; they are
both the path part of the current resource's URI.
Again: Not necessarily.
The Manual happens to be wrong. It says, without a
semblance of uncertainty, that PHP_SELF is 'the filename of
the currently executing script', which is inexcusable coming
from an authority of its stature.


But that's exactly what PHP_SELF is.

Micha
Jul 17 '05 #11

P: n/a
Michael Fesser wrote:
.oO(John Dunlop)
Please, no! Words like 'name' and 'script' only keep the
confusion alive. PHP_SELF is simply the path part of the
current resource's URI.


Not necessarily.


Aha! I was wrong. Thank you for putting me right. May I
repay you now?
Typically, Request-URI is an absolute-path reference,* that
is, it begins with a single slash. Then, if there is no
query part, REQUEST_URI and PHP_SELF are identical;


If the browser requested '/', PHP_SELF with contain '/index.php'.


Mine shows '/index', without '.php', even though '.php' is
part of the filename. The filename is 'index.php', not
'/index' or 'index'. So in this case PHP_SELF isn't the
filename. In fact, filenames here cannot contain slashes,
and backslashes, not slashes, show directory structure, so
PHP_SELF can't be a filesystem path either.
I don't consider that identical.
Nor do I. You're right.
And it gets even more complicated with server-side URI rewriting. In my
current testing scripts PHP_SELF will always contain the same value,
regardless of the requested URI.


Fascinating. Here, if I request <http://127.0.0.1/php/foo>,
PHP_SELF is '/php/foo' -- not the filename of the script.
If I request <http://127.0.0.1/php/foo.php>, PHP_SELF is
'/php/foo.php' -- again, not the filename. Both URIs
identify the same resource, by the way.
The Manual happens to be wrong. It says, without a
semblance of uncertainty, that PHP_SELF is 'the filename of
the currently executing script', which is inexcusable coming
from an authority of its stature.


But that's exactly what PHP_SELF is.


I've shown that to be untrue, haven't I?

--
Jock
Jul 17 '05 #12

P: n/a
.oO(John Dunlop)
Fascinating. Here, if I request <http://127.0.0.1/php/foo>,
PHP_SELF is '/php/foo' -- not the filename of the script.
If I request <http://127.0.0.1/php/foo.php>, PHP_SELF is
'/php/foo.php' [...]


This happens with content negotiation (MultiViews) enabled on the
server.
>The Manual happens to be wrong. It says, without a
>semblance of uncertainty, that PHP_SELF is 'the filename of
>the currently executing script', which is inexcusable coming
>from an authority of its stature.


But that's exactly what PHP_SELF is.


I've shown that to be untrue, haven't I?


OK, it's "the path and filename of the currently executing script".
At least in most cases ... ;)

Micha
Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.