Write objects to json file? - php

I have a problem: I need to write some objects that are in json format in a file, but in such a way that it would eventually result a valid json. Now it would be simple to make an array with them and then encode them, but the problem is that I get each element in a different .php page when some event is dispatched, and I need to pass them all to a single valid json.
Does anyone have any idea how would this be done?
Edit:
What I have is a Facebook app and I get user data and write it to a json file, however for most of the user's data, I need to request permissions. Also, each of the .php pages is for one type of data (one for groups, one for posting photos etc) and the user can choose what data he/she wants to be written in the json. It's not a good idea to ask for all permissions when entering the app, because users are likely to cancel entering apps that request many permissions. Instead, each time the user chooses to add some more data to the json, I will ask for the perms for that type of data.
At the end, when the user clicks a button I will write all the data to the json. I write everything with json_encode
Edit2: An approach I've been thinking of is to write all the data to the json, open it for reading, change all ][ to , and write back to the json. However, that might be an inefficient approach, since my file will be on a cloud, and opening and closing the file might cost some time

You need to provide more Information here, because the answer may change based on ether you'r using regular PHP or OOP PHP.
In the second case(OOP PHP) you can make a global array and fill it with the correct elements and when (in your code) you reach a complete object you can write your file.
In the first case(regular PHP) I think you can use a hidden input and post the variables from a page to the other...
Any way an example code would give more information on what you want to achieve here so the proper help could be provided.
Hope this help.

Related

How can I code a PHP file upload specificly for json files that is secure and wont allow Php or html to be uploaded

