PHP - Multilanguage Site Works On Localhost But Not On The Internet...
Hello,
I made a website, with 3 lang on it, and site works fine (localhost) but when I upload it, default lang is EN and whenever I change lang on the web, let's say from EN to FR, page goes on that lang in this case on FR and redirect me on home page and all text on site is on FR, that's ok, but after that, when I try to click on let's say about us, then on it's own change it back to default lang, and show me that page (about us) but on default lang... Here is sample of code how it's look... This is select.php and I include_once this file on every page... <?php session_start(); header('Cache-control: private'); // IE 6 FIX if(isSet($_GET['lang'])) { $lang = $_GET['lang']; // register the session and set the cookie $_SESSION['lang'] = $lang; setcookie("lang", $lang, time() + (3600 * 24 * 30)); } else if(isSet($_SESSION['lang'])) { $lang = $_SESSION['lang']; } else if(isSet($_COOKIE['lang'])) { $lang = $_COOKIE['lang']; } else { $lang = 'en'; } switch ($lang) { case 'en': $lang_file = 'lang.en.php'; break; case 'fr': $lang_file = 'lang.fr.php'; break; case 'de': $lang_file = 'lang.de.php'; break; default: $lang_file = 'lang.en.php'; } include_once 'lang/'.$lang_file; This is lang.en.php... $lang = array(); // menu $lang['txt1'] = 'Home'; $lang['txt2'] = 'About Us'; $lang['txt3'] = 'Services'; $lang['txt4'] = 'Contact'; It's the same for other two languages... and I simply put in index.php this... <ul> <li><a href="index.php"><em><b><?php echo $lang['txt1'];?></b></em></a></li> <li><a href="about.php"><em><b><?php echo $lang['txt2'];?></b></em></a></li> <li><a href="services.php"><em><b><?php echo $lang['txt3'];?></b></em></a></li> <li><a href="contact.php"><em><b><?php echo $lang['txt4'];?></b></em></a></li> </ul> Let's say again, this kind of code works fine on localhost, but on web not... Any idea why? Thank you. Cheers. Similar TutorialsHow should i input language file into db and then output it with user selected language?
$username = 'KELLY'; $offerName = 'Crowd Flower'; $amount = '30'; $currency = 'points'; $lang['text']['a_001'] = '%a has just completed the %b offer worth %c %d.';// ENGLISH // $input = str_replace(array('%a','%b','%c','%d'), array($username, $offerName, $amount, $currency), $lang['text']['a_001']); print $input; Edited by davidolson, 14 November 2014 - 11:04 AM. I was hoping someone could help me figure out why my Code: [Select] header('Location: .');works right on my localhost testing computer but not when I load it onto the actual server. Here are the two files in question. The first is a snippet from my index.php controller file. Code: [Select] if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include '../../includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select * from s_times where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching service time details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $day = $row['day']; $time = $row['time']; $event = $row['event']; $avail = $row['avail']; $orderby = $row['orderby']; $button = 'Update'; } include 'stimes_modify.php'; exit(); } if (isset($_GET['editform'])) { include '../../includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $day = mysqli_real_escape_string($link, $_POST['day']); $time = mysqli_real_escape_string($link, $_POST['time']); $event = mysqli_real_escape_string($link, $_POST['event']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $sql = "Update s_times set day = '$day', time = '$time', event = '$event', avail = '$avail', orderby = '$orderby' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating service times ' . mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } here is the stimes_modify.php file code Code: [Select] if (isset($_POST['action']) and $_POST['action'] == 'Edit') { include '../../includes/db.inc.php'; { $id = mysqli_real_escape_string($link, $_POST['id']); $sql = "Select * from s_times where id = '$id'"; $result = mysqli_query($link, $sql); if (!$result) { $error = 'Error fetching service time details ' . mysqli_error($link); include '../../includes/error.php'; exit(); } $row = mysqli_fetch_array($result); $pagetitle = 'Edit Category'; $action = 'editform'; $id = $row['id']; $day = $row['day']; $time = $row['time']; $event = $row['event']; $avail = $row['avail']; $orderby = $row['orderby']; $button = 'Update'; } include 'stimes_modify.php'; exit(); } if (isset($_GET['editform'])) { include '../../includes/db.inc.php'; $id = mysqli_real_escape_string($link, $_POST['id']); $day = mysqli_real_escape_string($link, $_POST['day']); $time = mysqli_real_escape_string($link, $_POST['time']); $event = mysqli_real_escape_string($link, $_POST['event']); $avail = mysqli_real_escape_string($link, $_POST['available']); $orderby = mysqli_real_escape_string($link, $_POST['orderby']); $sql = "Update s_times set day = '$day', time = '$time', event = '$event', avail = '$avail', orderby = '$orderby' where id = '$id'"; if (!mysqli_query($link, $sql)) { $error = 'Error updating service times ' . mysqli_error($link); include '../../includes/error.php'; exit(); } header('Location: .'); exit(); } The functionality of both pages seems to be working in relation to editing the database but the page will not redirect back to the main page when it gets back down to the header line. Like I said it works on localhost just not on actual server. I also tried putting in the full URL like this Code: [Select] header('Location: http://www.bbcpa.org/dbsite/admin/stimes/stimes/php');and still got a blank page. The URL in the address bar shows this http://www.bbcpa.org/dbsite/admin/stimes/?editform it should show this http://www.bbcpa.org/dbsite/admin/stimes/ so maybe something is wrong with this line in stimes_modify.php Code: [Select] <form action="?<?php htmlout($action); ?>" method="POST"> anyway any help would be greatly appreciated. Thanks Is there a reason why on my local machine with php, my login system works, but then when I upload my files and test it on my web host, the login system doesn't work properly. I'm using the same php version on my local machine and on my webhost, so I don't understand why it wouldn't work the same. When I try logging in on my webhost, everything processes as normal when a correct user/pass combo is found in the database, however, my session just doesn't seem to be saved, and therefore I won't be logged in. It'll end up refreshing to the home page (as I have it setup), but it won't show me as logged in. Is there something special I need to do in order for the session to be stored correctly? (I realize I haven't pasted any code, but I'm not sure exactly how much code would be needed for me to show in order to resolve the issue). Hi all, I wonder if any of you have this problem before.. I have a login page with "checked box remember me" - It is working fine in my localhost machine I can see the COOKIE in my browser's option setting (Firefox). But now the problem is: When I run the script in my test server; and do exactly the same thing..the COOKIE did not seem know. When I logged in as an admin and checked the box. And closed all the browser. Then, open the browser (Firefox)and go to the index page (landing page) then it redirect me to the login page instead. I looked the at COOKIE setting in my Firefox and I can it is stored there. Any ideas whats wrong? I have a CURL code that fetches some XML content from a remote server. I get the expected output on my localhost (XAMPP on windows). But from the live site(hosted on Linux), I get the CURL error:'couldn't connect to host'. function DownloadUrl($Url, $p){ // is curl installed? if (!function_exists('curl_init')){ die('CURL is not installed!'); } // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt ($ch, CURLOPT_POSTFIELDS, $p); curl_setopt ($ch, CURLOPT_POST, 1); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); if($output === false) echo 'Curl error: ' . curl_error($ch); else print $output; // close curl resource to free up system resources curl_close($ch); } I have been banging my head for quite a number of hours on this.........I am getting the below error with firefox 7 or chrome but NOT with IE Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/unlockth/public_html/motorola/insertmoto.php on line 35 Here is the code.......pls can anyone help me? <?php $userip = ($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; $name = $_POST['name'] ; $email = $_POST['email'] ; $phone = $_POST['phone'] ; $operator = $_POST['operator'] ; $imei = $_POST['imei'] ; $todayis = date("l, F j, Y, g:i a") ; @mail( "xxx@xxx.com", "ORDER SUBMISSION", $message = " $userip $message = $todayis Name: $name Email: $email Phone Model: $phone Phone Operator: $operator Phone Imei: $imei", "From: MOTOROLA SUBMISSION>"); ?> <? $id = $_POST['id']; include "/home/unlockth/password.php"; mysql_select_db("unlockth_unlocking",$db); mysql_query("INSERT INTO custdetails VALUES ('','$name','$email','$phone','$operator','$imei')"); $insertid = mysql_insert_id(); include "/home/unlockth/password.php"; mysql_select_db("unlockth_unlocking",$db); $getdata = mysql_query("SELECT * FROM motorola WHERE id=$id", $db); $row = mysql_fetch_array($getdata); $title = $row["title"]; $price_1 = $row["price_1"]; $price_2 = $row["price_2"]; $price_3 = $row["price_3"]; $imageaddr = $row["imageaddr"]; $description = $row["description"]; $keywords = $row["keywords"]; $time = $row["time"]; include '/home/unlockth/public_html/motorola/outputmotocode.php';?> Hi guys, I need a help to find out what is a problem. Some of my code does not work on my local comp and in the same time it works well when I place it on Internet server. First example: Code: [Select] <body> <?php if($_POST['submit_form'] == "Submit") { $varNewTeam = $_POST['Reg_Team']; $varNewCity = $_POST['Reg_City']; $db = mysql_connect('localhost', 'root', '') or die ('no connection with server'); mysql_select_db('db_m ,$db) or die('DB error'); mysql_query ("INSERT INTO reg2012 VALUES ('$varNewTeam','$varNewCity')") or die('insert error'); } ?> <form action="registration_2012_form.php" method="post"> <p>Team: <input type="text" name="Reg_Team" size="20" maxlength="50" value="<?=$varNewTeam;?>" /><br /></p> <p>City: <input type="text" name="Reg_City" size="20" maxlength="50" value="<?=$varNewCity;?>" /><br /></p> <p><input type="Submit" value="Submit" name="submit_form" /></p> </form> </body> On local comp: It gives me message "Undefined index: submit_form". On Net server works well. If I split the code in two files. In the first one I leave the form with "action=FILE2.php" and put my php code in the second file "FILE2.php" - it starts work even on local server. second example: Code: [Select] <body> <?php $db = mysql_connect('localhost', 'root', '') or die ('no connection with server'); mysql_select_db('db_m' ,$db) or die('DB error'); mysql_query ("CREATE TABLE temp1 (team char(50), city char(50) )") or die('create tables error'); ?> </body> It works in the Net and can not create the TABLE on my local comp. I use XAMPP on my local comp (if it's important) This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=346255.0 Hi, my school say not to use XAMPP, and I already have PHP installed, MySQL installed, Apache I am not sure, but assuming if I have it installed, how do I connect to localhost b/c beforer when I use XAMPP, the default for where to get php/mysql running was: C:\xampp\htdocs\ Please any help appreciated! does anyone know of a simple tutorial which will show me how to receive email sent via my localhost? i cant develop my script fully because of the email errors. thanks I'm looking to connect to a MySQL localhost on my mac. I've been working for a few hours at this and I still can't figure it out. Below is my code. I've tried a number of different ways to connect to the database including using new mysqli, mysql_connect and PEAR MDB2. Any suggestions as to what I can do? Thanks in advance. <?php $first=$_POST['first']; $last=$_POST['last']; if (!$first || !$last) { echo 'Error: Enter the required data.'; exit; } if (!get_magic_quotes_gpc()) { $first = addslashes($first); $last = addslashes($last); } $hostname = 'localhost:8889'; $username = 'root'; $password = 'root'; $dbname = 'phonebook'; @ $db = new mysqli($hostname,$username.$password,$dbname); if (mysqli_connect_errno()) { echo 'Errer: Could not connect to database'; exit; } echo '.....Connected Successfuly'; $query = "insert into contact values ('null','".$first."','".$last."')"; $result = $db->query($query); if ($result) { echo $db->affected_rows." contact inserted into the database"; echo 'Contact Entered: '.$first.' '.$last.''; } else { echo 'Error: Contact not added.'; exit; } $db->close(); ?> Hi, I still a noob in PHP programming I hope somebody in the forum can help me and give an ideas how to fixed to this problem, everytime I run localhost this message appear: ErrorException in Builder.php line 1023:count(): Parameter must be an array or an object that implements CountableBut if I type localhost/(anycharacter) the page appear but with error 404(kindly refer to image, all other buttons are working except the one indicated with the arrow( kindly refer on the last image, note: app_debug set to true), this problem keeps bugging me for a few weeks now that I still cannot find a way to fixed it. Thank you in advance. )
I've installed Drupal 7.1 on my computer and I'm trying to access it via localhost. However, the site does not load the "index.php" file. Instead, I get the list of files and folders in the working directory with the heading "Index of /drupal71" (drupal71 is the temporary site name). The .htaccess file has the following lines, so I'm confused as to why index.php doesn't load automatically. Code: [Select] # Set the default handler. DirectoryIndex index.php index.html index.htm Any suggestions? Hello, I am trying to create a registration module where an email would be sent to the user after registration. I am using xampp and have tried php mailer http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php4/0.90/ but couldn't get it to work... I've been told that it is possible to send an email from localhost through smtp... I need to know how to accomplish that. Am a beginner. suggestions and help would be appreciated I have a Login Script with a Remember me Function. The Script works flawlessly on my local server but when I upload it doesn't work on my web server. From what I can tell its a Session issue, When I log in, I make a session with the user ID, in which is used to pull all there information on other pages. On my local host it makes the sessions and everything is dandy, but on the web server it doesn't seem to make the session. Can anyone shed any light on this, I'm clueless once again ^_^ this problem really drives me crazy..hope that anyone could help. I left my page only with <?php session_start(); ?> with no script at all..and i still got error Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\Program Files\XAMPP 1.5.4\xampp\htdocs\folder\page1.php:1) in E:\Program Files\XAMPP 1.5.4\xampp\htdocs\folder\page1.php on line 2 No white space at all. I tried to upload this file into the server (not local) and no error appeared. but when i run it in my local server, error appeared. I restart my xampp so many times but still didn't fix this. what's the problem then? thanks in advance Hi, would like to know if there is any way to send email using localhost? is it possible and how can i do it? This topic has been moved to Other. http://www.phpfreaks.com/forums/index.php?topic=327407.0 I seem to be seeing a problem I havent noticed before when I use header for a redirect the session data passes to the new page when I use href it seems as though even when I do a session_start() on the new page the session data doesnt pass Is this normal or is there a setup issue on my server (bluehost) everything works fine on wamp but when i upload to implement it no good I am using this to generate PDF reports using fpdf, I want it to open a new page instead of just redirecting Is it that it is unable to pass the data to a new page on a server?? |