473,221 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

problem with PHP_SELF

here's situation:

i have installed php 5 and apache 2.0.

i can call my page with:

localhost\\subdir\page.php

inside my page i use links like this:

<a href="<?php $_SERVER['PHP_SELF']?>?style=bold">

to refresh page with new value to variable "style". Problem is that when i
load my page and try to click that link it directs me to:

http://subdir/page.php?style=bold

- "localhost" is missing, and therefore browser reports that page is
unavailable. If i set my link to

<a href="page.php?style=bold">

it's ok, but i'd like to use php_self.

is that maybe problem with apache configuration?

thanks!
Jul 17 '05 #1
5 2809
"Maja" <dr*************@zg.t-com.hr> wrote in message
news:cs**********@ls219.htnet.hr...
here's situation:

i have installed php 5 and apache 2.0.

i can call my page with:

localhost\\subdir\page.php

inside my page i use links like this:

<a href="<?php $_SERVER['PHP_SELF']?>?style=bold">

to refresh page with new value to variable "style". Problem is that when i
load my page and try to click that link it directs me to:

http://subdir/page.php?style=bold

- "localhost" is missing, and therefore browser reports that page is
unavailable. If i set my link to

<a href="page.php?style=bold">

it's ok, but i'd like to use php_self.

is that maybe problem with apache configuration?

thanks!


The variable $_SERVER['php_self'] doesn't contain the "http://" prefix, and
if you were to prepend "http://" to $_SERVER['php_self'], you would get the
behavior you describe above. In the above instance, $_SERVER['php_self']
would be set to "subdir/page.php". So if you use it like this:

<a href="<?php echo $_SERVER['PHP_SELF']?>?style=bold">

....then you shouldn't be having any problem. Since what you wrote above as
your code won't produce _any_ output (since you didn't echo out the
variable), I assume that you retyped rather than copy/pasted and thus
introduced another error. Retyping your code on the newsgroup is very bad
practice and should be avoided, at it usually just adds to the confusion of
troubleshooting errors in your code.

The documentation for $_SESSION and all other reserved variables can be
found at [http://www.php.net/reserved.variables]. I would suggest reading
it, as it is rather helpful for questions like this.

Hope this helps.

-Noah
Jul 17 '05 #2
*** Maja escribió/wrote (Fri, 14 Jan 2005 20:34:28 +0100):
i can call my page with:

localhost\\subdir\page.php
I can't figure out what you mean with this :-?

<a href="<?php $_SERVER['PHP_SELF']?>?style=bold">
There's no "echo", I suppose it's just a typo.
http://subdir/page.php?style=bold

- "localhost" is missing, and therefore browser reports that page is
unavailable. If i set my link to


From PHP manual <http://es2.php.net/manual/en/reserved.variables.php>:

'PHP_SELF'

The filename of the currently executing script, relative to the document
root. For instance, $_SERVER['PHP_SELF'] in a script at the address
http://example.com/test.php/foo.bar would be /test.php/foo.bar. The
__FILE__ constant contains the full path and filename of the current (i.e.
included) file.

If PHP is running as a command-line processor, this variable is not
available.
Check the rest of the page. Also, check the phpinfo() function. There isn't
a function that returns the current URL (which is actually never sent to
the server by the client) but you can build yours adding pieces: protocol,
host name, port, path...

In any case, you don't need the full path for internal links. Just remove
the "http://" part I'm pretty sure you add.

--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #3
i'at work so it's different name...
thanks for replay. i did some reading and came to this "new" problem.

(sorry i mistyped code before, (i forgot to put "echo"))

so... i'm using
<a href="<?php echo $_SERVER['PHP_SELF']?>?style=bold">
as links to reload page. and it works if my page is at root:
( "C:\program files\apache group\apache2\htdocs\page.php")
bit if my page is in some subdir it doesn't
( "C:\program files\apache group\apache2\htdocs\subdir\page.php")
can i still use 'PHP_SELF' to get only name "page.php" not URL relative to
root?

sorry for my lousy english.


Jul 17 '05 #4
"ToMeK" <t_***@hotmail.com> wrote in message
news:cs**********@ls219.htnet.hr...
i'at work so it's different name...
thanks for replay. i did some reading and came to this "new" problem.

(sorry i mistyped code before, (i forgot to put "echo"))

so... i'm using
<a href="<?php echo $_SERVER['PHP_SELF']?>?style=bold">
as links to reload page. and it works if my page is at root:
( "C:\program files\apache group\apache2\htdocs\page.php")
bit if my page is in some subdir it doesn't
( "C:\program files\apache group\apache2\htdocs\subdir\page.php")
can i still use 'PHP_SELF' to get only name "page.php" not URL relative to
root?


it looks like this works:

substr(strrchr($_SERVER['PHP_SELF'],'/'),1)

thanks anyway.
Jul 17 '05 #5
Maja wrote:
inside my page i use links like this:

<a href="<?php $_SERVER['PHP_SELF']?>?style=bold">


That is not risk-free. PHP_SELF, as we know, is the path
component of the current resource's URI. Given a base URI
of <http://example.invalid/foo/> and a mistyped current URI
of <http://example.invalid//foo/bar> (note the two slashes
before 'foo'), PHP_SELF is <//foo/bar>. That's a network-
path reference, which browsers should resolve to the
absolute URI <http://foo/bar>.

If you do use PHP_SELF as the value of an href, I suggest
you check it first, as you should with all input. Your
workaround -- only using what comes after the last slash in
PHP_SELF -- avoids the issue I mentioned.

And your English, for which you needn't apologise, is
perfectly understandable.

HAGW!

--
Jock
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jojocrazy | last post by:
I'm definately not a regexp wiz.... need some suggestions here: grab PHP_SELF, strip the end filename off and the 2 directories preceeding it... This is what I've come up with so far, except...
12
by: Don | last post by:
What's the PHP equivalent for the following? if(window.location == "http:/site.com/page1.html") { } else { }
11
by: ste | last post by:
Hi there, Further to my recent posts where I've received excellent help from Rik and Jerry, I've ended up with an image gallery on my website that displays images in a table, 3 images per row. ...
2
by: dalsoth | last post by:
Hi Guys I have created a website and to makes things easier i decided to use dreamweaver to do the secure login section and access levels for the pages. When testing locally on wamp my website...
2
by: mpar612 | last post by:
Hi everyone, The code posted below retrieves all of the rows from a database table. It paginates them by limiting to 20 results per page. It is supposed to print 5 rows of results with 4...
5
by: Tom | last post by:
I have a function that restricts access to a page to logged in users. When a user who isn't logged in goes to the page, it will dynamically generate a login form. I'm trying to use it in...
6
by: rynato | last post by:
whatever code I put inside this IF statement: if ($_SERVER == 'POST') I get a parse error. Even 'print "something goes here"' doesn't work. Any ideas?
18
by: zoilus | last post by:
Can not determine how "<?=PHP_SELF?>" is supposed to work. The below is the line of code. <!-- <form name="search" method="post" action="<?=$PHP_SELF?>"--> When the above statement is run the...
2
coolv
by: coolv | last post by:
Hello I have problem in my page that the dropdown box is not displaying data according to selection of first dropdown.Please help me. Below is my code. thanks.............. <?php ...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.