Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get current url

Status
Not open for further replies.

glimbeek

Programmer
Nov 30, 2009
83
NL
Hi,

This may sound like a silly request... but here goes. I want to get the current URL from the address bar. The right side of the URL to be more precise. This is done by $_SERVER['REQUEST_URI']. However I need to "get" the url in a PHP file, but the URL that I get when I get it in that php file is wrong. So I want to get the url in the php file using a different php file so I can get the correct url.

I'm trying to do this in a Joomla website that uses JoomSEF.
The URL I'm trying to get is a search engine friendly URL, however I'm getting something like: /index.php?option=com_jcomments&tmpl=component. So I want to get the current url from a different PHP file, a PHP file that does has the correct SEF URL.

Does anyone have any idea if and how this can be done?
 
I don't follow. $_SERVER['REQUEST_URI'] returns the URL that as used to access the page, including all query sting parameters.

The value is not wrong, so I don't know what you mean by getting a correct SEF URL.

If you are including your second file into website, then you already know its URL, not sure why you want to get it.

If what you want is just the "index.php" without the parameters, you can either use SCRIPT_FILENAME, or use string functions to extract the value.

If I'm totally off on this, perhaps you can explain more what you are trying to get.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi Vacunita,

All valid questions.
I'll know it's a weird request and I might be taking a wrong approach to fixing my "problem". I'll try to explain what I want to achieve and in what situation this is.

On my Joomla! website I'm using an extension JComments. This extension changes the button texts and error message according to the language of Joomla!

I set this language myself by using a GeoIP database the first time someone visits my website. However I don't want to JComments to be displayed in French for someone from French when they are looking at the Dutch part of my website.

So there are a few files JComments loads to display what it needs to display. There is one file with classes from which a class can be called from any location. So I created an extra class with the right function and I call the class and the function on the "right" location in other files so they language is changed according to where the visitor is on the website. This language change is done by looking at the SEF url. For instance: is for French and is for Dutch. This works perfectly for everything except one bit of the JComments extension. One file (the file that handles the error messages and the captcha image) doesn't use a SEF url, but for instance something like index.php?component=com_jcomment&action=captcha&id=123456. So I need to a way to check the URL from a different file that is called on the same page that does "use/see" the right SEF URL.

Hopefully this makes sense.
 
I don't see how that would be possible. There's no way to know what file should be opened to get the correct language from. Perhaps you can change the link a bit to include a language parameter for you to use.

index.php?component=com_jcomment&action=captcha&id=123456&[red]lang=fr[/red] or whatever.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
it might be possible. it's illogical though.

the vague solution i put forward is this:

1. edit the php.ini to add an auto_prepend script
2. in the auto_prepend script grab the script name relative to the document root and prepend the protocol and server name etc.
3. assign that to a global variable.
 
Cheers for the reply's, yeah it is illogical.

I do know however which file does "get" the right SEF URL and appending something to it's URL isn't possible + I'd still need to know what to append so I can for instance, append the language tag code so I can use that.

 
Getting the langauge will not be straightforward. The browser sends a header (Accept-Language: en-gb in my IE7) which may or may not be helpfull.
 
Hi ingresman,

That's the whole point. I don't want to get the language by browser language but by where the visitor is on the website AKA, the URL the visitor is on.
 
how does the user select the language? and thereafter how does he change it?

I am thinking that session persistence might be the answer.
 
The user visits the website.
We look at the browser language and for UK/US difference we look at the IP (they both get en-GB) but we look at it to serve location based banners/links.

When the user visits the website we set the Joomla language accordingly. The user can't really change it's language they can however "visit" a different language part of the website.
 
then one assumes that joomla will know what page etc that it is showing. so joomla probably exposes a method somewhere of obtaining this information. joomla specific stuff is beyond my knowledge - I can't stand the framework.
 
Cheers for your help so far jpadie.

Maybe someone else can point me in the right direction?
 
Solved it.. sort off...

I made a nasty hack to solve this. Get the URL in a file where the URL is correct, write it to a text file and read that output in the location where I need it. It seems to be working, but it's an ugly hack.

Cheers for the provided help.
If anyone has a better suggestion, please let me know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top