473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with PHP_SELF

here's situation:

i have installed php 5 and apache 2.0.

i can call my page with:

localhost\\subd ir\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 2835
"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\\subd ir\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\\subd ir\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.variab les.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\h tdocs\page.php" )
bit if my page is in some subdir it doesn't
( "C:\program files\apache group\apache2\h tdocs\subdir\pa ge.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\h tdocs\page.php" )
bit if my page is in some subdir it doesn't
( "C:\program files\apache group\apache2\h tdocs\subdir\pa ge.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
1643
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 I'd like to replace the ..html for any extension and I've tried it but doesn't work... and I've also tried parsing backing a second directory but no luck, maybe you have an alternative solution:
12
4465
by: Don | last post by:
What's the PHP equivalent for the following? if(window.location == "http:/site.com/page1.html") { } else { }
11
2785
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. This works great and opens all images in the database when I open the url mywebsite/gallery.php, or I can choose certain images (by category) by going to url's like mywebsite/gallery.php?category=landscape Although the above worked perfectly...
2
4287
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 works perfectly. On internet though, the pages that don't require a user to log in i can search my job database perfectly and see the results so the connection to the database is fine. When i try to log in though i just get a user is unauthorised...
2
1273
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 results per row. Everything works fine, except the first row returned from the database is never printed. It doesn't matter how the results are ordered or how many rows are in the db, the first row that is supposed to be printed is not printed. Does...
5
2845
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 conjunction with the free shared SSL certificate offered by my host. To use SSL, you would change a URL like this http://mydomain.com/page.php
6
17529
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
10760
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 following is the result. You don't have permission to access /dev/forms/forms_testing/< on this server.
2
2218
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 session_start(); if (!isset($_SESSION)) {
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.