1

I am getting "Notice: unserialize(): Error at offset 0 of 1081 bytes" error while unserializing curl response.

Curl request page - ping1.php :

<?php
$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "http://example.com/test/curl/ping2.php",
    CURLOPT_POST           => true,
    CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
echo unserialize($result);
?>

Curl response page - ping2.php

<?php
$data=array('test'=>1,'testing'=>2);
echo serialize($data);
?>
4
  • Well, what does $result contain? Commented Jul 16, 2013 at 7:14
  • Well, can you show what it contains? Because that's where the problem is. That's what the error message is about. Commented Jul 16, 2013 at 7:19
  • Put var_dump($result) in ping1.php and show the output. Commented Jul 16, 2013 at 7:20
  • var_dump($result) : i.imgur.com/4Mk5fpG.png Commented Jul 16, 2013 at 7:30

2 Answers 2

1

Got your issue .

ERROR

When I ran your code and saw the result I got

string '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>413 Request Entity Too Large</title>
</head><body>
<h1>Request Entity Too Large</h1>
The requested resource<br />/experimentation/Stack/stack.php<br />
does not allow request data with POST requests, or the amount of data provided in
the request exceeds the capacity limit.
<hr>
<address>Apache/2.2.22 (Fedora) Server at localhost Port 80</address>
</body></html>
a:2:{s:4:"test";i:1;s:7:"testing";i:2;}' (length=474)

WHY AM I GETTING THIS ERROR?

You are getting this error beacause you are using CURLOPT_POST but not sending any post data . Rather than explaining it here I will refer you to this post which is base of your issue.

RESOLUTION

CURLOPT_POST is not required since we are not posting any data .

Here is your working code

<?php

$ch = curl_init();
$curlConfig = array(
    CURLOPT_URL            => "http://example.com/test/curl/ping2.php",
    CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
print_r(unserialize($result)) ;

?>
Sign up to request clarification or add additional context in comments.

Comments

0

the $result variable contains an error message, so it can't be unserialized

also, be careful with closing tags in ping2.php as it may include extra unwanted spaces

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.