I am working on a site that allows models to be uploaded.
the models are json format like this :
{"meta":{"format_version":"3.0","model_format":"bedrock_old","box_uv":true},"name":"crocodile","geo_name":"crocodile","resolution":{"width":128,"height":128},"elements":[{"name":"body","from":[-4.5,3,-11],"to":[4.5,12,9],"autouv":0,"color":0,"origin":[0,0,0],"uuid":"dc9860c3-1826-d5a0-5475-140558d9bcbd"},{"name":"head","from":[-4,3.5,-13],"to":[4,11.5,-11],"autouv":0,"color":1,"origin":[0,0,0],"uv_offset":[44,45],"uuid":"64585c76-5a21-4d25-e334-afdc62e32bec"},{"name":"jawtop","from":[-4,7,-19],"to":[4,11,-13],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[60,29],"uuid":"08ff348f-2450-1885-c0f6-1754cd0361e0"},{"name":"jawtop","from":[-3,7,-25],"to":[3,10,-19],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[0,45],"uuid":"ce05463f-09fe-45c3-f038-016152a1d962"},{"name":"jawtop","from":[-2,7,-29],"to":[2,9,-25],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[22,55],"uuid":"68004a0b-3d5e-1628-bc01-f97fc31d7add"},{"name":"jawtop","from":[-3,11,-17],"to":[-1,12,-14],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[0,71],"uuid":"1f51dc8c-bce3-f6b1-e3ce-b8bd95cfb0b6"},{"name":"jawtop","from":[1,11,-17],"to":[3,12,-14],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[10,71],"uuid":"a5e2642b-891a-8531-068a-f58f6773086d"},{"name":"jawbottom","from":[-3.5,4,-24],"to":[3.5,7,-13],"autouv":0,"color":3,"origin":[0,0,0],"uv_offset":[58,0],"uuid":"ad1c59ee-6f3f-07ef-fcdc-190444c48dc7"},{"name":"jawbottom","from":[-2.5,5,-30],"to":[2.5,7,-24],"autouv":0,"color":3,"origin":[0,0,0],"uv_offset":[0,55],"uuid":"750a2256-945c-2ea9-b2a3-eaf1af4b55ec"},{"name":"leg0","from":[3.5,2,5],"to":[5.5,7,8],"autouv":0,"color":4,"origin":[0,0,0],"uv_offset":[20,63],"uuid":"80425fb4-9022-e3f0-369c-4327b745fb92"},{"name":"leg0bot","from":[3.5,-1,6],"to":[5.5,3,8],"autouv":0,"color":5,"origin":[0,0,0],"uv_offset":[28,71],"uuid":"6afca6bb-c3b1-3284-1c00-ef2028a079aa"},{"name":"leg1","from":[-5.5,2,5],"to":[-3.5,7,8],"autouv":0,"color":6,"origin":[0,0,0],"uv_offset":[52,55],"uuid":"a7c6896b-f5af-9216-3cd7-0ad96fe57966"},{"name":"leg1bot","from":[-5.5,-1,6],"to":[-3.5,3,8],"autouv":0,"color":7,"origin":[0,0,0],"uv_offset":[20,71],"uuid":"675b7a00-486a-568b-9c51-09cef03b2abd"},{"name":"leg2","from":[3.5,2,-9],"to":[5.5,7,-6],"autouv":0,"color":0,"origin":[0,0,0],"uv_offset":[0,63],"uuid":"59aeddb8-d40b-8894-466c-ce509b62ef2f"},{"name":"leg2bot","from":[3.5,-2,-8],"to":[5.5,2,-6],"autouv":0,"color":1,"origin":[0,0,0],"uv_offset":[48,63],"uuid":"240ac047-9697-f70d-88af-2c948ef0a1a2"},{"name":"leg3","from":[-5.5,2,-9],"to":[-3.5,7,-6],"autouv":0,"color":2,"origin":[0,0,0],"uv_offset":[10,63],"uuid":"269587ec-ed0a-74b0-0aac-d1e3f4b757db"},{"name":"leg3bot","from":[-5.5,-2,-8],"to":[-3.5,2,-6],"autouv":0,"color":3,"origin":[0,0,0],"uv_offset":[40,63],"uuid":"97f9b166-f557-ac6b-853e-74e476343c85"},{"name":"tail0","from":[-3.5,4,9],"to":[3.5,11,18],"autouv":0,"color":4,"origin":[0,0,0],"uv_offset":[0,29],"uuid":"eee0a07c-244b-e299-cdbb-f4722dd1d4b8"},{"name":"tail1","from":[-2.5,5,18],"to":[2.5,10,27],"autouv":0,"color":5,"origin":[0,0,0],"uv_offset":[32,29],"uuid":"0688b6e6-6366-6584-3e85-b6308f361a30"},{"name":"tail2","from":[-1.5,6,27],"to":[1.5,9,34],"autouv":0,"color":6,"origin":[0,0,0],"uv_offset":[24,45],"uuid":"37baa016-fdda-f2d8-6b0f-cbec8889a45d"},{"name":"tail3","from":[-0.5,6.5,34],"to":[0.5,8.5,40],"autouv":0,"color":7,"origin":[0,0,0],"uv_offset":[38,55],"uuid":"89277697-7dfb-6b42-2ea4-3d66a07425bb"},{"name":"tail4","from":[-0.5,7,40],"to":[0.5,8,44],"autouv":0,"color":0,"origin":[0,0,0],"uv_offset":[30,63],"uuid":"dc801a46-d1f8-2afd-1221-cbf021fda901"}],"outliner":[{"name":"body","uuid":"08b60937-c59c-d629-428d-dbc1b47bf899","export":true,"isOpen":true,"visibility":true,"autouv":0,"origin":[0,9,0],"children":["dc9860c3-1826-d5a0-5475-140558d9bcbd",{"name":"head","uuid":"794cb49d-09ea-b58a-d62f-7909c5329824","export":true,"isOpen":true,"visibility":true,"autouv":0,"origin":[0,9.5,-11],"children":["64585c76-5a21-4d25-e334-afdc62e32bec",{"name":"jawtop","uuid":"864311e9-ad20-750e-c1bc-d9003d8e09fa","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9,-13],"children":["08ff348f-2450-1885-c0f6-1754cd0361e0","ce05463f-09fe-45c3-f038-016152a1d962","68004a0b-3d5e-1628-bc01-f97fc31d7add","1f51dc8c-bce3-f6b1-e3ce-b8bd95cfb0b6","a5e2642b-891a-8531-068a-f58f6773086d"]},{"name":"jawbottom","uuid":"ca3610f0-82e8-c919-0b09-cc448af7db2b","export":true,"isOpen":true,"visibility":true,"autouv":0,"origin":[0,9,-13],"children":["ad1c59ee-6f3f-07ef-fcdc-190444c48dc7","750a2256-945c-2ea9-b2a3-eaf1af4b55ec"]}]},{"name":"leg0","shade":false,"uuid":"1c25265d-b108-2e3a-b48c-1840a8679882","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[3.5,9,6.5],"rotation":[-15,0,-30],"children":["80425fb4-9022-e3f0-369c-4327b745fb92",{"name":"leg0bot","shade":false,"uuid":"ccf50fe0-f61d-a385-ae91-1b9cf1cd704a","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[4.5,4,6],"rotation":[50,0,0],"children":["6afca6bb-c3b1-3284-1c00-ef2028a079aa"]}]},{"name":"leg1","uuid":"742bd91e-8c68-346f-8171-5fd796e5168b","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-3.5,9,6.5],"rotation":[-15,0,30],"children":["a7c6896b-f5af-9216-3cd7-0ad96fe57966",{"name":"leg1bot","uuid":"f9aac351-dd57-f3c7-8888-aecf46f41bf0","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-4.5,4,6],"rotation":[50,0,0],"children":["675b7a00-486a-568b-9c51-09cef03b2abd"]}]},{"name":"leg2","shade":false,"uuid":"756ef132-6c43-8a05-f00e-89efded63842","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[3.5,9,-7.5],"rotation":[-15,0,-30],"children":["59aeddb8-d40b-8894-466c-ce509b62ef2f",{"name":"leg2bot","shade":false,"uuid":"dccb0f87-61fd-f919-3e77-ea01d2b7b921","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[4.5,4,-7],"rotation":[50,0,0],"children":["240ac047-9697-f70d-88af-2c948ef0a1a2"]}]},{"name":"leg3","uuid":"8b2f9b00-b22c-5b3c-a530-436a5d9d4a7a","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-3.5,9,-7.5],"rotation":[-15,0,30],"children":["269587ec-ed0a-74b0-0aac-d1e3f4b757db",{"name":"leg3bot","uuid":"a91c7b0e-3d6f-4a0e-18bf-c83531e1ef2e","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[-4.5,4,-7],"rotation":[50,0,0],"children":["97f9b166-f557-ac6b-853e-74e476343c85"]}]},{"name":"tail0","uuid":"c3e0f719-cb90-e79f-8664-3b6bc1531c0d","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,9],"children":["eee0a07c-244b-e299-cdbb-f4722dd1d4b8",{"name":"tail1","uuid":"0f292741-56cb-0d10-fc48-bb6e00ca2755","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,18],"children":["0688b6e6-6366-6584-3e85-b6308f361a30",{"name":"tail2","uuid":"38c0f23e-4aae-37ba-340d-95a042b86cbf","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,27],"children":["37baa016-fdda-f2d8-6b0f-cbec8889a45d",{"name":"tail3","uuid":"ba8b9331-6926-6d51-3f9c-b206a4f971b7","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,34],"children":["89277697-7dfb-6b42-2ea4-3d66a07425bb",{"name":"tail4","uuid":"e70eca10-4cd6-05eb-d828-02e363c9a3a5","export":true,"isOpen":false,"visibility":true,"autouv":0,"origin":[0,9.5,40],"children":["dc801a46-d1f8-2afd-1221-cbf021fda901"]}]}]}]}]}]}],"textures":[{"path":"crocodile.png","name":"crocodile.png","folder":"","namespace":"","id":"0","particle":false,"mode":"bitmap","saved":true,"uuid":"c62c819f-3c1a-aefb-00ff-415b02e2f7ac","source":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAcyElEQVR4Xu2dCZRddX3Hf/fts89kxQhZCEvUo6BQDQlJCG5d1IoeJCRshpAEEqEICNJqrYpiW3tsKWpRsFVL4egBUYvVgiACcupCrdoAAZIANhCyzJLZ3nJvz+f3v7+XIcyb8zLzcucm3Ms5zMvMe/f/f//f97cv15MGX8fO6wgqvifpVCDDRU8KuUCGip40FwIpljxJpQJZfdYiSac9SadTUqn44vuBFPJZ8VKeVMq+lEoVueb6u70Gb63u2/3jp88IHr3l19JTKlU/05HNyhtXnyDlMvv19ffpTErKJV9K5Yq0NOfkQx/7zqTtue4vt98bG77h447uCLgpRE+nRAIWDDzJ53wFBGd3yfmLJZ/LyOBQUZqbcrK3f1iy2bR4nifZTFqGhktyzWcnDwAv/vfVwTXv+9bLAHD9HWfK1771WwUBBC+WKlLIZ6R/oKggvvZzP2j4eY6XsPV+ruEbnv3qziDliWSzTgLkso7zkQDlikgmLbJ21VIZLpaV61MpTw+yqZCVvr1DThoUsnLFJ7/X8L3VeyhjSYDBwaLuD2APDZVUgrH3IBC5/K++O2l7rve77f++hm94/pyOwPNEuX+4ZLeH8wNJp0X4zcXnLlZxz38V31euD4JAKn4gKc+TXC49qeK0FgBWXnGkbNozVYaHy5LJpGRwqKT7RooNDBTlo4kEEDlmTodKfQ8AFD0BDHAHnI/+BwCrVyxSrslk0goMDg8gYBMABtTBpR+fPH2KCnjyil/IV7dsUTWA/l8zb578cnm7cj1Si72jqpBiKgl8Xz56faICZM6RnUE2YwYfhA8UAL7viR+I8LeNF5wmA4PD0tSUU4IjRiE+QDCD6s8+MXniFAlw0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7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7yYBQORHHq8FEwDEix6R7+b/AZovzmIGTS/bAAAAAElFTkSuQmCC"}]}
The file is called crocodile.bbmodel
I am looking for a way to allow users to upload .bbmodel files that is safe so that no web shells or malicious code can sneak its way past the upload can you guys help?
From what I know there is no magic button that will let you do this. that said the first thing you will want to do is make sure the uploaded file is valid json. check this Fastest way to check if a string is JSON in PHP?
Next you will need to define which fields in json are valid and what types the value should contain. for this I would create a skeleton versioin of the json string and store it a database field. Examining your json further you might need multiple skeletons for the various repeat or nested elements. eg one for meta like this
"meta":{"format_version":"","model_format":"","box_uv":}
you would want another skeleton for elements probably describing the keys for a single 'element'. and of course validate the textures.source nodes against a base64 encoding.
Next you will want to decide what are acceptable types for each of the field values. compare each field of the submitted json against an acceptable type you define.
once you do all of this validation you can be reasonably sure you have a valid file...I won't say secure or non-malicious but, done properly it will help you ingest the file without errors.
Still not guaranteed to be 'secure' but, it is a reasonable approach and would probably satisfy most due diligence critiques. If anyone can improve and provide more steps or different tricks to secure something like this I'd be glad to hear it.

PHP - Permanently changing array values

The title may explain the gist of it, but I want to know something. I am new to coding in PHP, and am adding it alongside my HTML5 so I can create a website for a game I'm creating. But, I need to know if I can permanently and dynamically change the contents of a file within an FTP.
So, say if I had 2 array values in a Username and Password field when I first created it. Is there any possible way to create a function that, upon registering information, allows me to permanently add those array values, so that every time I open the file, it stays at three values?
I want to do this so that I have a simple login system created. If there are any questions that have what I'm looking for in PHP, feel free to close as a duplicate and point me in the right direction. This is my first step, and I hope I can get some help on it. Thanks again in advance.

Trouble with implementation of download code redeemer

I'm designing a website for a small indie record label and they've dropped a bombshell asking if I could implement a function where a user can enter a code to receive a digital download.
Is there a simple solution to doing this? I was thinking all I would need is an input field where the user can enter a code, it gets verified and then allows a download but it sounds too simple. Is this even possible with something like .php (complete beginner)?
I'm willing to learn or I would've packed it in already so any advice would be great. Thanks.
Edit:
Thanks to some great advice I was able to create this!
If you wanted to do it at a very simple level, it is not much more than you describe it to be. You would need to familiarize with PHP and MySQL or some other database, but it isn't too difficult to create.
You need to figure a few things out, such as how do you want to limit the codes, 3 downloads in the first 24 hours to allow for failed downloads, restrict it to IP, or strictly one full download. Since you have the list of the 1000 codes given, you will probably want to base your system around having codes pre-generated and inserted in the database, rather than having an algorithm that can validate the codes on the fly and then check for already used codes.
You would want to store the download(s) in a directory that is not accessible from the web, and the php script would validate the code, and if valid serve the download to the user.
You can probably look to the wordpress plugin's database structure for other ideas, but I think at the very least you would need:
download_code (the code itself, probably primary key or at least index)
download_file (optional, the name/path of the file this code allows them to download)
redeemed (0 if not redeemed, 1 if redeemed)
redemption_time (timestamp of the first, or last redemption based on your requirements)
download_count (how many times downloaded if allowing more than 1)
ip_address (ip address of the redeemer)
email_address (email address if you want to collect it, or give user the option)
download_url (the unique string for the download url. this could be one way to implement download verification beyond the code, but is not necessary)
You would then need to create an html page with the text box for entering the code, and any other optional data you wish to collect. The form would submit to your PHP script.
When the PHP script receives a form post, it would validate all of the data (i.e. email address if you were collecting it). Once all data is valid, you read from the database looking for a code matching what the user entered.
If no data was found with the code, send them back to the form to try re-entering it. If a record is found, you can check the redeemed value from the database and see if the code has been used or not. If it has, this is where you can use custom logic to decide if they are still within their download window, the ip address is the same, or whatever criteria you want to use to allow re-downloads.
If it has been redeemed, show an error message. If it is still okay to download, you can serve a download by reading the file and sending it to the browser see example #1 here.
At some point you will have to update your database to set the redeemed flag to 1 and update the other values such as timestamp and download count. You can either run this code before you serve the download, or you can run it after the download is served. In some cases if the download was cut off, the last portion of your script won't run and therefore won't update redeemed or download_count. This may or may not be what you want, so you can decide where you want to do the updating.
Eventually you can update it to include an administration panel, but in the beginning all configuration could be done within the php script or config file. And eventually you could update it to use flash or some other technology to download the file and show progress bars etc.
Hopefully that will give you some idea on whether or not you want to try to implement it. Otherwise you could always search php on Hotscripts to see if there is an already rolled standalone version of what you want.

The simplest way to allow a web user to update a text file using PHP and Javascript?

Problem:
I don't know the simplest way to allow a single web viewer to update data in a text file on a server. (ie. only 1 person will be changing the data.)
Objective:
To make a prototype web application just one person needs to input in the start and end dates of new assignments and locations of staff and the whole company can visualize the information on a GANTT chart, probably using this Jquery libary.
Constraints:
My data is about the equivalent size of 1000 of these javascript list of lists like
*data = [["John Smith" , "assigment" , "1/1/10", "1/1/11", "Peru"],[...],...]*
Employee assignment data must be on an internal server.
I can't use a database (such as SQlite or MySQL).
I can only use PHP, Javascript, and jQuery.
Fact: Javascript cant directly change a data file sitting on the server.
My tentative fuzzy solution:
On client-side: use jQuery getJSON() to pass the data back and forth between dataReadWriter.php.
On server-side: dataReadWriter.php modifies a PHP array as well as writes modified data and reads JSONdata.txt stored in a text file on our internal server.
Given the constraints, it can't be done a lot smarter than what you are suggesting. One thing though, you shouldn't overwrite the only file containing the data, at least switch back and forth between two files, and make sure that your program does not overwrite the other file if one of the files show any signs of being damaged. You can use a PHP session to keep track of which file is the most recent, but better have some in-file timestamps as a fallback.
Is there anything in particular that you worry about?

Looking for design/architecture suggestions for a simple HTML game

Imagine that HTML page is a game surface (see picture).
User can have n number of boards (blue divs) on his page. Each board can be moved, re-sized, relabeled, created new and removed.
Inside each board there are m number of figures (purple divs). Each of these user can move inside the board or to another board, re-size, change color and label, delete, add new.
The goal of the game is not important, but let's say it is to rearrange figures in a certain way so that they disappear.
But the goal of the programmer is to save the whole game surface in the database for every user of the site, and to load it later when he returns.
So, how do I go about data exchange between client and the database?
Here's how I think it can be, but maybe there is a better way.
In the database I think of creating tables users, boards and figures.
Then I can SELECT all that belongs to a user and create his HTML page (surface).
But then, user will be able to change all of those properties of boards and figures and I don't know how to track those changes and how to save them back to the database. Is this a situation where JSON should be used?
Yes, if Javascript is an option, then basically you should generate a document (xml or json or plain text, doesn't really matter that much, though json is probably easiest if you're using javascript) that describes the serialized state of the board.
You can then track all changes client-side in a javascript object, and have javascript serialize that as a string that you then transfer to the server using XHR.
I would say that generally, in this scenario, you're best off with each object being a DOM element of some kind (div, span, whatever), because that way the browser can do all the work for you on figuring out positions and such, just absolutely position it all and work from there.
I'm assuming this is mostly going on with javascript when they're playing and that you already know how to do that. Well, each figure has propertes, like this:
-board (the one it's in)
-id
-label
-width
-height
-color
-x position (relative to board)
-y position (relative to board)
So each of those properties will be held in a javascript variable or array while playing. Likewise, the boards also have properties:
-id
-label
-width
-height
-color
-x position (relative to page)
-y position (relative to page)
So you will hold these in javascript variables as well.
When you save you just need to pass all of those variables over to the server. So make your XHR with your JSON string. Once your server receives the request you translate the JSON back into variables you can stick in the database. The way you're planning your database sounds appropriate.
To restore you would just SELECT the appropriate info for that user and (either with a normal page load or XHR) and use your javascript that moves everything around to create and position the objects where they need to go.

Categories