Need help with Current URL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Mr. Rod
Forum Newbie
Posts: 3
Joined: Mon Mar 22, 2010 6:04 pm
Location: Santiago, Chile

Need help with Current URL

Post by Mr. Rod »

Hello, I'm Rod, new here. I need help with the current time function (is that how is it called?). I'm using it in phpBB and works great, BUT there's a problem, which I'll explain later...

This is the code I'm using:

Code: Select all

'CURRENT_URL'                   => generate_board_url() . '/' . $user->page['page'],
I'm using it to place a link in the header of my forum. The header is present in all forum pages and the link I have is to change the language on the fly (for example: http://www.example.com/forum/index.php?nlang=fr) so if I go to the 'memberlist.php' page the link will appear like this in the navigation bar: http://www.example.com/forum/memberlist.php?nlang=fr

But here comes the problem: if I go to a thread the link won't work because there's already the ? and for "nlang=fr" to work it needs an & instead (http://www.example.com/forum/viewtopic. ... ]?nlang=fr[/b]). How can I make it so that the question mark is replaced with an ampersand ONLY when this situation happens (viewtopic.php page or any other that already has a variable).

Thanks.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help with Current URL

Post by Christopher »

User strpos() to check if there is a ? in the URL. If there is use &; if not use ?.
(#10850)
User avatar
Mr. Rod
Forum Newbie
Posts: 3
Joined: Mon Mar 22, 2010 6:04 pm
Location: Santiago, Chile

Re: Need help with Current URL

Post by Mr. Rod »

Hey, could you elaborate how to make use of this function, please? I have never used it before.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help with Current URL

Post by Christopher »

There many great examples in the manual:

http://us2.php.net/manual/en/function.strpos.php
(#10850)
User avatar
Mr. Rod
Forum Newbie
Posts: 3
Joined: Mon Mar 22, 2010 6:04 pm
Location: Santiago, Chile

Re: Need help with Current URL

Post by Mr. Rod »

Thank you for the link, but I read through it all and I'm not sure how to integrate that into my code. I'm not an expert with php though I've been working with it since last year, if you or someone else could explain in detail would be fab! :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help with Current URL

Post by Christopher »

strpos() returns false if what you are searching for is not found. The examples show how to check. So pass the URL string as the "haystack" and '?' as the "needle" to see if there are parameters already. The it is just a matter of concatenating with '&' or '?'.
(#10850)
joeyey
Forum Newbie
Posts: 1
Joined: Mon Sep 24, 2012 3:57 am

Re: Need help with Current URL

Post by joeyey »

@Christopher, you are not helping at all. You are using ambiguous terms when this person states he's a new user.
Anyways, @Mr. Rod, take a look at https://www.phpbb.com/community/viewtop ... #p12445445
It may help.
\
Post Reply