473,796 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to capture client browser address bar when click to an icon

osward
38 New Member
Hello everyone,

My site needs to support 3 different languages that runs under phpnuke 8.0, phpnuke provides language interface select function that allows switching from different interface, namely using different language files.

Every time when user is inside a module, when they click the language interface selection, it send the user back to the index page. I had found out a typical browser address to switch from language would read : http://mysite.com/ndex.php?newlan g=english

I had tried manually to alter the newlang=xxxx and it works and so as inside any other modules that won't send me back to index page. Therefore I could added different links in the module to let user switching language interface without leaving the module.

Here is what I want to achieve, I want to write a small function when user click a flag or link, the function capture the client's browser address and append the newlang=xxx and send it to the server to request the proper language. In this case I don't have to worry about adding links to every module manually.

What I really need is the code or php function to capture the user's browser address bar

Thanks in advance

Please help
Oct 20 '07 #1
11 3318
pbmods
5,821 Recognized Expert Expert
Heya, osward.

Simply set a session variable, and then use that session variable when fetching content.

For example, create a page called setLang.php (or whatever you'd like to call it):
Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
  3. switch( $_GET['lang'] )
  4. {
  5.     case 'en_us':
  6.     case 'en':
  7.     case 'lojban':
  8.     .
  9.     .
  10.     .
  11.         $_SESSION['lang'] = $_GET['lang'];
  12.     break;
  13. }
  14.  
  15. header('Location: ' . $_SERVER['HTTP_REFERER']);
  16.  
Then, put the link on the home page:
Expand|Select|Wrap|Line Numbers
  1. <a href="setLang.php?lang=en_us"><img src="picture_of_us_flag.png" /></a>
  2. <a href="setLang.php?lang=en"><img src="picture_of_uk_flag.png" /></a>
  3. <a href="setLang.php?lang=lojban"><img src="picture_of_dr_james_browns_head.png" /></a>
  4.  
And so on.

Then, when you are fetching content, simply reference $_SESSION['lang'] to determine which language to use:

Expand|Select|Wrap|Line Numbers
  1. session_start();
  2.  
  3. if( empty($_SESSION['lang']) )
  4. {
  5.     $_SESSION['lang'] = 'en_us';
  6. }
  7.  
  8. $__lang =& $_SESSION['lang'];
  9.  
Oct 20 '07 #2
osward
38 New Member
Thanks for the tips and code example. I think you had pointed me to the right direction. I know phpnuke use cookie and maybe I can make use of it.

However, if I have to make use of the section cookie, I got to know the present url of the user not their language interface they are using. What I want to do is to create an icon with link like this
e.g.
Expand|Select|Wrap|Line Numbers
  1. <a href=\"/$url&newlang=english\"><img src=\"images/Eng.gif\" border=\"0\" width=\"12\" height=\"14\" alt=\""._ENG."\" title=\""._ENG."\" hspace=\"3\" vspace=\"3\"></a>
where the $url is
Expand|Select|Wrap|Line Numbers
  1. <a href=\"/modules.php?newlang=english&name=event\"><img src=\"images/Eng.gif\" border=\"0\" width=\"12\" height=\"14\" alt=\""._ENG."\" title=\""._ENG."\" hspace=\"3\" vspace=\"3\"></a> 
You might want to have a look at my test site at http://cf-home.cn, There are 3 flags in the middle of the header section, which is doing exactly what you suggested me to do. (Note the address bar of your browser) Please click the module feedback and you will find 3 language interface icons there that I manually added the link http://www.cf-home.cn/modules.php?ne...&name=Feedback for english

What I really want to do is when user click the Zh-tw icon for example, he sends the present url plus append &newlang=zh-tw to the server

Any idea of how to achieve this?
Oct 22 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, osward.

You can get the relative URI of the current page by using $_SERVER['SCRIPT_NAME'].
Oct 22 '07 #4
osward
38 New Member
Heya, osward.

You can get the relative URI of the current page by using $_SERVER['SCRIPT_NAME'].
The $_SERVER['SCRIPT_NAME'] only returns http://www.cf-home.cn/modules.php and the address bar reads http://www.cf-home.cn/modules.php?nam e=Feedback.

Anything I am missing from your reply?
Oct 22 '07 #5
pbmods
5,821 Recognized Expert Expert
Heya, osward.

If you want to include the variables, use $_SERVER['PHP_SELF'];

Note that to prevent XSS when outputting $_SERVER['PHP_SELF'] in an HTML document, you'll want to run it through htmlspecialchar s() first.
Oct 22 '07 #6
osward
38 New Member
I found $url = $_SERVER['FULL_URL']; works best for me, the interesting thing is hat when I made the first a switch eg, from English -> Zh-cn-utf8 (Simplify Chinese), it works fine and the address bar is exactly as I did it manually, however if I click English again, the &newlang=Englis h just append to the last url but still it works

I would like to convert the first capture url as string and use it in the link, how am I converting the first capture url (ie when user first visit the page) into a string? Right now the $_SERVER('FULL_ URL'] keep returing url everytime the link is hit.
Oct 23 '07 #7
pbmods
5,821 Recognized Expert Expert
Heya, osward.

You'll probably want to build it manually.

If you have this in the head of your HTML:
Expand|Select|Wrap|Line Numbers
  1. <base href="http://<?php echo $_SERVER['HTTP_HOST']; ?>" />
  2.  
Then you can make your link prefix as follows:
Expand|Select|Wrap|Line Numbers
  1. $_linkPrefix = $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($_GET);
  2.  
You may also find add_rewrite_var () to be useful.
Oct 23 '07 #8
osward
38 New Member
Heya, osward.

You'll probably want to build it manually.

If you have this in the head of your HTML:
Expand|Select|Wrap|Line Numbers
  1. <base href="http://<?php echo $_SERVER['HTTP_HOST']; ?>" />
  2.  
Then you can make your link prefix as follows:
Expand|Select|Wrap|Line Numbers
  1. $_linkPrefix = $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($_GET);
  2.  
You may also find add_rewrite_var () to be useful.
Hi pbmods,

Because I am not quite sure of what you menat in the reply

I found a script as follows:
[PHP]$_SERVER['FULL_URL'] = 'http';
$script_name = '';
if(isset($_SERV ER['REQUEST_URI'])) {
$script_name = $_SERVER['REQUEST_URI'];
} else {
$script_name = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']>' ') {
$script_name .= '?'.$_SERVER['QUERY_STRING'];
}
}
[/PHP]

