Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

little php script to change the language on the page

Featured Replies

Hi,

 

I've got 3 versions of my website in 3 languages. I want 3 little flags on the page. When someone clicks to change the language I want to get the same page but in the other language.

 

Is there a way to get the page name then find that page name in a different folder in the directory with php.

 

E.g.

 

3 websites, 3 folders, same page names, 3 different languages

 

Pixel English

Pixel Georgian

Pixel Russian

 

Thanks

 

Andy

Hi, I have just written this script for you, hope this helps.

<?php
//sees if a link has been clicked on and the variable set
if (isset($_REQUEST['language'])) {
//finds out which language has been chosen
if ($_REQUEST['language'] == 'l1') {
	$filename = 'languages/language_1/index.php';
} elseif ($_REQUEST['language'] == 'l2') {
	$filename = 'languages/language_2/index.php';
} if ($_REQUEST['language'] == 'l3') {
	$filename = 'languages/language_3/index.php';
} 
//if a link has not been clicked on and a variable been set then the $filename is set to the default filename
} else {
$filename = 'languages/default.php';
}
?>
<html>
<body>
	<!--the below will remain the same over all the pages, only the include will change-->
	<a href="<?php echo $_SERVER['PHP_SELF']; ?>?language=l1">Language 1</a> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?language=l2">Language 2</a> <a href="<?php echo $_SERVER['PHP_SELF']; ?>?language=l3">Language 3</a><br />
	<!--this will pull the selected content from the selected filename-->
	<?php include($filename); ?>
</body>
</html>

 

Mike

www.everydayprint.co.uk

  • Author

Wow! Thanks very much. I appreciate it.. I will use it today. I will post a link to you once the site it up.

 

Thanks

Andy

  • Author

Hi, I need some helping using this. My page has an included header and footer.

 

Where do I put the script?

 

Thanks

Andy

  • Author

I decided to do this instead -

 

<?php $file = basename($_SERVER['SCRIPT_NAME']); ?>
<a href="<?php echo '../pixel english/'.$file ?>">english</a><br />
<a href="<?php echo '../pixel georgian/'.$file ?>">georgian</a><br />
<a href="<?php echo '../pixel russian/'.$file ?>">russian</a><br />

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.