Jump to content

Recommended Posts

Hello all,

 

Sorry to join and ask a question immediately. I have just been asked to help out adding some new languages to a website. There is some php working to help the redirects on the pages. I have attached a snippet below and the php file. Currently the only pages it allows you to change to are italian (from the English pages)

 

I am sure this is really simple but I am having trouble getting my head around it and adding two new language directories. I could replace everything with standard HTML links but the php is obviously a better way to do it and it is about time I learnt it.

 

Any help or pointers as to what is happening here would be massively appreciated.

 

Thanks

 

 

Graham

 

 

<a href="transporter.php?l=it/index.html" id="view_it"><img src="images/flag_it.jpg" alt="Site in Italian" title="Site in Italian" /></a>

 

or

 

<a href="../transporter.php?l=index.html" id="view_uk"><img src="../images/flag_uk.jpg" alt="Site in English" title="Site in English" /></a>

 

transporter.php

I have added the php code below as I noticed no one had looked at the file. I just wondered if it was better to post it in case that was the way I should have posted it originally.

 

Any help would be really appreciated, again sorry for jumping straight in with a question. I have ordered O'Reilly PHP so with a little luck I will be able to answer this myself in a few weeks.

 

Thanks

 

Graham

 

<?php

 

/*

Because IE doesn't support HTTP_REFERER we have to use ugly GET strings

 

$ref = $_SERVER['HTTP_REFERER'];

$ref_parts = explode('/', $ref);

$page = $ref_parts[count($ref_parts) - 1];

$dir = $ref_parts[count($ref_parts) - 2];

 

 

if($dir == 'it'){

header("location:" . $page);

exit();

} else{

header("location:it/" . $page);

exit();

}

 

*/

 

 

if(isset($_GET['l']) && !empty($_GET['l'])){

header("location:" . trim($_GET['l']));

exit();

}

 

 

 

 

?>

I'm using sessions for one my project - http://www.stdimitar.org

 

It works very well.

 

 

bulgarian.php

 



<?php

session_start();
$_SESSION['lang'] = null;

header('Location:stdimitar/');

exit;

?>

 

english.php

 


<?php

session_start();

$_SESSION['lang'] = 'en';

header('Location:stdimitar/');

exit;

?>

 

index.php (controller)

 


$lang = ($_SESSION['lang'] == 'en') ? 'en' : null;

 

That's all and very simple :)

Edited by jazzman1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.