473,383 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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

osward
38
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?newlang=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 3278
pbmods
5,821 Expert 4TB
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
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 Expert 4TB
Heya, osward.

You can get the relative URI of the current page by using $_SERVER['SCRIPT_NAME'].
Oct 22 '07 #4
osward
38
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?name=Feedback.

Anything I am missing from your reply?
Oct 22 '07 #5
pbmods
5,821 Expert 4TB
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 htmlspecialchars() first.
Oct 22 '07 #6
osward
38
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=English 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 Expert 4TB
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
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($_SERVER['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=english 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("php", "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 Expert 4TB
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_query() 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
osward
38
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_query() 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.
Hi, pbmod,

I finally got it done by appending &newlang=english to your pervious code posted
Expand|Select|Wrap|Line Numbers
  1. $_linkPrefix = $_SERVER['SCRIPT_NAME'] . '?' . http_build_query($_GET);
The link to the English interface now read $_linkPrefix&newlang=english

However, I still don't understand and haven't use the first part of the code you posted
Expand|Select|Wrap|Line Numbers
  1. <base href="http://<?php echo $_SERVER['HTTP_HOST']; ?>" />
What do you mean by
If you have this in the head of your HTML:
I don't have any HTML documents here through the phpnuke. Am I missing you by a beat?
Oct 26 '07 #11
pbmods
5,821 Expert 4TB
Heya, Osward.

The base tag allows you to specify sort of the 'prefix' for every link on your page.

I'm not too familiar with phpnuke specifically, but like any CMS, there should be a header file that you can edit that contains the HTML that goes at the top of every page.

Adding a base tag is not strictly necessary, but it makes it a lot easier to, for example, migrate your site to a new server or to make it easier to keep your link behavior consistent.

For more information, check out this article.
Oct 26 '07 #12

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

Similar topics

3
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
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
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...
1
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...
0
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...
4
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...
4
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:...
1
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...
5
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.