473,386 Members | 1,715 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,386 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 2816
"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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.