Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #19225

Re: JSON and PHP

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: JSON and PHP
Date 2022-12-28 09:56 +0100
Message-ID <k12emkF4sbjU3@mid.individual.net> (permalink)
References <tog2vc$tnl$21@gallifrey.nk.ca>

Show all headers | View raw


On 28/12/2022 01.34, The Doctor wrote:
> Trying to implement a JSON array in PHP
> Using

<too much code so removed, use a code repository and link to it>

> 	  Just wonder how to supress repeats.

Don't insert the same data multiple times into an array.

Here is a short code demonstrating what you are doing
--- example.php ---
<?PHP
for($i = 0; $i < 3; $i++) { // this replaces the foreach in the original 
code
$MyObj[] = array("same each time", "this from round $i");
var_dump($MyObj);
}
?>
--- eof ---

You can see how the array grows each iteration of the loop.

Some tips:
Separate display and logic into two files, one with only the logic and 
one with only showing the resulting data, this makes it far cleaner and 
simpler to update the design of the page without affecting the logic.

Do not have variable with the same name but different case, it makes 
your code far more difficult to follow and more mistakes can sneak in

Validate input data, always go with whitelisting of what is allowed to 
be in a input, this way you always know the data is safe to use. Regular 
expression can make this simpler.

Always calculate the total, do not trust that from a post or else 
customers gets all the items for free. Also item prices should always be 
fetched from the stored price list, not from a post value.

Store data that you don't want to be manipulated but you need no the 
next page in the session, as this data can't be manipulated by the user 
and you don't need to revalidate the data on each page.

-- 
  //Aho

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

JSON and PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2022-12-28 00:34 +0000
  Re: JSON and PHP "J.O. Aho" <user@example.net> - 2022-12-28 09:56 +0100
    Re: JSON and PHP doctor@doctor.nl2k.ab.ca (The Doctor) - 2022-12-28 14:42 +0000
      Re: JSON and PHP "J.O. Aho" <user@example.net> - 2022-12-28 22:09 +0100
        Re: JSON and PHP H H H H H H H H H H H H H H H H H H E <angel00000100000@icloud.com> - 2023-01-04 09:10 -0800
          Stop spamming (Was: JSON and PHP) "J.O. Aho" <user@example.net> - 2023-01-04 19:24 +0100
  Re: JSON and PHP Arno Welzel <usenet@arnowelzel.de> - 2022-12-28 19:00 +0100
  Re: JSON and PHP ThE sUn <angel00000100000@mail.ee> - 2022-12-28 21:28 -0800

csiph-web