0

I am sending same data with PHP cURL. But I am using "\n" character in a text area and it prints "Empty reply from server". Unless I use "\n", it is working.

For example:

<form action="gonder.php" method="post">
<textarea name="content" rows=23 cols=70></textarea>
<input class="button" type="submit" value="Kaydet">
</form>

And my gonder.php file:

<?php

if($_POST['content'] != ""){

$ch = curl_init('http://address/page.php');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'bilgi='.$_POST['content']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch) or die(curl_error($ch));

header("Location: index.php?olay=2");
}

?>

Additional information: My file has single-quotes at the end.

How can I solve this problem?

veriler.txt:

araba
ev
dükkan
mağaza

veriler.txt is in another server and I want to rewrite it with a textarea using post method

2 Answers2

0

curl will encode for you if you pass an array, or you can use urlencode() in your existing code:

$content = array('bilgi' => $_POST['content']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
AbraCadaver
  • 73,820
  • 7
  • 55
  • 81
0

I think that you need to send the text as HTML using this functions nl2br(htmlentities()) :

 curl_setopt($ch, CURLOPT_POSTFIELDS, 'bilgi='.nl2br(htmlentities($_POST['content'])));

as

araba<br>
ev<br>

Then when you receive it extract the text from html code using str_replace( "<br>" , "\n" , $_POST['bilgi']); , And write it into you file veriler.txt

bestyasser
  • 93
  • 1
  • 11
  • sory I wrote wrong here. but I need '\n' because I want to write a file in other server using it – user2980523 Nov 11 '13 at 20:38
  • thanks but it not impact if I write 1 line, it is working but if write multiple lines, it isn't work. My problem is this already. – user2980523 Nov 11 '13 at 20:50
  • Give a small example for your text data. – bestyasser Nov 11 '13 at 21:09
  • I wrote it my main question. veriler.txt is in another server and I want to rewrite it with a textarea using post method – user2980523 Nov 11 '13 at 21:25
  • Yes, I think you need to send the text as HTML using this functions nl2br(htmlentities()) as araba
    ev
    .... Then then when you receive it extract the text and write it into veriler.txt as : araba ev
    – bestyasser Nov 11 '13 at 21:50