Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9008537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:57:47+00:00 2026-06-16T01:57:47+00:00

I use json_decode in my PHP to parse data from POST (the POST itself

  • 0

I use json_decode in my PHP to parse data from POST (the POST itself is executed via ajax). My code looks like this:

$data = json_decode($_POST['logdata'], true);
if(!$data) {
    $ecodes = array(
    JSON_ERROR_NONE           => "No error has occurred",
    JSON_ERROR_DEPTH          => "The maximum stack depth has been exceeded",
    JSON_ERROR_STATE_MISMATCH => "Invalid or malformed JSON",
    JSON_ERROR_CTRL_CHAR      => "Control character error, possibly incorrectly encoded",
    JSON_ERROR_SYNTAX         => "Syntax error",
    JSON_ERROR_UTF8           => "Malformed UTF-8 characters, possibly incorrectly encoded"
    );
    $err = json_last_error();
    $result = array("error" => 1, "error_msg" => "Invalid log data: " . $ecodes[json_last_error()]);
    echo json_encode($result);
    exit;
}

...  //use $data array

This code works fine. When executed on my local linux machine or my mac, the passed data is decoded correctly and everything works fine. However when the same code is executed on godaddy shared hosting, the decoding fails with Syntax error. Having spent a lot of time trying to narrow down the problem, I found out that the problem occurs when I have < or > characters in the values of JSON object properties.

The uploading part (ajax) in javascript looks like this:

$.ajax({
    url:        '/emaillog.php',
    type:       'POST',
    dataType:   'json',
    data:       { logdata: JSON.stringify(this.logData[this.scenarioLogId]) },
    cache:      false,
    error:      function(jqXHR, textStatus, errorThrown) {
        alert("Error occurred during upload: " + textStatus);
    },
    success:    function(data, textStatus, jqXHR) {
        var msg = data.error
                  ? "An error occurred processing action log: " + data.error_msg
                  : "Action log processed successfully.";
        alert(msg);
    }
})

As you can see, the value of the POST parameter is created using JSON.stringify and is correct on inspection (both client and server side). If it matters, here’s an example value of the submitted POST parameters:

{
    "scenarioId":"1",
    "scenarioName":"MOH",
    "startTime":1355496349,
    "log":[
        {
         "role":"Leader",
         "task":"MOH",
         "response":"start",
         "time":1355496349
        },
        {
         "role":"Head",
         "task":"<span class=\"bold\">Assign Role</span>",
         "response":"done",
         "time":1355496351
        }
    ]
}

If the last element in the array (with task Assign Role) is removed, then everything is processed successfully. If I replace < and >> characters with spaces, again, everything is fine.

Two questions arise from this:

  1. If syntax error on such a JSON string is the correct behaviour, then why do I not see the error in the other two environments? Also, why is JSON.stringify then producing an incorrect string?

  2. If syntax error on such a JSON string is an incorrect behaviour, then something must be wrong with godaddy’s PHP implementation or configuration.

Note that, while I explicitly asked about godaddy, it’s only relevant as insofar it’s the only provider where the code produces an error. Anybody can shed some light on this situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:57:48+00:00Added an answer on June 16, 2026 at 1:57 am

    For whatever reason, on godaddy hosting only (maybe in some other places too, but not in other places I tested), when I was submitting the form, the server was escaping quotes – and that’s what was causing the issue. The solution to the problem was quite simple: instead of doing

    $data = json_decode($_POST['logdata'], true);
    

    I did

    $data = json_decode(stripslashes($_POST['logdata']), true);
    

    and everything worked perfectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My string like this: { key: value’s, key2: value } I use json_decode() PHP
I want use php curl with oauth to get the JSON data from twitter
I would like to parse one newest feed from one page by PHP. As
I'm writing a PHP application which uses AJAX to submit forms via POST when
json_decode function is not part of PHP 5.1, so I cannot use it. Is
I use JSON.NET and I would like to parse the following object which I
I use json-rpc client from json-rpc.net in my windows phone application. Code: var client
Ok i need to use json on my iOS application to send/receive data to/from
I am converting a javascript/php/ajax application to use jQuery to ensure compatibility with browsers
I've got PHP5.2 currently. I ultimately want to use json_decode , to parse the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.