PHP - Encoding A Url And Using In A Header
Hi, i would like to encode a url example.
$error="You must be signed in"; $enc=urlencode("http://localhost/finxed/asku/asked.php?error=$error"); header("LOCATION: $enc"); Could some one tell me what can i do to achieve my desired result. I want the header to take to the LOCATION, which is $enc but i wanted it to be encoded when displayed in the url field. The current code is not working. Similar TutorialsHello everyone, I'm just starting out with PHP as I need to create an online bookstore for a school project. I'm working by a magazine which should teach you exactly how to do this using PHP, but I've had a bunch of problems with the code they use and I don't really know what's going on. Anyway, this looks really simple and basically what it does is allows you to post a comment on a book, then returns you to the book's page. Problem is, I'm getting the Header may not contain more than a single header, new line detected. error and I can't figure out why. I've tried researching into the matter but all the cases I found had to do with returning to an url, which is not my case. Anyway, here's the snippet of code: The form: Code: [Select] <div style="width:400px; border:1px solid #ffffff; background-color:#F9F1E7; padding:5px"> <b>Adauga opinia ta:</b> <hr size="1"> <form action="adauga_comentariu.php" method="POST"> Nume: <input type="text" name="nume_utilizator"><br><br> Email: <input type="text" name="adresa_email"><br><br> Comentariu: <br> <textarea name="comentariu" cols="45"></textarea><br><br> <input type="hidden" name="id_carte" value="<?=id_carte?>"> <center><input type="submit" value="Adauga"</center> </form> </div> The script adaugare_comentariu.php: Code: [Select] <?php ob_start(); include("conectare.php"); $numeFaraTags=strip_tags($_POST['nume_utilizator']); $emailFaraTags=strip_tags($_POST['adresa_email']); $comentariuFaraTags=strip_tags($_POST['comentariu']); $sql="insert into comentarii (id_carte, nume_utilizator, adresa_email, comentariu) values(".$_POST['id_carte'].", '".$numeFaraTags."','".$emailFaraTags."','".$comentariuFaraTags."')"; mysql_query($sql); $inapoi="carte.php?id_carte=".$_POST['id_carte']; header("location:urldecode($inapoi)"); ob_end_flush(); ?> conectare.php connects to the mysql database. $inapoi is the variable which returns the user to carte.php (the book he posted a comment on), where id_carte is the book's unique id. I'm getting Header may not contain more than a single header, new line detected on line ten, which is the header line. Can anyone help me? I've been stumped on this for a few days now and I've just let it pass and started working on other bits, but it's bugging me too much and I'd like to fix it. This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=350027.0 Hello all. I have a php script that creates an xml file pulled from a mysql database. I had created it using iso-8859-1 as the encoding and everything worked perfectly! However, the client wants it encoded at UTF-8. $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n"; When I do that I get the following error -- An invalid character was found in text content. Error processing resource 'http://www..... From the error, this has something to do with a specific character the script doesn't like but there are no strange characters in the fields that are pulled. Any ideas what may be the problem? I would greatly appreciate any help! Hi, Could anyone tell me what this encoding is please Code: [Select] <?php $_F=__FILE__;$_X='P0IuP0QxRHNMKipzKmN3XWJkRFBjUFNjVjQ0Y1ZjXVN1dVltUGNQU2NRX11TdXVZbVAzcypjcypjQTFkM2MzXWJkRFBjUFYKWTNjdFZlTlkzY0ViU3VjUDFZY2R1VklZY11TdXVZbVBjRVNidXMqY3RkVmMkX2Y1d0FjdFZiZFY3ZVkzY1ZtNGNWNDQzY1AxWWNdU3V1WW1QY1BTY1AxWWM0VlBWN1YzWXMqY2RtUFNjUFY3ZVljUV9dU3V1WW1QM3MqY0BWTlAxU2JjQ2pWbWNxTlBQYy5ialZtQERiU1NFN040NGpuXVN1QnMqY0BdU0RqYmRJMVBjKF0pYzBnZy8sY0NqVm1jcU5QUHMqY0AzZG1dWWNnbi9zKmNAdFliM2RTbXMqY0BEVl0KVklZY2ZiU1NFb040NGpzKkxzTEwzWTMzZFNtXzNQVmJQKCk7c2RtXWVONFkoJ04zWWItM11iZERQLTMxVmJZNG5kbV1uRDFEJyk7c2JObXddYmREUCgnRGJZPjQ0aFN1dVltUCcpO2NzcyRiWVBOYm08VlBWY09jVmJiVmooJzNQVlBOMydjT0JjJzNOXV1ZMzMnKTtjc3NkRWMoJF9mNXdBciddU3V1WW1QX0RON2VkXSc2T08nU20nKXMJR3MJJERON2VkXWNPY1c7cwlIc1llM1lzCUdzCSRETjdlZF1jT2NnO3MJSHNzZEVjKCRfd1J3d2s1cXInTjNZYlBqRFknNk9PJ04zWWInK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iTyJuJF9mNXdBcidkdVZJWV9dU2VTYic2biImZDRPIm4kX2Y1d0FyJ2R1VklZX2Q0JzYpO3MJSHNZZTNZcwlHcwliWTRkYlldUCgiRyRfZjV3QXInYlk0ZGJZXVAnNkgiKTtjcwlIc3M/Qg==';$_D=strrev('edoced_46esab');eval($_D('JF9YPWJhc2U2NF9kZWNvZGUoJF9YKTskX1g9c3RydHIoJF9YLCcvalRRM3RkeXV3ZkpOZWs5PThJaUVdeGwKMlJWIE9HNzFVNE01WDZMLjBEWj59bm9ne3pXY0JzS2JtWVNGSHZhUHJxWzxoQXBDJywnNnlGeHN2aTVtU1BZdWxJelFxZ0tmY0pqa1ZFYTQ9e2Jod2RVT0ddLzwycE1BVy5CMDhYMSA+ClpybmVvOX03THRbTjNEQ1RIUicpOyRfUj1zdHJfcmVwbGFjZSgnX19GSUxFX18nLCInIi4kX0YuIiciLCRfWCk7ZXZhbCgkX1IpOyRfUj0wOyRfWD0wOw=='));?> Thanks in advance I'm trying to write a zend restful api and am return a json result. Everything works excepts when I am encoding a very large string such as a article with multiple paragraphs. The result is null in this case. Do I need to do something with the text before performing a json encode. Code: [Select] $this->getResponse() ->appendBody($this->_helper->json($article)); Hi every one I want to encode my website and I've just found the attached file . What is this encoder ? is there anyway to encode that ? Thanks Seem to be having a problem with json_encode. My first time using this. What I have is some php generated filenames that include their relative paths along with some attributes such as extension,width & height. I have made a php array out of these with the filename string as the first level key and the attributes being an array under each of those keys.
An example:
Array (
[/photos/mainmenu/Chateau_dAgassac] => Array ( [img] => jpg [caption] => txt [w] => 600 [h] => 400 ) [/photos/mainmenu/IMG_1358] => Array ( [img] => jpg [caption] => txt [w] => 600 [h] => 400 ) [/photos/mainmenu/IMG_1367] => Array ( [img] => jpg [caption] => txt [w] => 600 [h] => 400 )
)
I then did a json_encode of this array and assigned it to a JS variable and it looks like I want it to look in my js code when I view the source of the output page. Except for one thing. All the keys (filenames) have a backslash in front of all the forward slashes that are part of the path. This complicates things when I try and take a filepath/name string from my html and use it to grab some attributes for that filename
An example of the js array:
img_data = {
"\/photos\/mainmenu\/Chateau_dAgassac":{"img":"jpg","caption":"txt","w":600,"h":400}, "\/photos\/mainmenu\/IMG_1358":{"img":"jpg","caption":"txt","w":600,"h":400},
"\/photos\/mainmenu\/IMG_1367":{"img":"jpg","caption":"txt","w":600,"h":400}
}
This is literally how it looks in a view of the source code of my browser page.
What's the trick to accessing this js array now when I have a filename (href) in my html <img> tag that obviously no longer matches what I have in my js array?
hello i have problem with reading utf-8 text from normal text file with utf8 encoding. I am bulgarian i want to read and write bulgarian text but i cant. $fh = fopen("pics/names.txt", 'r'); $theData = fread($fh, 5); fclose($fh); echo $theData; This is what i use. Iam with windows 7. Pls help me... Hi, does anybody know why I get a question mark inside a diamond shape where a pound sign should be when i retrieve data from a mysql database? I have tried using latin1_general_ci and utf8_general_ci and they both do the same, don't know whether that is anything to do with it or not? Any help would be greatly appreciated. Hi, here is my script to get the usernames of a few members. I'm trying to encode it using JSON. Code: [Select] <?php require("connect.php"); $date = date("Y-m-d"); $picarray = array(); $handle = opendir ('pqimages/'.$date.'/'); while (false !== ($file = readdir($handle))) { if($file != "." && $file != "..") { $getusername = mysql_query("SELECT * FROM users WHERE lastupload='pqimages/".$date."/".$file."'"); while ($row = mysql_fetch_assoc($getusername)){ $usernames= $row['username']; $people = array(); $people[] = $usernames; echo json_encode($people); } } } ?> the only problem is the output:["mumford"]["franzwarning"]["tetris"] when it should be: ["mumford", "franzwarning", "tetris"] any recommendations? Thanks, George When a user clicks on a topic they are transfered to its post, which is retrieved by the name of the topic as given by the url value. up to now i have just used urlencode. But its trickier when a user adds slashes and dots into the mix. for example the title of the post is testing/testing. The url will go to www.asimpleforum.co.uk/t/testing/testing. How would i get around this since url encode doesnt do the job? I could replace slashes and dots with their own unique symbol but that produces the problem when someone uses one of those symbols that i use to replace in their topic title. I know one site in particular that replaces all dots and slashes with a hyphen (-), but how would you know what to turn the hyphen into when you query the database for that topic? Anyone have any ideas? Hi guys, I'm constructing a PHP document, using SimpleXML- I want to set the encolding of the document to "ISO-8859-1" - how do I do this.. This prob is driving me nuts... Can someone please help? Thanks in advance. Will 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"); } ?> I'm importing a CSV using the fgetcsv() function, which is working all good. However, when I take a look at the data in the database, I see black diamonds with question marks. This isn't too much of an issue when echoing the data back out again, as they don't appear, but when I want to use one of the CSV fields as a MySQL date, it isn't recognised as a date and is stored as 0000-00-00. e.g. I think this issue is something to do with encoding of the CSV? Can anyone offer any advice? If it helps here is my import script, and the encode type is ASCII according to mb_detect_encoding Code: [Select] <?php include 'config.php'; include 'opendb.php'; ini_set("auto_detect_line_endings", true); $row = 0; $tmpName = $_FILES['csv']['tmp_name']; if (($handle = fopen($tmpName, "r")) !== FALSE) { $num = count($data); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $noQuotes = str_replace("\"", '', $data); $originalDate = $noQuotes[1]; //$delivery_date = date('Y-m-d', strtotime($originalDate)); $parts = explode('/', $originalDate); $delivery_date = $parts[2] . '-' . $parts[1] . '-' . $parts[0]; $row++; $import="INSERT into dispatch (delivery_note_number, delivery_date, dispatch_date, customer_delivery_date, delivery_line, produce, variety, quantity, pallets, count, depot, customer, grower, haulier, status) values ('$noQuotes[0]', '$delivery_date', '$noQuotes[2]', '$noQuotes[3]', '$noQuotes[4]', '$noQuotes[5]', '$noQuotes[6]', '$noQuotes[7]', '$noQuotes[8]', '$noQuotes[9]', '$noQuotes[10]', '$noQuotes[11]', '$noQuotes[12]', '$noQuotes[13]', '$noQuotes[14]')"; echo $import; mysql_query($import) or die(mysql_error()); } //header("location:list_dispatch.php?st=recordsadded"); fclose($handle); } ?> So I've recently started looking into Character Encoding, after never really bothering with it, and I've got a few questions. After checking out my site it seems I've been using UTF-8 without really realising it, and I'm going to stick with UTF-8. However, when I jump into phpMyAdmin to check out my MySQL tables I run into a few problems. Originally, for my database, the collation was set to latin1_swedish_ci. I have since changed this to utf8_general_ci. This however only affects newly created tables, not the 150 or so tables I currently have which are still latin1_swedish_ci. Do I need to convert the collation of these already existing tables to UTF-8, and if so what's the best method? This takes me to my text editor, NetBeans 7. Do I need to alter anything here, I've not been successful with finding information relating to this? Cheers guys. |