Jump to content

.htaccesss encoding issues


megetron

Recommended Posts

Hi,

I haveof issues regarding encoding. in my old hosting server I had none.

To enforce the server to use utf-8. looks like the server use another encoding, so this is my htaccess file:

 

<FilesMatch "\.(htm|html|css|js)$">

ForceType 'text/html; charset=UTF-8'

</FilesMatch>

<Files "default.php">

ForceType 'text/html; charset=UTF-8'

</Files>

<Files "emailvalidate.php">

ForceType 'text/html; charset=UTF-8'

</Files>

 

 

When I try to execute emailvalidate.php I get a strange behaviour. here is the output:

connection($host,$user,$pass,$db); if((!isset($B1))and($flag=="0")) { // form auto submitted by List $event = $eventcompo; if($event=="ChooseEvent") { $msg="Please select an Event! "; $_SESSION['BODY']=""; $_SESSION['HEADER']=""; $_SESSION['FOOTER']=""; } $_SESSION['BODY']=""; $_SESSION['HEADER']=""; $_SESSION['FOOTER']=""; $sql="SELECT * FROM partners_adminmail, partners_event WHERE partners_adminmail.adminmail_eventname = partners_event.event_name AND partners_adminmail.adminmail_eventname = '$event' "; $res=mysql_query($sql); while($row = mysql_fetch_object($res)) { $from=$row->adminmail_from; $sub=$row->adminmail_subject; $_SESSION['BODY']=$row->adminmail_message; $_SESSION['HEADER']=$row->adminmail_header; $_SESSION['FOOTER']=$row->adminmail_footer; $status=$row->event_status; } $msg=""; header("Location:index.php?Act=email&from=$from&sub=$sub&header=$header&body=$body&footer=$footer&event=$event&status=$status&msg=$msg&to=$to"); exit; } if((isset($B1))or($flag=="1")) { // echo "submitted from button"; $event = $eventcompo; $from =trim($fromtxt); $sub =trim($subjecttxt); $body =trim($bodytxt); $header =trim($headertxt); $footer =trim($footertxt); $getst =$statusradio; $_SESSION['HEADER']=$header; $_SESSION['BODY']=$body; $_SESSION['FOOTER']=$footer; if ($getst=="active") { $status="yes"; } else { $status="no"; } } // validations if(empty($from)) $err = "1"; else $err = "0"; if(empty($sub)) $err .= ".1"; else $err .= ".0"; if(empty($header)) $err .= ".1"; else $err .= ".0"; if(empty($body)) $err .= ".1"; else $err .= ".0"; if(empty($footer)) $err .= ".1"; else $err .= ".0"; if($err!="0.0.0.0.0") { $msg="Invalid Entry...Please do not empty any fields"; $_SESSION['HEADER']=$header; $_SESSION['BODY']=$body; $_SESSION['FOOTER']=$footer; header("Location:index.php?Act=email&from=$from&sub=$sub&event=$event&status=$status&msg=$msg&to=$to"); exit; } if($event=="ChooseEvent") { $msg="Please select an Event! "; header("Location:index.php?Act=email&from=$from&sub=$sub&event=$event&status=$status&msg=$msg&to=$to"); exit; } if($from != '[from]') { if(!$partners->is_email($from)) { $msg="From field should be a valid E-mail Id ! "; header("Location:index.php?Act=email&from=$from&sub=$sub&event=$event&status=$status&msg=$msg&to=$to"); exit; } } ////////////// test sending if ($flag=="1") { if(!$partners->is_email($to)) { $msg="Please Enter a valid E-mail Id on Test Field !!"; header("Location:index.php?Act=email&from=$from&sub=$sub&event=$event&status=$status&msg=$msg&to=$to"); exit; } $sql_admin="select * from partners_admin"; $res_admin=mysql_query($sql_admin); $row_admin =mysql_fetch_object($res_admin); //common header and footer $adminheader=stripslashes($row_admin->admin_mailheader); $adminfooter=stripslashes($row_admin->admin_mailfooter); $admin_email = stripslashes($row_admin->admin_email); $today =date("Y-m-d"); /////////// mail sending $headers = "Content-type: text/html; charset=UTF-8\n"; $headers .= "From: $from\n"; $headers =str_replace("[from]",$admin_email,$headers); $body1="

"; $body1.="

 

 

 

"; $body1.="

 

 

"; $body1.="

"; $body1.="

 

 

 

"; $body1.="

 

$adminheader

 

"; $body1.="

 

 

"; $body1.="

 

 

"; $body1.="

 

$header

 

"; $body1.="

 

 

"; $body1.="

 

 

"; $body1.="

 

 

 

"; $body1.="

 

 

"; $body1.="

 

 

"; $body1.="

 

$body"; $body1.="

 

 

"; $body1.="

 

 

"; $body1.="

 

 

 

"; $body1.="

 

 

"; $body1.="

 

 

"; $body1.="

 

$footer

 

"; $body1.="

 

 

"; $body1.="

 

 

"; $body1.="

 

$adminfooter

 

"; $body1.="

 

 

"; $body1.="

"; $body1.="

"; $body1.="

 

 

"; $body1.="

"; //Replace variable in the content with values $body1=str_replace("[aff_firstname]","Affiliate FirstName",$body1); $body1=str_replace("[aff_lastname]","Affiliate LastName",$body1); $body1=str_replace("[aff_company]","Affiliate Company",$body1); $body1=str_replace("[aff_email]","Affiliate Email",$body1); $body1=str_replace("[aff_loginlink]","Affiliate Url",$body1); $body1=str_replace("[aff_password]","Affiliate Password",$body1); $body1=str_replace("[mer_firstname]","Merchant FirstName",$body1); $body1=str_replace("[mer_lastname]","Merchant Lastname",$body1); $body1=str_replace("[mer_company]","Merchant Company",$body1); $body1=str_replace("[mer_email]","Merchant Email",$body1); $body1=str_replace("[mer_loginlink]","Merchant Url",$body1); $body1=str_replace("[mer_password]","Merchnat Password",$body1); $body1=str_replace("[from]",$admin_email,$body1); $body1=str_replace("[commission]","Commission Earned",$body1); $body1=str_replace("[program]","Program Name",$body1); $body1=str_replace("[type]","Transaction type",$body1); $body1=str_replace("[date]","Transaction Date",$body1); $body1=str_replace("[today]",$today,$body1); mail($to,$sub,$body1, $headers); $msg="Mail has been send to ".$to; header("Location:index.php?Act=email&from=$from&sub=$sub&event=$event&status=$status&msg=$msg&to=$to"); exit ; } ////////////// updating table $sql="select * from partners_adminmail WHERE adminmail_eventname='$event'"; $res=mysql_query($sql); if(mysql_num_rows($res)>0) { $sql1="UPDATE partners_adminmail SET adminmail_from ='$from',adminmail_subject='".addslashes($sub)."',adminmail_header='".addslashes($header)."',adminmail_footer='".addslashes($footer)."',adminmail_message='".addslashes($body)."' WHERE adminmail_eventname='$event'"; $sql2="UPDATE partners_event SET event_status ='$status' WHERE event_name='$event'"; $res=mysql_query($sql1) or die ("cant exe"); $res2=mysql_query($sql2) or die ("cant exe 2 nd"); $msg="Message updated "; header("Location:index.php?Act=email&from=$from&sub=$sub&event=$event&status=$status&msg=$msg&to=$to"); } else { $sql1="INSERT INTO partners_adminmail ( adminmail_id , adminmail_eventname , adminmail_from , adminmail_subject , adminmail_message , adminmail_header , adminmail_footer ) VALUES ('', '$event', '$from', '".addslashes($sub)."', '".addslashes($body)."', '".addslashes($header)."', '".addslashes($footer)."')"; $sql2="UPDATE partners_event SET event_status ='$status' WHERE event_name='$event'"; $res=mysql_query($sql1); echo mysql_error(); $res2=mysql_query($sql2) ; echo mysql_error(); $msg="Message updated "; header("Location:index.php?Act=email&from=$from&sub=$sub&event=$event&status=$status&msg=$msg&to=$to"); } ?>

 

 

 

 

 

Link to comment
Share on other sites

<Files "emailvalidate.php">

ForceType 'text/html; charset=UTF-8'

</Files>

 

So, you are forcing the server to serve the PHP file as a HTML static file.  You are getting the desired results that you asked for.  If you want PHP parsed as PHP, then do not force the type to HTML.

Link to comment
Share on other sites

<Files "emailvalidate.php">

ForceType 'text/html; charset=UTF-8'

</Files>

 

So, you are forcing the server to serve the PHP file as a HTML static file.  You are getting the desired results that you asked for.  If you want PHP parsed as PHP, then do not force the type to HTML.

Thanks! but how do I php files on server to use UTF-8?

Why did I change server and the charachters displayed badly?

Link to comment
Share on other sites

you can use the AddCharset directive to set the specified extension to use the specified charset. (e.g)

 

AddCharset UTF-8 .php

 

basically, this will cause all the files with the targeted extension to send a Content-Type: header with the charset as whatever you specify.

 

Note that this will change all of the .php files in all of the subdirectories stemming from the current location.

 

You can also target one file (e.g.)

 

<files "example.php">
AddCharset UTF-8 .php
</files>

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.