Page 1 of 1

Need help with Current URL

Posted: Mon Mar 22, 2010 6:30 pm
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.

Re: Need help with Current URL

Posted: Mon Mar 22, 2010 7:18 pm
by Christopher
User strpos() to check if there is a ? in the URL. If there is use &; if not use ?.

Re: Need help with Current URL

Posted: Mon Mar 22, 2010 7:48 pm
by Mr. Rod
Hey, could you elaborate how to make use of this function, please? I have never used it before.

Re: Need help with Current URL

Posted: Mon Mar 22, 2010 7:58 pm
by Christopher
There many great examples in the manual:

http://us2.php.net/manual/en/function.strpos.php

Re: Need help with Current URL

Posted: Mon Mar 22, 2010 10:03 pm
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! :)

Re: Need help with Current URL

Posted: Tue Mar 23, 2010 3:06 am
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 '?'.

Re: Need help with Current URL

Posted: Mon Sep 24, 2012 4:27 am
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.
\