Multi language with php .po (Poedit) [duplicate] - php
on my website, the user has several options such as language, date and region. when the user clicks anyone of those all is fine, the website adapts to the specific choices, but when they go to another page they loose all their choices, it would be nice if i found a way to keep them for their entire visit or perhaps 24hours.
example: bob goes onto my website, under the region setting, he clicks UK and as a result the website adapts and shows him a UK flag as a result. However, he when he goes to the next page he looses the flag and his region setting and has to choose his region setting all over again.
This is what I want to fix. I will post the whole code up in case this may help:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Loughborough University | Students Union</title>
<script type="text/javascript" src="scripts/changesheets.js"></script>
<?php include("scripts/lang_change.php"); ?>
<?php include("scripts/factoid_randomise.php"); ?>
<?php include("scripts/greeting.php"); ?>
<?php include("scripts/menu_change.php"); ?>
<?php include("scripts/lang_select.php"); ?>
<?php include("scripts/geo_loc_change.php"); ?>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/grey_white.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/orange_black.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/offwhite_blue.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript">
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr','li','p');
//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;
function ts( trgt,inc ) {
if (!document.getElementById) return
var d = document,cEl = null,sz = startSz,i,j,cTags;
sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;
if (!( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
cEl.style.fontSize = szs[ sz ];
for ( i = 0 ; i < tgs.length ; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
}
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'Japanese' :
echo "<div id='logo_japanese'></div>";
break;
case 'Chinese' :
echo "<div id='logo_chinese'></div>";
break;
default:
echo "<div id='logo'></div>";
break;
}
}
?>
<ruby style='float:right; margin-top:-80px;'>
<rb><button style='background-image:url(/misc/FYP/images/textchange.png); width:31px; height:29px; border:none; '></button> </rb>
<rb><a href="javascript:ts('body',-1)" ><button style='background-image:url(/misc/FYP/images/textchangeb.png); width:23px; height:29px; border:none;'></button></a></rb>
<rb><button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/theme1.png); width:29px; height:29px; border:none; '></button></rb>
<rb><button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/theme2.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/theme3.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button style='background-image:url(/misc/FYP/images/Britishflag.png);width:48px; height:20px;border:none;' ></button></rb>
</ruby>
<div class='greeting'>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo welcome($tz_ger,$greetings_ger);
break;case 'Korean' :
echo welcome($tz_kor,$greetings_kor);
break;case 'Russian' :
echo welcome($tz_rus,$greetings_rus);
break;
case 'Japanese' :
echo welcome($tz_jap,$greetings_jap);
break;
case 'Chinese' :
echo welcome($tz_chi,$greetings_chi);
break;
default:
echo welcome($tz_eng,$greetings_eng);
break;
}
}
?></div>
</div>
<div id="line"></div>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo makeMenu($links,$tabs_ger,$title);
break;
case 'Korean' :
echo makeMenu($links,$tabs_kor,$title);
break;
case 'Russian' :
echo makeMenu($links,$tabs_rus,$title);
break;
case 'Japanese' :
echo makeMenu($links,$tabs_jap,$title);
break;
case 'Chinese' :
echo makeMenu($links,$tabs_chi,$title);
break;
default:
echo makeMenu($links,$tabs_eng,$title);
break;
}
}
?>
<div id="line"></div>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo changeGeoLoc($GeoLoc,$details_ger,$geoplugin);
break;case 'Korean' :
echo changeGeoLoc($GeoLoc,$details_kor,$geoplugin);
break;case 'Russian' :
echo changeGeoLoc($GeoLoc,$details_rus,$geoplugin);
break;case 'Japanese' :
echo changeGeoLoc($GeoLoc,$details_jap,$geoplugin);
break;
case 'Chinese' :
echo changeGeoLoc($GeoLoc,$details_chi,$geoplugin);
break;
default:
echo changeGeoLoc($GeoLoc,$details_eng,$geoplugin);
break;
}
}
?>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'Russian' :
echo "<div id='welcome_pic_russian'>";
break;
case 'Japanese' :
echo "<div id='welcome_pic_japanese'>";
break;
case 'Chinese' :
echo "<div id='welcome_pic_chinese'>";
break;
default:
echo "<div id='welcome_pic'>
";
break;
}
}
?>
<div id="play_feature">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo selectLang($h_ger,$lang_ger,$values,$h2_ger,$lang_ger2,$countries,$day,$month,$year);
break;case 'Korean' :
echo selectLang($h_kor,$lang_kor,$values,$h2_kor,$lang_kor2,$countries,$day,$month,$year);
break;
case 'Russian' :
echo selectLang($h_rus,$lang_rus,$values,$h2_rus,$lang_rus2,$countries,$day,$month,$year);
break;
case 'Japanese' :
echo selectLang($h_jap,$lang_jap,$values,$h2_jap,$lang_jap2,$countries,$day,$month,$year);
break;
case 'Chinese' :
echo selectLang($h_chi,$lang_chi,$values,$h2_chi,$lang_chi2,$countries,$day,$month,$year);
break;
default:
echo selectLang($h_eng,$lang_eng1,$values,$h2_eng,$lang_eng2,$countries,$day,$month,$year);
break;
}
}
?>
<?php
/*
#author geoPlugin (gp_support#geoplugin.com)
#copyright Copyright geoPlugin (gp_support#geoplugin.com)
*/
require_once('scripts/geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
?>
<div id='menu2' style='width:250px; margin-left:-40px;'>
</div>
<div style="color:#616161; margin-left:-20px;">
<blockquote>‘<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo randomFactoid($factoidsg);
break;case 'Korean' :
echo randomFactoid($factoidsk);
break;case 'Russian' :
echo randomFactoid($factoidsr);
break;case 'Japanese' :
echo randomFactoid($factoidsj);
break;
case 'Chinese' :
echo randomFactoid($factoidsc);
break;
default:
echo randomFactoid($factoids);
break;
}
}
?>’</blockquote>
</div>
</font>
</div></div>
<div id="homepage_text">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_POST['languages'] as $language) {
switch ($language) {
case 'German' :
echo "<p>text</p>";
break;
case 'Korean' :
echo "<p>text.</p> ";
break;
case 'Russian' :
echo "<p>text </p>";
break;
case 'Japanese' :
echo "<p>text</p>";
break;
case 'Chinese' :
echo "<p>text</p>";
break;
default:
echo "<p>text</p>";
break;
}
}
?>
</div></div>
</div>
</body>
</html>
This may be doable in cookies/sessions or something similar but i dnt know how i could incorporate cookies/session into this with the way i have coded it.
Any other suggestions other than cookies or sessions are welcome.
Any help greatly appreciated.
VERY IMPORTANT UPDATE
*After the suggestions below i tried this code:*
<?php
session_start(); //put this at the top of your script on all pages that need to remember
if(isset($_POST['languages']))
{
$_SESSION['languages'] = $_POST['languages'];
}?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Loughborough University | Students Union</title>
<script type="text/javascript" src="scripts/changesheets.js"></script>
<?php include("scripts/lang_change.php"); ?>
<?php include("scripts/factoid_randomise.php"); ?>
<?php include("scripts/greeting.php"); ?>
<?php include("scripts/menu_change.php"); ?>
<?php include("scripts/lang_select.php"); ?>
<?php include("scripts/geo_loc_change.php"); ?>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/grey_white.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/orange_black.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/offwhite_blue.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript">
//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr','li','p');
//Specify spectrum of different font sizes:
var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var startSz = 2;
function ts( trgt,inc ) {
if (!document.getElementById) return
var d = document,cEl = null,sz = startSz,i,j,cTags;
sz += inc;
if ( sz < 0 ) sz = 0;
if ( sz > 6 ) sz = 6;
startSz = sz;
if (!( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
cEl.style.fontSize = szs[ sz ];
for ( i = 0 ; i < tgs.length ; i++ ) {
cTags = cEl.getElementsByTagName( tgs[ i ] );
for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
}
}
</script>
</head>
<body>
<div id="wrapper">
<div id="header">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'Japanese' :
echo "<div id='logo_japanese'></div>";
break;
case 'Chinese' :
echo "<div id='logo_chinese'></div>";
break;
default:
echo "<div id='logo'></div>";
break;
}
}
?>
<ruby style='float:right; margin-top:-80px;'>
<rb><button style='background-image:url(/misc/FYP/images/textchange.png); width:31px; height:29px; border:none; '></button> </rb>
<rb><a href="javascript:ts('body',-1)" ><button style='background-image:url(/misc/FYP/images/textchangeb.png); width:23px; height:29px; border:none;'></button></a></rb>
<rb><button onclick='JavaScript:changeSheets(1)' style='background-image:url(/misc/FYP/images/theme1.png); width:29px; height:29px; border:none; '></button></rb>
<rb><button onclick='JavaScript:changeSheets(2)' style='background-image:url(/misc/FYP/images/theme2.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button onclick='JavaScript:changeSheets(3)' style='background-image:url(/misc/FYP/images/theme3.png);width:29px; height:29px;border:none;' ></button></rb>
<rb><button style='background-image:url(/misc/FYP/images/Britishflag.png);width:48px; height:20px;border:none;' ></button></rb>
</ruby>
<div class='greeting'>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo welcome($tz_ger,$greetings_ger);
break;case 'Korean' :
echo welcome($tz_kor,$greetings_kor);
break;case 'Russian' :
echo welcome($tz_rus,$greetings_rus);
break;
case 'Japanese' :
echo welcome($tz_jap,$greetings_jap);
break;
case 'Chinese' :
echo welcome($tz_chi,$greetings_chi);
break;
default:
echo welcome($tz_eng,$greetings_eng);
break;
}
}
?></div>
</div>
<div id="line"></div>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo makeMenu($links,$tabs_ger,$title);
break;
case 'Korean' :
echo makeMenu($links,$tabs_kor,$title);
break;
case 'Russian' :
echo makeMenu($links,$tabs_rus,$title);
break;
case 'Japanese' :
echo makeMenu($links,$tabs_jap,$title);
break;
case 'Chinese' :
echo makeMenu($links,$tabs_chi,$title);
break;
default:
echo makeMenu($links,$tabs_eng,$title);
break;
}
}
?>
<div id="line"></div>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo changeGeoLoc($GeoLoc,$details_ger,$geoplugin);
break;case 'Korean' :
echo changeGeoLoc($GeoLoc,$details_kor,$geoplugin);
break;case 'Russian' :
echo changeGeoLoc($GeoLoc,$details_rus,$geoplugin);
break;case 'Japanese' :
echo changeGeoLoc($GeoLoc,$details_jap,$geoplugin);
break;
case 'Chinese' :
echo changeGeoLoc($GeoLoc,$details_chi,$geoplugin);
break;
default:
echo changeGeoLoc($GeoLoc,$details_eng,$geoplugin);
break;
}
}
?>
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'Russian' :
echo "<div id='welcome_pic_russian'>";
break;
case 'Japanese' :
echo "<div id='welcome_pic_japanese'>";
break;
case 'Chinese' :
echo "<div id='welcome_pic_chinese'>";
break;
default:
echo "<div id='welcome_pic'>
";
break;
}
}
?>
<div id="play_feature">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo selectLang($h_ger,$lang_ger,$values,$h2_ger,$lang_ger2,$countries,$day,$month,$year);
break;case 'Korean' :
echo selectLang($h_kor,$lang_kor,$values,$h2_kor,$lang_kor2,$countries,$day,$month,$year);
break;
case 'Russian' :
echo selectLang($h_rus,$lang_rus,$values,$h2_rus,$lang_rus2,$countries,$day,$month,$year);
break;
case 'Japanese' :
echo selectLang($h_jap,$lang_jap,$values,$h2_jap,$lang_jap2,$countries,$day,$month,$year);
break;
case 'Chinese' :
echo selectLang($h_chi,$lang_chi,$values,$h2_chi,$lang_chi2,$countries,$day,$month,$year);
break;
default:
echo selectLang($h_eng,$lang_eng1,$values,$h2_eng,$lang_eng2,$countries,$day,$month,$year);
break;
}
}
?>
<?php
/*
#author geoPlugin (gp_support#geoplugin.com)
#copyright Copyright geoPlugin (gp_support#geoplugin.com)
*/
require_once('scripts/geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
?>
<div id='menu2' style='width:250px; margin-left:-40px;'>
</div>
<div style="color:#616161; margin-left:-20px;">
<blockquote>‘<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo randomFactoid($factoidsg);
break;case 'Korean' :
echo randomFactoid($factoidsk);
break;case 'Russian' :
echo randomFactoid($factoidsr);
break;case 'Japanese' :
echo randomFactoid($factoidsj);
break;
case 'Chinese' :
echo randomFactoid($factoidsc);
break;
default:
echo randomFactoid($factoids);
break;
}
}
?>’</blockquote>
</div>
</font>
<a href="http://s06.flagcounter.com/more/7ydE" ><img src="http://s06.flagcounter.com/count/7ydE/bg=FFFFFF/txt=000000/border=CCCCCC/columns=3/maxflags=25/viewers=Visitors/labels=0/pageviews=1/" alt="free counters" style="border:none; margin-left:15px;"/></a></div></div>
<div id="homepage_text">
<?php
if(!isset($_POST['languages']))
{
$_POST['languages'] = array('English');
}
foreach ($_SESSION['languages'] as $language) {
switch ($language) {
case 'German' :
echo "<p> </p>";
break;
case 'Korean' :
echo "<p></p> ";
break;
case 'Russian' :
echo "<p> </p>";
break;
case 'Japanese' :
echo "<p>。</p>";
break;
case 'Chinese' :
echo "<p></p>";
break;
default:
echo "<p></p>";
break;
}
}
?>
</div></div>
</div>
</body>
</html>
WHICH DIDNT WORK. ANY reasons why, seem to have done everything people have told me?**
The session can be used at this situation. You can assign these values in the session variable and can access on all the pages of application.
$_SESSION['somevar']='someval';
You should take a serious look at using gettext for manageable localization support. Instead of doing conditionals for every piece of your page, you'll simply call a function like <?php _('Welcome!') ?> and it will be automatically translated according to your language setting.
Download the library
Follow these instructions
Sessions or Cookies are definitely the best way to do it:
The thing is that you have to have a way to connect it with the user.
Technically you could store it in a database and either store a cookie on the user's computer that says which database entry to read or even store the user's ip and relate it to the user that way (although that's a pretty unreliable method). But that's all probably an overkill for what you want to do.
Here is how to incorporate sessions into your code:
Posting only one language
For a start lets reformat what you already have.
You have $_POST['languages'] which is actually an array that contains one result.
In that case you may as well make it a string and call it $_POST['language']
You also must remember to post it correctly (in the singular) when the user originally chooses his language.
First off you have to start the session at the top of the page:
session_start();
Next you have to save the user's selection to a session variable.
We are going to check if the user has selected a language (from the $_POST variable) and, if yes, assign it to a $_SESSION variable.
if ($_POST['language']) {
$_SESSION['language'] = $_POST['language'];
}
The session variable functions identical to any other variable, but it will carry on from page to page until the session ends.
Now we are going to check what the language is
This is pretty simple. In your example you checked what the language was by finding what the user had 'posted':
isset($_POST['languages'])
In our new code, we are going to check the session variable, which we have just saved:
$_SESSION['language']
Choosing the right language
No need to make $_POST['languages'] an array and then use a foreach to loop through it.
A simpler way of doing it would be like this:
switch($_SESSION['language']) {
case "german": //do german suff
case "english": //do english suff
etc...
}
Additionally, you first checked if the session tag was empty and then put a value if it wasn't.
You can skip that step and instead put inside the switch() { } at the end, after all the cases:
default: //do default language stuff
As a session:
session_start(); //put this at the top of your script on all pages that need to remember
if(isset($_POST['languages']))
{
$_SESSION['languages'] = $_POST['languages'];
}
Then change:
foreach ($_POST['languages'] as $language) {
to
foreach ($_SESSION['languages'] as $language) {
As a cookie:
if(isset($_POST['languages']))
{
setcookie('language', $_POST['languages'], 7776000) //sets cookie for 90 days, or 7776000 seconds
}
and change
foreach ($_POST['languages'] as $language) {
to
foreach ($_COOKIE['languages'] as $language) {
I believe this answer is complete... do you intend to support multiple languages?
DEMO + SOURCE: https://so.lucafilosofi.com/remembering-users-selection-from-one-page-to-the-next/
<?php
session_start();
if (isset($_GET['lang'])) {
$_SESSION['lang'] = $_GET['lang'];
}
if (isset($_SESSION['lang'])) {
define(LANGUAGE, $_SESSION['lang']);
}
else {
define(LANGUAGE, 'en_GB');
}
include 'languages/'.LANGUAGE.'.php';
?>
Add the top of the code, write "session_start();"
After that, whenever an update is submitted, update the matching $_SESSION array's index (you may choose names such as "region", "language", "lng" - the choice is up to you as long as you are consistent). Then, whenever you are loading a page, load it depending on the value in the $_SESSION array.
See also: http://il2.php.net/manual/en/book.session.php
After all related session updates - one main thing is that how you set your $_SESSION variables. It shows that you get it from $_POST, but there is no place in code that actually posts the value. You mention that someone clicks to change the language - is it done via the form submit, or via a URL?
Add a dump of $_SESSION variable right after you set the language value, and see if it actually gets set... I have a feeling that you never reach that line of code as you don't have a $_POST variable defined anywhere...
The only problem with the session variable is that the user can't change his setting anymore, if that is what you want! But it should be possible using hidden input variable on each page, too. In fact I'm using hidden input variable all the time and also I compress this variable so it is quite fast and secure and also I'm using ajax.
It is very difficult to read the lengthy example code. Please reduce the size of a non working example.
The PHP session code relies on a SESSION ID. There are two ways to transport these ID from web page to web page: POST and GET. But what I can see is, that you support only one, the POST method. In case of GET you must add the SESSION ID variable SID to the URL used for navigation.
The details of SESSION ID handling are described in the PHP documentation:
Passing the Session ID
Related
PHP Switch Case not ending statement after "break;"
In following function if the input is blue then it is giving result as: "header content goes here Your favorite color is blue!" whereas it is supposed to give- "Your favorite color is blue!", please help me correcting it. If input is red then it is ending statement here as: "header content goes here" which is correct. Please forgive me if I am asking silly question as I am new to PHP and I don't know if it is ok or not to use function as variable in switch case. test1.php <?php function header2() { ?> header content goes here <?php } $good =header2(); $Input2 = $_POST['input']; switch ($Input2) { case "red": echo $good; break; case "blue": echo "Your favorite color is blue!"; break; case "green": echo "Your favorite color is green!"; break; default: echo "Your favorite color is neither red, blue, nor green!"; } ?> main.js $('[id=stringone]').click(function(){ var string =$('[id=stringotherone]').val(); $.post('test1.php',{input: string}, function(data){ $('[id=stringotherthanone]').text(data); }); }); test.php <! doctype html> <html lang="en"> <head> <link rel="stylesheet" href="css/hwcb.css"> </head> <body> <input type="button" value="Go" id="stringone"> <input type="text" id="stringotherone"/> <p><div id="stringotherthanone"></div></p> <script src="jquery.js"></script> <script src="js/css.js"></script> <script src="main.js"></script> </body> </html>
You need to return in the function otherwise it outputs when the function is called. Example: https://3v4l.org/1Ptml vs. https://3v4l.org/ug778 $good =header2(); is outputting the header content goes here, not the echo $good; in the switch. That actually does nothing because that variable is empty.
Change <?php function header2() { ?> header content goes here <?php } to <?php function header2() { return 'header content goes here'; }
Hide login link when logged in
My website welcome page has got a link to login and one to logout. I want to know how to only show the logout link when the user is logged in and the other way around? index.php code: <?php require_once('Connections/PAPCon.php'); ?> <?php //initialize the session if (!isset($_SESSION)) { session_start(); } // ** Logout the current user. ** $logoutAction = $_SERVER['PHP_SELF']."?doLogout=true"; if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){ $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){ //to fully log out a visitor we need to clear the session varialbles $_SESSION['MM_Username'] = NULL; $_SESSION['MM_UserGroup'] = NULL; $_SESSION['PrevUrl'] = NULL; unset($_SESSION['MM_Username']); unset($_SESSION['MM_UserGroup']); unset($_SESSION['PrevUrl']); $logoutGoTo = "login.php"; if ($logoutGoTo) { header("Location: $logoutGoTo"); exit; } } ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_PAPCon, $PAPCon); $query_Users = "SELECT * FROM tbl_utilizadores"; $Users = mysql_query($query_Users, $PAPCon) or die(mysql_error()); $row_Users = mysql_fetch_assoc($Users); $totalRows_Users = mysql_num_rows($Users); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>RelPro</title> <link rel="stylesheet" type="text/css" media="screen" href="style.css" /> <style type="text/css"> #container #intro #pageHeader h1 { font-size: 4em; } </style> </head> <body> <div id="container"> <div id="intro"> <div id="pageHeader" style="padding: 20px 0 0 50px;"> <h1>RelPro</h1><h2> </h2> <h2><span>by: Mário Honório 12ºPI Nº6</span></h2> <h2><div style="position: absolute; left: 944px; top: 152px; height: 100px;"><img src="Logo PAP 2.png" alt="" width="230" height="187" /></div></h2> </div> <div id="preamble"> <h3><span>Acerca da RelPro</span></h3> <p class="p1">Este website foi criado no âmbito do Curso Profissional de Técnico de Gestão de Equipamentos Informáticos de forma a avaliar toda a aprendizagem realizada. Foi concebido de forma a facilitar o acesso a relatórios de projectos de final de curso de várias áreas a todos os interessados. É um website de fácil acesso, simples design e produzido em linguagem PHP, MySQL e HTML.</p> </div> </div> <div id="supportingText"></div> <div id="footer"></div> <div id="linkList"> <div id="linkList2"> <div id="lselect"> <h3 class="select"><span>Secções:</span></h3> <ul> <li>RelPro</li> <li>Relatórios</li> <li>Admin</li> <li>Contactos</li> <li>Login</li> <li>Log out</li> </ul> </div></div> </div> </div> </body> </html> <?php mysql_free_result($Users); ?> Here is a picture of the section menu where the links are: Either hidden or disabled will do.
display it based on session if($_SESSION['MM_Username']) { ?> <li>Log out</li> <?php }else { ?> <li>Login</li> <?php }
The use of a ternary operator can be used effectively here. <?php error_reporting(E_ALL); ini_set('display_errors', 1); session_start(); session_destroy(); // comment this out if it gives you trouble // Comment this out to test and using your own method of user check. $_SESSION['MM_Username'] = "John"; $login = "<li>Login</li>"; $logout = "<li>Log out</li>"; $check_login = isset($_SESSION['MM_Username']) ? $logout : $login; $logout : $login - Only one will echo depending on if the session is set or not. Then replace this entire block: <ul> <li>RelPro</li> <li>Relatórios</li> <li>Admin</li> <li>Contactos</li> <li>Login</li> <li>Log out</li> </ul> with: <ul> <li>RelPro</li> <li>Relatórios</li> <li>Admin</li> <li>Contactos</li> <?php echo $check_login; ?> </ul> <?php echo $check_login; ?> takes care of both actions. You will need to make a few adjustments of course, as far as placement goes. Reference(s): http://php.net/manual/en/language.operators.comparison.php
You can display it with checking if the session variable(s) is set. Example for only one session variable: if(isset($_SESSION['MM_Username'])) echo '<li>Log out</li>'; else echo '<li>Login</li>'; Do not use MySQL driver as it is deprecated. Use MySQLi(mproved) instead.
After some research and some try and fail attempts here is the final code i used to do this thingy (with some addons): <?php $loginlink = "index.php"; if (isset($_SESSION['MM_Username'])){ echo "Hello " . $_SESSION['MM_Username']; echo "<br/><a href='".$logoutAction."'>Logout</a>"; }else{ echo "<a href='".$loginlink."'>Login</a>";} ?> It worked for me and maybe it can help someone else. Thanks to #Richard Reiber whose code was my jump start. Peace, Slaxer13
How to call a function onClick of a directory
i'm trying to make a file browser and i'm trying to find how to call a function when the user clicks on a directory. For starting i tried to use onClick inside a href on the class part (right before FUNCTION folderSize) having us a goal to open the path inside testDir if i click on any of the files or directories on the list but it does nothing. I'm searching for some hours now it but i can't find the solution. If someone could help i would be greatfull. Here is the index.php: <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link href="/css/myCSSfile.css" rel="stylesheet" type="text/css"> <link rel="shortcut icon" href="/images/dit.ico"><link rel="stylesheet" href="/css/search.css"> <link rel="stylesheet" href="/css/button.css"> <link rel="stylesheet" href="/css/button2.css"> <script type="text/javascript" src="/js/resolutionfinder.js"></script> <script type="text/javascript" src="/js/changeInputValue.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript" src="/js/ajaxcalls.js"></script> <body onload='ShowDivInCenter();' onresize='ShowDivInCenter();'> <div class="cont"> <div id="main"> </script> <div id="container"> <h1> UOP Directory Contents</h1> <img class="logo" src="/images/logo.jpg" title="uop search engine" width="450" height="240" /> <form action=''> <input type='search' id="search" name='s' autocomplete="off"> <input type='button' id="button" value='Search' class="button1" > </form> <div class="tfclear"></div> </div> <table class="sortable"> <thead> <tr> <th>Filename</th> <th>Type</th> <th>Size <small>(KB)</small></th> <th>Date Modified</th> </tr> </thead> <tbody> <?php // Opens directory $rootDirectory=opendir("."); starter($rootDirectory); Function starter($myDirectory) { $testDir = 'C:\webdev\apache\htdocs\allo1'; // Gets each entry while($entryName=readdir($myDirectory)) { $dirArray[]=$entryName; } // Finds extensions of files function findexts ($filename) { $filename=strtolower($filename); $exts=split("[/\\.]", $filename); $n=count($exts)-1; $exts=$exts[$n]; return $exts; } // Closes directory closedir($myDirectory); // Counts elements in array $indexCount=count($dirArray); // Sorts files sort($dirArray); // Loops through the array of files for($index=0; $index < $indexCount; $index++) { // Allows ./?hidden to show hidden files if($_SERVER['QUERY_STRING']=="hidden") {$hide=""; $ahref="./"; $atext="Hide";} else {$hide="."; $ahref="./?hidden"; $atext="Show";} if(substr("$dirArray[$index]", 0, 1) != $hide) { // Gets File Names $name=$dirArray[$index]; $namehref=$dirArray[$index]; // Gets Extensions $extn=findexts($dirArray[$index]); // Gets file size $size=number_format(filesize($dirArray[$index])/1024,2). ' KB'; // Gets Date Modified Data $modtime=date("M j Y g:i A", filemtime($dirArray[$index])); $timekey=date("YmdHis", filemtime($dirArray[$index])); // Prettifies File Types, add more to suit your needs. switch ($extn){ case "png": $extn="PNG Image"; break; case "jpg": $extn="JPEG Image"; break; case "svg": $extn="SVG Image"; break; case "gif": $extn="GIF Image"; break; case "ico": $extn="Windows Icon"; break; case "txt": $extn="Text File"; break; case "log": $extn="Log File"; break; case "htm": $extn="HTML File"; break; case "php": $extn="PHP Script"; break; case "js": $extn="Javascript"; break; case "css": $extn="Stylesheet"; break; case "pdf": $extn="PDF Document"; break; case "zip": $extn="ZIP Archive"; break; case "bak": $extn="Backup File"; break; default: $extn=strtoupper($extn)." File"; break; } // Separates directories if(is_dir($dirArray[$index])) { $extn="<Directory>"; $size=folderSize($dirArray[$index]); $size=number_format($size/1024,2). ' KB'; $class="dir"; } else { $class="file"; } // Cleans up . and .. directories if($name=="."){$name=". (Current Directory)"; $extn="<System Dir>";} if($name==".."){$name=".. (Parent Directory)"; $extn="<System Dir>";} // Print 'em print(" <tr class='$class'> <td>$name</td> <td>$extn</td> <td>$size</td> <td sorttable_customkey='$timekey'>$modtime</td> </tr>"); } } } FUNCTION call_php_function(directory) { $.post("index.php", ("dir": directory), function(data){ alert(data); // Will output, whatever your starter-functions outputs }); } FUNCTION folderSize($dir) { $count_size = 0; $count = 0; $dir_array = scandir($dir); foreach($dir_array as $key=>$filename){ if($filename!=".." && $filename!="."){ if(is_dir($dir."/".$filename)){ $new_foldersize = foldersize($dir."/".$filename); $count_size = $count_size+ $new_foldersize; }else if(is_file($dir."/".$filename)){ $count_size = $count_size + filesize($dir."/".$filename); $count++; } } } return $count_size; } ?> <div id="ajaxresults" class="ajaxresults"></div> <br /> <br /> <hr class="style-seven"> <br /> <br /> <div id="showing"></div> <div id="results" class="results"></div> </tbody> </table> <form><input type='button' id="button" value='DownLoadAll' class="button2"onClick="window.location.href='downloadZip.php?directtozip=$myDirectory&zipaki'"></form> </div> </div> </body>
Please Notice, that this code is not suitable for public productive use. It's good enough to learn with it. The HTML-Part: Directory-Name The jQuery (Js) Part: function call_php_function(php_function, anyattribut) { $.post("functions.php", ("call_function": php_function, "attribute_name": anyattribut), function (data) { // Data is what you get from the echo in the PHP-Script below alert(data); // Outputs "hello" } } The PHP-Part: function any_php_function($attribut) { echo "hello"; } $allowed_funcs = array("any_php_function", "any_other_function"); if (in_array($_POST["call_function"], $allowed_funcs)) call_user_func($_POST["attribute_name"]); This code is enough for your purposes: HTML-Part: directory-name jQuery-Part: function call_php_function(directory) { $.post("your_file.php", ("dir": directory), function(data){ alert(data); // Will output, whatever your starter-functions outputs }); } PHP-Part if (isset($_POST["dir"]) && !empty($_POST["dir"])) { starter($_POST["dir"]); }
Following a Codeigniter/Ajax/Jquery tutorial: Can't seem to debug what I'm doing wrong
I'm following the tutorial here: http://www.jotorres.com/2012/01/using-jquery-and-ajax-with-codeigniter/ For my view, I have: <script type="text/javascript" src="<?php echo jquery ?>"></script> <button type="button" name="getdata" id="getdata">Get Data.</button> <div id="result_table"> </div> <script type="text/javascript" language="javascript"> $('#getdata').click(function(){ $.ajax({ url: "<?php echo base_url().'users/get_all_users';?>", type:'POST', dataType: 'json', success: function(output_string){ $("#result_table").append(output_string); } // End of success function of ajax form }); // End of ajax call }); </script> The header and footer are predominantly links to other pages on the website but the relevant sections of the header and beginning are: <!DOCTYPE html> <!-- Website template by Jeremiah Tantongco, jtantongco#gmail.com --> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $title ?> </title> <link rel="stylesheet" href="<?php echo template ?>" type="text/css" /> <link rel="stylesheet" href="<?php echo display_elements ?>" type="text/css" /> </head> Note: template and display_elements are variables pointing to css files somewhere on the server declared in config/constants Note: jquery is a variable declared in config/constants that points to the newest jquery file on the server. It is the newest developer version available. for controller methods: public function test(){ $this->renderTemp_noData('users/test', 'Test page'); } public function get_all_users(){ $query = $this->db->get('users'); if($query->num_rows > 0){ $header = false; $output_string = ""; $output_string .= "<table border='1'>\n"; foreach ($query->result() as $row){ $output_string .= "<tr>\n"; $output_string .= "<th>{" . $row->uid ."}</th>\n"; $output_string .= "</tr>\n"; } $output_string .= "</table>\n"; } else{ $output_string = "There are no results"; } //echo $output_string; echo json_encode($output_string); } public function renderTemp_noData($page, $title) { $data['title'] = $title; $accountType = $this->session->userdata('aid'); switch ($accountType) { case 0: $this->load->view('templates/LI_header', $data); $this->load->view($page); $this->load->view('templates/LI_footer'); break; case 1: $this->load->view('templates/LI_header_role1',$data); $this->load->view($page); $this->load->view('templates/LI_footer_role1'); break; case 2: $this->load->view('templates/LI_header_role2',$data); $this->load->view($page); $this->load->view('templates/LI_footer_role2'); break; case 3: $this->load->view('templates/LI_header_role3',$data); $this->load->view($page); $this->load->view('templates/LI_footer_role3'); break; default: redirect('/sessions/log_in/','refresh'); } } When I go to the page with the Get Data button, I press it and nothing happens. So if anyone knows how to expose the error message that would be great. Also, When I test to see output for get_all_users, this is what I get: "<table border='1'>\n<tr>\n<th>{1}<\/th>\n<\/tr>\n<tr>\n<th>{2}<\/th>\n<\/tr>\n<tr>\n<th>{3}<\/th>\n<\/tr>\n<tr>\n<th>{4}<\/th>\n<\/tr>\n<tr>\n<th>{5}<\/th>\n<\/tr>\n<tr>\n<th>{6}<\/th>\n<\/tr>\n<tr>\n<th>{7}<\/th>\n<\/tr>\n<tr>\n<th>{8}<\/th>\n<\/tr>\n<tr>\n<th>{9}<\/th>\n<\/tr>\n<tr>\n<th>{10}<\/th>\n<\/tr>\n<tr>\n<th>{12}<\/th>\n<\/tr>\n<tr>\n<th>{13}<\/th>\n<\/tr>\n<tr>\n<th>{14}<\/th>\n<\/tr>\n<tr>\n<th>{15}<\/th>\n<\/tr>\n<tr>\n<th>{16}<\/th>\n<\/tr>\n<tr>\n<th>{17}<\/th>\n<\/tr>\n<tr>\n<th>{18}<\/th>\n<\/tr>\n<\/table>\n" Is JSON supposed to look this way? My gut says no but this is the first time I've ever used JSON, Jquery, and AJAX. Also, The numerical values are correct. Looking at my database, there are only UIDs 1-18 with no 11.
Your get_all_users() function adds HTML to your $output_string, which you are then json_encoding. That's not quite how JSON works. Replace with: public function get_all_users() { $this->output->set_content_type('text/javascript; charset=UTF-8'); $query = $this->db->get('users'); echo json_encode($query->result()); } That said, your database calls should live in a model, not your controller.
jquery .html() not displaying in ie works fine in firefox
I have a what i would call a stange problem, though its to do with internet explorer (7 8 in both normal and compatability modes) so is not that strange to have a problem!! I have created a page break system. there are buttons on the page [previous] [next] [show all] / [show as pages] when the buttons are clicked it uses an ajax call to get the data and replace the html of a div. all the buttons work in firefox, safari etc but in ie only the [show all] [show as pages] buttons work the [previous] [next] buttons just empty the data. the page is visible here: http://www.pimms-transfer-eu.org/index_ietest.php?id_lang=10 here is my jquery code: $(document).ready(function() { $id_sec = <?php echo $row_rs_sections['id_sec']; ?>; function getBreaks($id_sec ,$id_brk){ // function to get next page and previous page var ajax_load = "<img src='img/icons/loadinfo_circle 16x16.gif' alt='loading...' /> Loading data..."; $("#pbcontent").html(ajax_load); $.get('getbreakData.php?id_sec='+$id_sec+'&id_brk='+$id_brk, function(data) { $("#pbcontent").empty(); // tried adding this to fix ie prob $("#pbcontent").html(data); }); }; function getAllBreaks($id_sec){ //function to get all pages var ajax_load = "<img src='img/icons/loadinfo_circle 16x16.gif' alt='loading...' /> Loading data..."; $("#pbcontent").html(ajax_load); $.get('getbreakData.php?id_sec='+$id_sec+'&showall=true', function(data) { $("#pbcontent").html(data); }); }; //using live as buttons are page loaded via ajax $('.showAllButton').live('click', function(){ $id_brk = $(this).attr('rel'); getAllBreaks($id_sec, $id_brk); }); $('.showAsPagesButton').live('click', function(){ $id_brk = $(this).attr('rel'); getBreaks($id_sec, 0); }); $('.prevButton').live('click', function(){ $id_brk = $(this).attr('rel'); getBreaks($id_sec, $id_brk); }); $('.prevButton').live('hover', function () { this.src = '/img/icons/prev_on.gif'; }, function () { this.src = '/img/icons/prev_off.gif'; }); $('.nextButton').live('click', function(){ $id_brk = $(this).attr('rel'); getBreaks($id_sec, $id_brk); }); $('.nextButton').live('hover', function () { this.src = '/img/icons/next_on.gif'; }, function () { this.src = '/img/icons/next_off.gif'; }); getBreaks($id_sec ,0); // load page }); and the code that is called via ajax: <?php require_once('Connections/pimms.php'); ?> <?php // Require the MXI classes require_once ('includes/mxi/MXI.php'); if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $MMID_rs_pagebreaks = "0"; if (isset($_GET['id_sec'])) { $MMID_rs_pagebreaks = $_GET['id_sec']; } mysql_select_db($database_pimms, $pimms); $query_rs_pagebreaks = sprintf("SELECT * FROM sections_sec WHERE id_sec = %s", GetSQLValueString($MMID_rs_pagebreaks, "int")); $rs_pagebreaks = mysql_query($query_rs_pagebreaks, $pimms) or die(mysql_error()); $row_rs_pagebreaks = mysql_fetch_assoc($rs_pagebreaks); $totalRows_rs_pagebreaks = mysql_num_rows($rs_pagebreaks); $id_sec = $row_rs_pagebreaks['id_sec']; ?> <?php // set up the vars //store the content for the page in $str $str = $row_rs_pagebreaks['text_sec']; // break up the content into pages $myPages = explode('<div style="page-break-after: always;">',$str); // get the number of pages $pageCount = count($myPages); // array starts from 0 so create values for the display counter +1 $pageCountHR = $pageCount; // set default to the first page ($page = 0) $page = 0; //set the default to the display counter $pageHR = $page+1; // set the page to the page requested if it has been passed if (isset($_GET['id_brk'])) { $page = $_GET['id_brk']; //set the value to the display counter $pageHR = ($page+1); }; // set up the next and previous links $nextLink = $page +1; $prevLink = $page -1; // echo the results /* echo('pagecount in array = '.$pageCount.'<br>'); echo('hr pagecount = '.$pageCountHR.'<br>'); echo('page in array = '.$page.'<br>'); echo('hr page = '.$pageHR.'<br>'); echo('prev page = '.$prevLink.'<br>'); echo('next page = '.$nextLink.'<br>'); */ // set wether to show all pages or not $showAll = false; if (isset($_GET['showall'])) { $showAll = $_GET['showall']; }; // set the page to display $pagetoprint = $myPages[$page]; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="css/pagebreaks2.css" rel="stylesheet" type="text/css" /> <script src="Scripts/development-bundle/jquery-1.4.2.js" type="text/javascript"></script> <script src="Scripts/roundedcorners.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $('.pagingInfo').corner(); $('.navButton_on').corner(); }); </script> </head> <body> <?php if($pageCount > 1){?> <div id="navBar"> <?php if ($page != 0){?> <div id="navitem"> <?php if($showAll == false){?> <img src="/img/icons/prev_off.gif" alt="To Left" width="21" height="15" class="prevButton" rel="<?php echo($prevLink);?>"/> <?php };?> </div> <?php }else{?> <div class="noButton"></div> <?php };?> <?php if($showAll == false){?> <div class="pagingInfo"> Page <?php echo($pageHR);?> of <?php echo($pageCountHR);?> </div> <?php };?> <?php if ($pageHR < $pageCountHR){ ?> <div id="navitem"> <?php if($showAll == false){?> <img src="/img/icons/next_off.gif" alt="To Right" name="NavRight" class="nextButton" id="NavRight" rel="<?php echo($nextLink); ?>"/> <?php };?> </div> <?php }else{ ?> <div class="noButton"></div> <?php }; ?> <?php if ($showAll == false){?> <div class="showAllButton navButton_on"> Show All Pages </div> <?php };?> <?php if ($showAll == true){?> <div class="showAsPagesButton navButton_on"> Show As Pages </div> <?php };?> </div> <br /> <br /> <?php };?> <h1><?php echo $row_rs_pagebreaks['name_sec']; ?></h1> <?php if ($showAll == true){ echo($str); }else{ echo($pagetoprint); };?> <?php if($pageCount >1){?> <div id="navBar"> <?php if ($page != 0){?> <div id="navitem"> <?php if($showAll == false){?> <img src="/img/icons/prev_off.gif" alt="To Left" width="21" height="15" class="prevButton" rel="<?php echo($prevLink);?>"/> <?php };?> </div> <?php }else{?> <div class="noButton"></div> <?php };?> <?php if($showAll == false){?> <div class="pagingInfo"> Page <?php echo($pageHR);?> of <?php echo($pageCountHR);?> </div> <?php };?> <?php if ($pageHR < $pageCountHR){ ?> <div id="navitem"> <?php if($showAll == false){?> <img src="/img/icons/next_off.gif" alt="To Right" name="NavRight" class="nextButton" id="NavRight" rel="<?php echo($nextLink); ?>"/> <?php };?> </div> <?php }else{ ?> <div class="noButton"></div> <?php }; ?> <?php if ($showAll == false){?> <div class="showAllButton navButton_on"> Show All Pages </div> <?php };?> <?php if ($showAll == true){?> <div class="showAsPagesButton navButton_on"> Show As Pages </div> <?php };?> </div> <br /> <br /> <?php };?> </body> </html> <?php mysql_free_result($rs_pagebreaks); ?> EDIT: i looked into document types in case that was the problem and i think i have it set up correctly on both files: getbreakdata.php: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> index_ietest.php: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
You're trying to stick the whole <html> block of another page inside a <div>...IE isn't going to like that. There are other issues as well, reused IDs and an unmatched </div> in your source that IE also won't tolerate very well. The main issue is that unclosed </div> which doesn't exist in the Show All version. but why not fix all the issues? :) Instead of $.get() you can use .load() to get content from the server for only a portion of the page, for example: $("#pbcontent").load('getbreakData.php?id_sec='+$id_sec+' #container'); This would load only the #container into #pbcontent, discarding the rest of the requested page.
I encountered same problem previously. In IE JQuery live method was not working for some AJAX generated contents. So i used JQuery livequery plugin.
Thanks nick pointing out the missing div element was a great help. helped me locate the problem!! The content to be displayed was pulled from a database, it was in the code that split the content into seperate pages that was causing the error. $myPages = explode('<div style="page-break-after: always;">',$str); when it should have been: $myPages = explode('<div style="page-break-after: always;"><span style="display: none;"> </span></div>',$str); now the closing div for the page-break is gone all works great. will add http://validator.w3.org/ to my list of tools!!!