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

  • Home
  • SEARCH
  • 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 8864427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:14:18+00:00 2026-06-14T16:14:18+00:00

I have an array on view $all_set which contain some ids.now i want to

  • 0

I have an array on view $all_set which contain some ids.now i want to pass this array in controller using form submit.for that i used the j son encode and decode.

on my view:

<?php $all_set=json_encode($all_set); ?>

<input type="hidden" name="all_set" value="<?php echo serialize($all_set); ?>">

the above value contains(as i saw in page source):

<input type="hidden" name="all_set" value="s:26:"{"0":"1","5":"2","13":"3"}";">

Now on controller:

$result=$this->input->post('all_set');

           $result= unserialize($result);
           $result=json_decode($result);
           print_r($result); die;

This gives me error and i am not getting any array on controller.
Error:

Message: unserialize() [function.unserialize]: Error at offset 0 of 5 bytes

Why is this so? please Help.

  • 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-14T16:14:20+00:00Added an answer on June 14, 2026 at 4:14 pm

    You have to add htmlspecialchars() to your serialize.

    <input type="hidden" name="all_set" value="<?php echo htmlspecialchars(serialize($all_set)); ?>">
    

    EDIT

    Why this solves the problem? Let’s see the OP’s quoted output first:

    value="s:26:"{"0":"1","5":"2","13":"3"}";">
          ^     ^
    

    I added ^ to mark the problem source – your value included quotation marks, which made browser see this input more less like this:

    value="s:26:" {"0" "1" , "5" : "2","13":"3"}";">
    

    It simply closed the string once it found matching ". There’re are special characters in HTML, including <, >, &, " which have to be converted to entities if they are expected to be passed literaly. So by calling htmlspecialchars() we convert all these characters and the markup would look like this:

    value="s:26:&quot;{&quot;0&quot;:&quot;1&quot;,&quot;5&quot;.....
    

    Browser interprets it now correctly, displays correctly and sends back correctly but to not treat it as part of markup.

    EDIT 2

    In fact unserialize is quite uselss in your code. Get rid of serialize()/unserialize() completetly – your json encoded data is just pure string, so you need only htmlspecialchars().

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

Sidebar

Related Questions

I have a Form element: $Form=new Zend_Form; $Form->setAction($this->view->url(array('controller'=>'auth','action'=>'create'),null,true)) ->setMethod('post') ->setAttrib('id','auth-form') ->removeAttrib('enctype'); As can be
I have a plist (array of dictionaries) which populates a table view and works
I have this code in my view: echo form_label('State', 'state'); $options = array( 'No
I need to display array of images in a single view which have various
I have a url http:// * .com/branch/module/view/id/1/cat/2/etc/3. It becomes. array ( 'module'=>'branch', 'controller'=>'module', 'action'=>'view'
In a view, I get an array of objects. I want to have a
I have a master detail Application in xCode. In Master View Controller an Array
i have an string data array which contains data like this 5~kiran 2~ram 1~arun
I have a MySQL table set up using phpMyAdmin which you can view in
I have a view which is a big table. This table is populated from

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.