I am using the $script_name and append the language selection &newlang=englis h as the link. I put the link in the index page and I could change language interface anywhere except the index page. It returns a 404 error and the address bar reads http://mydomain.index. php&newlang-english.
In the above } else {
I am sure it meant the same as you instructed me to do, add a '?' to the $_SERVER['PHP_SELF'] but still couldn't add the '?' at the index page

Am I missing anywhere on my part? I also try the str_replace like
[PHP]} else {
$script_name = $_SERVER['PHP_SELF'];
if($_SERVER['QUERY_STRING']>' ') {
$script_name .= str_replace("ph p", "php?", $_SERVER['PHP_SELF']).$_SERVER['QUERY_STRING'];
}[/PHP]
and yet could not at the '?' at the index page. Please help

Thanks in advance
Oct 26 '07 #9
pbmods
5,821 Recognized Expert Expert
Heya, osward.

It's never getting to the else in your code because $_SERVER['REQUEST_URI'] exists.

If you're trying to replace the value in each URL, consider modifying $_GET and using http_build_quer y() as I suggested above. Since each array key can only have one corresponding value, this will ensure that each _GET variable is only output once in the query string, even if its value has changed.
Oct 26 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

3
2737
by: Marcia Gulesian | last post by:
How can I capture the event when I click (focus) with the cursor anywhere in the page (that is, on a component or elsewhere). This event would occur in an I.E 5.5 or later browser.
88
12567
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
4
5528
by: feng | last post by:
Hi, In our asp.net app, we need to capture the event when user close the browser window by clicking on the "x" button. But it doesn't seem to be as easy as it sound. Can someone show me how to do this? Thanks
1
2544
by: Hose B | last post by:
HI all, I have a legacy app in which users can pick various page templates. There is a template preview dialog. It works such that they view a list of icons in an asp page that represent each available page template. Each template is a straight-forward HTML file (not an asp or aspx) When a user clicks on an icon, the text comprising the selected template's HTML file is read into a string variable that is then injected into a <DIV> tag...
0
1683
by: Brad White | last post by:
Overview: I have a custom web app that has an 'Inbox' that refreshes every 30 seconds. One user uses Outlook to host the web page. Using IE, the refresh works fine. If the user is working in another window, the web page quietly refreshes in the background. Hosted in Outlook, the refresh causes Outlook to come to the front on every refresh. Or in XP, causes the toolbar icon to flash.
4
4814
by: Bill Manring | last post by:
I need to capture the event when the user closes the browser in my application. I have some code in the session_End event, which works fine when the session times out, but I need to end the session immediately when the user closes the browser. Does anyone know a way of doing this? -- Thanks,
4
2111
by: Ray Stevens | last post by:
Is it possible to place a company icon (logo) in the browser address field so that if a user copies it as a shortcut to his desktop the icon will be there. For example, like this: http://espn.go.com/
1
2800
by: Feng | last post by:
Hi, Need help on the following issue. We need to clean up some session specific backend resource when a user ends his session. We have a "Logoff" button on the pages that handles that. But the problem is that sometimes the user still closing their browser window by clicking on the "x" button of the window. This is quite a problem for us because it will leave unreleased resource on the server for an unpredictable period of time,...
5
3164
by: vasilis | last post by:
I have a list box in a site with which I capture a selected value with the onChange event using the capture_value() function (code listed below). This function passes 2 arguments, i.e., 'str' which is the selected list box value and 'passed_url' which is a passed url for running a php script (which contains some url query parameters, e.g. 'somescript.php?var1=value1&var2=value2&var3=value3'). The capture_value() function actually sends a...
0
9533
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
10461
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10239
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
10190
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
9057
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6796
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
5579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
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.