registro.php - PHP Online
Form of PHP Sandbox
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of registro.php.php
- <?php
- //===========Registro de usuarios============//
- if(isset($_POST['nombre'])){ //validacion de datos minima
- $objson = null;
- $file = "registros.json"; //archivo de lectura y escritura
- $data = [];
- if(file_exists($file)){ //recompilacion de datos existentes
- $string = file_get_contents($file,true);
- $data = json_decode($string,true);
- }else{
- die('no se puede leer el archivo de registro');
- }
- //nuevos datos
- $data[]=[
- 'nombre'=>$_POST['nombre'],
- 'pais'=>$_POST['pais'],
- 'celular'=>$_POST['celular'],
- 'email'=>$_POST['email'],
- ];
- //imprimimos para saber que datos tenemos
- echo '<pre>';
- echo var_dump($data);
- echo '<pre>';
- //pasamos los datos a formato json string
- $fullrecord = json_encode($data);
- //guardamos y validamos los datos.
- if (file_put_contents($file, $fullrecord)===false){
- die('no se puede escribir en l archivo');
- }
- }
- //pasado 5 segundos redirigimos al index.php
- echo '<meta http-equiv="refresh" content="5;url=index.php">';
- ?>