Jump to content

Multi Language Session Switch


greenbman

Recommended Posts

ok so on the following code the NavMenuEng.php appears correctly however the NavMenuSpan.php does not appear however in the source code the NavMenuSpan.php is there just like the Eng one. Here is the code:

 

 

<?php session_start();
$_SESSION['lang'] = 0;
if(isset($_GET['lang'])){
if($_GET['lang']=='eng'){
$_SESSION['lang'] = 0;

}else if($_GET['lang']=='span'){
$_SESSION['lang'] = 1;
}
}
?>
<center><a href="index.php?lang=eng"><img title="English" src="images/english.png"></a>        <a href="index.php?lang=span"><img title="Spanish" src="images/spanish.png"></a></center>
<?php

switch($_SESSION['lang']){

case 0:
include("NavMenuEng.php");
break;
case 1:
include("NavMenuSpan.php");
break;
default:
include("NavMenuEng.php");
break;
}
  ?>

 

And this is the NavMenuEng.php:

 

<div id="menu">
   <ul>
 <li class="active"><a href="index.php" accesskey="1" title="Home">Homepage</a></li>
 <li><a href="skills.php" accesskey="2" title="Skills">Skills</a></li>
 <li><a href="reffs.php" accesskey="3" title="References">References</a></li>
 <li><a href="about_me.php" accesskey="4" title="About Me!">About Me</a></li>
 <li><a href="contact_me.php" accesskey="5" title="Contact Me!">Contact Me</a></li>
   </ul>
  </div>

 

And this is the NavMenuSpan.php:

 

<div id="menu">
   <ul>
 <li class="active"><a href="index.php" accesskey="1" title="Home">Página Principal</a></li>
 <li><a href="skills.php" accesskey="2" title="Skills">Habilidades</a></li>
 <li><a href="reffs.php" accesskey="3" title="References">Referencias</a></li>
 <li><a href="about_me.php" accesskey="4" title="About Me!">Acerca de mí</a></li>
 <li><a href="contact_me.php" accesskey="5" title="Contact Me!">Contacto</a></li>
   </ul>
  </div>

 

Hopefully someone can help with this.

 

Thank you all for the Views.

gbman

Link to comment
Share on other sites

On a side note, you have a lot of unnecessary code in there.

 

You set $_SESSION['lang'] to a default of 0 to start. Then you have a if() condition that will set it to 0 if a condition is met. Why, you already set it to 0 to begin with right? Then you put a default case in your switch statement and also duplicate the code for the 1 condition. Anyway, that 0 or 1 values are a waste. It makes it more difficult to read in your code and is not intuitive.

 

As to why you are not seeing the spanish content, my guess would be that you aren't actually sending 'span' on the query string as you think you are. Try echoing out $_GET['lang'] to the page. This code will work much better and I've included a couple debugging lines

 

<?php

session_start();

if(isset($_GET['lang']))
{
$_SESSION['lang'] = strtolower(trim($_GET['lang']));
}

?>
<center><a href="index.php?lang=eng"><img title="English" src="images/english.png"></a>        <a href="index.php?lang=span"><img title="Spanish" src="images/spanish.png"></a></center>
<?php

//Debugging lines (Uncomment to debug)
//echo "\$_GET['lang']: {$_GET['lang']}<br>";
//echo "\$_SESSION['lang']: {$_SESSION['lang']}<br>";

switch($_SESSION['lang'])
{
case 'span':
 include("NavMenuSpan.php");
 break;
case 'eng':
default:
 include("NavMenuEng.php");
 break;
}

?>

Edited by Psycho
Link to comment
Share on other sites

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.