PHP - Curl Foreign Language Encoding Problem
Similar TutorialsHi, I'm having following problem when I try to add records in two tables, one (password) has primary key and student has a foreign key contraint with password. Anyone please clarify what Im doing wrong. Thanks ! SQL CODE: INSERT INTO student(id, firstname, surname,dob, class,nationality,houseno,line1,line2,city) VALUES('00010', 'test','test','1980-01-01','test','test','test','test','test','test'); INSERT INTO password (id, password,salt) VALUES('00010','abc','abcde'); ERROR: #1452 - Cannot add or update a child row: a foreign key constraint fails (`chr_fyp/student`, CONSTRAINT `student_ibfk_1` FOREIGN KEY (`id`) REFERENCES `password` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) I have two tables in my MySQL database: 1. user user_id | firstname | lastname | nickname etc. and 2. con (for contribution) con_id | user_id (foreign key) | name | contribution | category etc. Here's how I wanted to solve the problem of assigning the foreign key to the 2nd table (I'm a beginner so bear with me. ) When logging in, I assigned the user_id to the session variable like this: // do the while loop while ($assoc = mysqli_fetch_assoc($rows)) { // assign database COLUMNS to the variables $dbuser_id = $assoc['user_id']; $dbuser_name = $assoc['nickname']; $dbuser_password = $assoc['password']; etc..................... // set a session after login $_SESSION['user'] = $dbuser_name . $dbuser_id; This prints out the user_id just like I wanted to: echo "Your user_id is: " . $_SESSION['user_id'] = $dbuser_id; Gives: Code: [Select] Your user_id is: 35 ... and this is how the assignment of the foreign key looks like WHILE posting the contribution: $user_id = $_SESSION['user'] = $dbuser_id; if (!empty($knuffix_name) && !empty($knuffix_category) && !empty($knuffix_contribution)) { // Write the data into the database $query = sprintf("INSERT INTO con (con_id, user_id, name, contribution, category, contributed_date) VALUES (' ', '$user_id', '%s', '%s', '%s', now())", mysqli_real_escape_string($dbc, $knuffix_name), mysqli_real_escape_string($dbc, $knuffix_contribution), mysqli_real_escape_string($dbc, $knuffix_category)); When I now do a contribution through the input areas, nothing gets inserted into the database and I automatically get logged out. Obviously it's not working as I thought it would and I'd like to know why is that? Notice that if I take the user_id part OUT, it's working again, so the rest of the code must be right then. Another question I have is: Is this common practice to solve this problem of assigning a foreign key, or is there a better way of doing it? Hi, I have few files which i need to display in correct format and also save in db to use. My problem is here is my code: $file = "C:\\file.txt"; $data = file_get_contents($file); $data = '<pre>'; $data .= mb_convert_encoding($file, 'UTF-8', 'ISO-8859-1'); $data .= '</pre>'; echo $data; but when i echo $data i get weird characters . here is result http://paste2.org/p/1361878 Thanks for any help. When you select language I just got an error message Got an error message that says: This problem can sometimes occur if you are disabled or refused to take accept cookies. I have accepted cookies. My code is: language.php <?php if(!isset($_COOKIE['language'])) { if(!isset($_GET['lang'])) { ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>123</title> <style type="text/css"> <!-- body { background-image: url(images/background.jpg); } .style1 { color: #FFFFFF; font-weight: bold; } --> </style></head> <body> <p><br> <br> <br> <br> <br> </p> <div align="center" style="margin-top:400px;"> <table width="200" border="0"> <tr> <td width="114"><div align="left"><a href="language.php?lang=swe"><img src="http://www.clickbuxer.com/images/swe.jpg" border="0" alt="swedish" /></a></div></td> <td width="1" rowspan="2"> </td> <td rowspan="2"><div align="left"></div></td> <td><a href="language.php?lang=usa"><img src="http://www.clickbuxer.com/images/usa.jpg" border="0" alt="usa" /></a></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td><div align="center" class="style1">SWE</div></td> <td> </td> <td width="0"><div align="center"></div></td> <td width="110"><div align="center" class="style1">USA</div></td> </tr> </table> </div> <p align="center"> </p> </body> </html> <?php } else { //Add cookie code $language = $_GET['lang']; setcookie("language", $language, time()+3600);//set to expire in 1 hour, 3600=seconds switch($language) { case usa: $redirect = "http://www.clickbuxer.com"; break; case swe: $redirect = "http://www.clickbuxer.com/sv/index.php"; break; default: $redirect = "http://www.clickbuxer.com"; } header("Location: $redirect"); } } else { //If cookie is already set $language = $_COOKIE['language']; switch($language) { case usa: $redirect = "http://www.clickbuxer.com"; break; case swe: $redirect = "http://www.clickbuxer.com/sv/index.php"; break; default: $redirect = "http://www.clickbuxer.com"; } header("Location: $redirect"); } ?> index.php <?php if(!isset($_COOKIE['language'])) { header("Location: http://www.clickbuxer.com/language.php"); } else { $language = $_COOKIE['language']; switch($language) { case usa: $redirect = "http://www.clickbuxer.com"; break; case swe: $redirect = "http://www.clickbuxer.com/sv/index.php"; break; default: $redirect = "http://www.clickbuxer.com"; } header("Location: $redirect"); } ?> Hi, Using arabic characters, I have a project, in the admin panel, where i am trying to change the value in the text box(ajax) on onblur js function. Firefox simply working great but i am getting square brackets in the text box in the browser ie. I simply guessing the value from the text box is not in the form of utf-8 encoding, i am calling the external javascript file, this is the code am using.. Code: [Select] // JavaScript Document var xmlhttp; //function namechange(name_fieldvalue) function namechange(name_fieldvalue,name_fieldname,id_val,id_fieldname,table_name) { /* alert(name_fieldvalue); alert(name_fieldname); alert(id_val); alert(id_fieldname); alert(table_name); */ if (name_fieldvalue.length==0) { document.getElementById("txtHint").innerHTML=""; return; } xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support XMLHTTP!"); return; } var url="ajax_namechange.php"; url=url+"?name_fieldvalue="+name_fieldvalue; url=url+"&name_fieldname="+name_fieldname; url=url+"&id_val="+id_val; url=url+"&id_fieldname="+id_fieldname; url=url+"&table_name="+table_name; xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } Anyone has the idea on this, please help me. Thanks, Hello masters. I wish to share with you a problem that is killing me in this dais!! I have a website in xhtml, with some php form. This website is made for Japanese customers (all in Japanese) and that's the big trouble. The language encoding of the php form is really killing me. I tried several solutions, but I couldn't sort this problem. So I was wondering if you guis could help me... This is how it should work: customers fill up the form in Japanese. The php script send the deta to my mail address and to the customer one. Simply and plan. No image, just text ... easy. I tested it on my Japanese computer and it works great: I recive the mail, the customer recive the mail and all the field are ok and I can read all the Japanese charachters. The big troubles come out when I try to fill up the form with a Japanese mobile device: Both the customer and me recive a mail with weird characters. something like this: ..????i???.... and so on....damn, I can't understand why. The most weird thing is that it really works great on computer browser. But as this is a website for mobile devices I have no choice but to settle this. Here is part of the code I use for the form: <?php // I set the page encoding to EUC-JP and set the Japanese language mb_language("ja"); mb_internal_encoding("EUC-JP"); // Declare $ $EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); $EmailTo = "orders@mobile-body-ex.com"; $Subject = "Body-ex Cellphone Order"; $Nome = Trim(stripslashes($_POST['Nome'])); $Cognome = Trim(stripslashes($_POST['Cognome'])); $Postal = Trim(stripslashes($_POST['Postal'])); $Address = Trim(stripslashes($_POST['Address'])); $Number = Trim(stripslashes($_POST['Number'])); .... // validation $validationOK=true; if (Trim($EmailFrom)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.xhtml\">"; exit; } // prepare email body text $Body = "モバイルサイトから注文受けました: Angel スリーラウンドペンダント AD-0011 Booking Form;"; $Body .= "名前: "; $Body .= $Nome; $Body .= "\n"; $Body .= "名前(フリガナ): "; $Body .= $Cognome; $Body .= "\n"; $Body .= "郵便番号: "; $Body .= $Postal; $Body .= "\n"; $Body .= "住所: "; ..... // send email $success = mb_send_mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); .....Follow the second mail directed to the customer email address. ps: モバ are Japanese characters... Both the html page with the form and the php page are set to EUC-JP (charset="euc-jp"). What should I do to make this work properly? I repeat that it actually works on the net if you use a computer browser (try to see at http://www.mobile-body-ex.com/ora1.html). But I couldn't find a way to make it works if you fill up the form trough a browser for mobile devices (Japanese). ......please, give me some hint Thank you everybody! I am helping a friend to fix their website and I dont have too much experience with php. I have noticed a problem with the language on one of the pages http://www.fincalavicaria.com/alameda.php When the page loads the Servicios shows in Spanish, which is correct however, if you click on the Servicios link it changes to the English version in the Spanish vesrion. This should only be available after you have changed the language for the site to english at the top As I dont have too much experience I would be grateful if someone could tell me what would be causing this to happen. It should be something very easy to fix but no matter what I try I can't find the problem. Thank you. Hello everybody, Hope somebody can help. As the subject says, I'm having encoding problems in my includes files, the "accents" and some special characters don't work. However, they do work in my main HTML. I really don't know what the problem is and how to fix it. Thanks in advance. I submit text to my MySQL database using a form on my site. When I look at the text in my database, sometimes, there are strange characters. The strange characters are caused by quotation marks, em dashes, apostrophes and foreign letters of the alphabet. I think that this only happens when the source of the text is a Windows program. I understand that this is a character encoding issue, but I don't fully understand the subject. I've spent the last few hours researching it, but it's only confused me.
My site uses UTF-8 encoding:
<meta http-equiv="content-type" content="text/xml; charset=utf-8" />The collation of my database is utf8_general_ci. My form looks like this: <form action="" method="post"> </form>As you can see, an accept-charset="utf-8" attribute has not been specified. Questions 1) I am guessing that my problem is that the Windows characters are being misinterpreted by my UTF-8 setup. Is that correct? 2) If so, is there a way that I can safely convert the Windows characters to UTF-8 during the submission process? 3) Should I also specify an accept-charset="utf-8" attribute on the form? 4) When I paste the Windows text directly into my database without using the form, the characters save without turning into the strange characters. But they don't render properly on my site. Can't browsers identify Windows characters? Hello everyone For a multilingual website we have to be able to open 1 page in 4 different languages. For example, product 'A' is in Dutch, English, French and German. How can I open the right language file? At the moment I use Code: [Select] http://www.zinncosmetics.nl/shop/product_info.php?products_id=36?language=de but it doesn't work. It allways opens the default Dutch pages. What do I do wrong? I don't have very much php experience (newbie) so please don't make it too difficult for me. Thanks for all help! I'm trying to submit to my site using this script that I made: <?php session_start(); $title = "<title>CS</title>"; $url = "http://cheatskape.com/wtag/sendchat.php"; $token = md5(uniqid(rand(), true)); $_SESSION['token'] = $token; $ch = curl_init(); //Initalize a new cURL session $name = "PROBLEM"; $msg = "LOL"; $postfields = "token=".$token."&name=".$name."&url=&message=".$msg.""; echo $title; //set the title of the window curl_setopt($ch, CURLOPT_POST, 1); //set the type, curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); //and what fields to use curl_setopt($ch, CURLOPT_URL, $url);//Set the URL to use curl_exec($ch); //execute it echo "<br /><br /><br />"; print_r(curl_getinfo($ch)); //Print info of the cURL execution curl_close($ch); //Close our current cURL session ?> However, it refuses to post.. What am I doing wrong? This is my first time using cURL the curl info shows me this: Quote Array ( [url] => http://cheatskape.com/wtag/sendchat.php [content_type] => text/xml; charset=UTF-8 [http_code] => 200 [header_size] => 439 [request_size] => 208 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.39 [namelookup_time] => 0 [connect_time] => 0.188 [pretransfer_time] => 0.188 [size_upload] => 68 [size_download] => 2039 [speed_download] => 5228 [speed_upload] => 174 [download_content_length] => 2039 [upload_content_length] => 0 [starttransfer_time] => 0.39 [redirect_time] => 0 [certinfo] => Array ( ) ) Hello, hello i need use curl with proxy. but i get "undefined variable offset 1" error . here is the standart code i use. please help me about it thanks curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_PROXY, $proxy); curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt($ch, CURLOPT_REFERER, $referer); curl_setopt($ch, CURLOPT_USERAGENT, $agent); Hi,
I'd stumbled upon a problem around doing curl on an asp website which use cookie.
I use username n session id to determine the cookie file, on a case when a second browser open up it should have different session id, hence it may create new cookies instead of using the active previously-made cookie file, please do correct me if I'm wrong.
So question is....how to detect a user is logged or not in such situation ?
Or perhaps how is the proper way to determine a cookie file in such situation ?
Thanks in advance,
Hi I made a curl and don't know what to do with the string I got back, I would need the id and the name of each, should I explode, don't know how to do that, here is what I got as answer: Quote string(596) "{"data":[{"name":"Esoterik Forum","category":"Community","id":"180883525283576"},{"name":"Hellsehen und Wahrsagen","category":"Company","id":"177967172214131"},{"name":"Spirituelle Lebensberatung","category":"Website","id":"164411270264299"},{"name":"Esoterik","category":"Website","id":"164524456919432"},{"name":"Kartenlegen und Hellsehen","category":"Company","id":"173933135951523"},{"name":"Exchange","category":"Application","id":"190533567633445"},{"name":"Astrologie","category":"Website","id":"164928140213920"},{"name":"Esoterik Forum","category":"Application","id":"184577371575355"}]}" Hey guys, I have developed an script which opens or fetches a page using curl, now the problem is the url i am trying to fetch follows lot of redirects(say 302) and in between it stores several cookies also which i don't know or guess. So i was just thinking, is there any way so that i can automatically store the cookies in a particular file which server wants to store, and let it sent in request as per the asking of a request in request header? I hope you would have got what i mean to say here, for example suppose i want to open http://www.example.com and now that above url faces lot of redirects probably 5-6 and then ends up on http://www.test.com now in between it stores some cookies in clients computer and then it fetches them also. Since i don't know which cookie it gonna store, I must put this responsibility to PHP itself to store and send the requested cookies in request headers. Also i want to send the referrer also in request header, and it must be the last page that or request sent to the server, no matter whether it's in betwen redirects or to the final page. In short i mean to create the complete emulation of browser for this URL. |