Posts by Inkeliz • 20,671 points
671 posts
-
1
votes2
answers114
viewsQ: Is there any way to force you to ignore errors in Go?
Golang forces us to manually remove unused items in the code, for example: for index, item := range retorno.Threads { fmt.Fprint(w, item.Id) } If you run a go run .... he will say: index declared…
-
0
votes1
answer241
viewsA: Group data from a Query?
You can use the GROUP_CONCAT, grouping by COD_AUT, if this is the only common parameter. Soon: SELECT id, cliente, GROUP_CONCAT(descricao) as descricao, forma_pgto, bandeira, valor, codigo, data,…
-
2
votes3
answers637
viewsA: Make PHP print the result of the Factorial class
For small numbers you can simply do: array_product(range($numero, 1)); If you want the 8! the range() will create [8,7,6,5,4,3,2,1] and the array_product will multiply all of them, resulting in…
-
1
votes1
answer44
viewsA: Search for record in array()
This is probably due to weak PHP typing, array_search returns the key of the array that has the given value. So consider this: var_export( array_search(1, [1,2,3]) ); // 0 This is equivalent to…
-
1
votes1
answer929
viewsA: Call to a Member Function fetch_object() on a non-object
Summary: Change this: $user = $result->fetch_object(); For this: $user = $stmt->fetch(); This will have the result in array, not on object. If you really want to use fetch_object() you will…
-
1
votes1
answer449
viewsA: Array_push in php multidimensional associative arrays
You don’t need the array_push, you can just do: $arrDados = array(); $arrDados += array('NumeroEmpenhoAno' => array('code' => 0,'size' => 1)); $arrDados += array('UnidadeOrc' =>…
-
0
votes3
answers47
viewsA: PHP-error but still sends what is requested
You should use one exit(): if(!mysqli_query($conn, $usql)) { echo "Error updating database!"; exit(); } This way if you fall into this condition you will be shown the error due to the echo, and…
-
0
votes2
answers707
viewsA: Checking repeated numbers in PHP
First I believe it is better to divide this into several functions, a function as the name suggests should make a single function. However you can simply use the count() with the array_unique() and…
-
2
votes3
answers210
viewsA: Audio aleatorio na pagina
To get all the songs you can use the glob, thus: $musicas = glob('data/*.{mp3,wav}', GLOB_BRACE); This will list all .mp3 and .wav that are in the folder data, for example: array ( 0 => 'data/07.…
-
12
votes8
answers2184
viewsA: How to know all possible combinations of 0 and 1 in Java?
If there are 5 houses, so there are 2 5 combinations, then just loop through all 32 combinations. for (int i = 0; i < 32; i++){ System.out.println(Integer.toBinaryString(i)); } If you want with…
-
3
votes2
answers772
viewsA: How does XOR work for two binaries with more than one digit?
The XOR is a mod 2, so if they were: 110 011 It would be the same: (1 + 0) mod 2, (1 + 1) mod 2, (1 + 0) mod 2 Assuming , were concatenation, see this in Wolfgramalpha. When you do this with two…
-
1
votes2
answers1262
viewsA: PHP Check/Take Down Login Duplicity Session
No, at least natively does not exist, what you can do is save to the database which session is active, including using the session_set_save_handler to do so or you can create your own session…
-
1
votes3
answers441
viewsA: Integer conversation in the rounding account 0.1
I think this question is duplicate of this, which in itself is also duplicated from others, but the fact that the representation is 8, even in float, can cheat. When you give one: echo ((0.1 + 0.7)…
-
5
votes1
answer399
viewsA: HTML & PHP - HTML code simply not read
The problem is logical and predictable by the behavior of Bcrypt. I will try to pass a basic of the behavior of Bcrypt. But, see that do this: <?php $senha = "a-mesma-senha"; echo…
-
3
votes1
answer36
viewsA: How to leave the date in this format 27-Feb-17 at 21:52
To documentation has exactly what you want, which is the M (for the month to be in the format of Jan until Dec) and the y (for the year to be in the format of two numbers, where 2017 is 17). So just…
-
0
votes2
answers305
viewsA: Simple html dom grab "text/javascript" link?
Just use the Xpath of PHP, basically the following: $html = "seu HTML obtido por file_get_content ou por cURL..."; $DOM = new DOMDocument; $DOM->loadHTML($html); $XPath = new DomXPath($DOM);…
-
3
votes4
answers6374
views -
4
votes2
answers172
viewsA: What is the best way to turn a secure contact form?
I do not guarantee that this answer corrects all problems, there may still be other security problems! This is the function: bool mail ( string $to , string $subject , string $message [, string…
-
4
votes2
answers984
viewsA: How to update data from a table only if the new values are different from the current ones?
O Mysql does not update if the values are equal, according to the documentation itself: If you set a column to the value it Currently has, Mysql notices this and does not update it. Link For…
-
3
votes3
answers78
viewsA: While PHP does not exceed count
A simpler solution to do what you want is to use the range(), native. That’s all you need: // Trata o input: $inicio = $_GET['inicio'] ?? 0; $inicio = is_numeric($inicio) ? $inicio : 0; $final =…
-
4
votes1
answer25706
viewsA: Warning: Illegal string offset
This publication should be a "duplicate" of a few, I don’t even know if I should answer this, because the answer is in the error itself. What is happening is because the foreach() is causing only…
-
2
votes1
answer369
viewsA: "mysqli_connect" does not work
I believe that to do what you want you should use the __construct(), that way when you do the new Connection(), for example, you will automatically trigger the construct(), he is able to set the…
-
0
votes2
answers61
viewsA: PHP Creating experienced leveis
If it’s 50 to 50 you can just do: $level = floor( ($exp / 50) + 1 ); Test it out here. This could be done at the time of displaying to the user, while in the database only keeps the value in…
-
5
votes1
answer39
viewsA: Delete first number if 0
You can use the ltrim, by default it removes spaces at the beginning of the text. However, specifying the last argument, it will remove the specified characters if they appear at the beginning of…
-
0
votes2
answers73
viewsA: Use unique identifier timestamp in a PHP process?
Handles many transactions per second and uses time() then you have many collisions per second, naturally. The time() returns the date in unixtime, that the number of seconds counted since 1970.…
-
0
votes2
answers777
viewsA: Retrieve data returned via json with PHP
You need to add a User-Agent, so that CURL becomes closer to a common browser, see a list of UA here. To define a User-Agent there are two ways, choose one of them: Adding CURLOPT_USERAGENT (-A):…
-
2
votes1
answer322
viewsA: Protect input from scripting attack
What you should do is use the htmlentities() at the time of flaunt the result. This is vulnerable: // Input: $Nome = $_POST['nome']; // Output: echo $Nome; This is relatively safe against XSS: //…
-
2
votes1
answer40
viewsA: Is there any way to do multiple mysql queries and if any fail to undo all?
There is, for that you use the Transaction, on it you all queries that are executed within the transaction can be undone (rollback) or saved (commit). Mysqli already has support, just use:…
-
1
votes4
answers2070
viewsA: PHP, how do I stop when the number after . is 0 is hidden?
You can use the str_replace, thus: str_replace('.00', '', $numero); This will remove the .00 if there is, if the .00 no change will be made. Entrada: 100.00 Resultado: 100 Entrada: 100.30 Resultado:…
-
7
votes4
answers2570
viewsA: How to take the penultimate and antipenultímo item from an array
Basically the count() to get the number of items it has in the array, although there are other options. Being for example: $array = ['um', 'dois', 'tres', 'quatro', 'cinco', 'seis']; Can get the…
-
3
votes1
answer297
viewsA: PHP Object Injection
The class must already exist, with the magic methods, that’s all it needs, in general. Suppose you have this: class Teste { public $nome = ''; public function __destruct(){ echo 'Olá, ' .…
-
3
votes2
answers7167
viewsA: Error trying to delete with INNER JOIN in MYSQL
You need to specify which table you want to delete from, for example: DELETE `tb_users` FROM `tb_users` INNER JOIN `tb_marker` on `tb_users.id_users` = `tb_marker.id_users` WHERE `tb_users.id_users`…
-
2
votes2
answers996
viewsA: How do I protect my JSON application?
Summary: There’s no way, not that I’m pessimistic, but in fact there’s no way. CSRF protection: If you’re worried about someone reading the content, there are two "distinct": Get your /json.json on…
-
1
votes1
answer520
viewsA: Return facebook user ID
Depends, if you’re using the official Facebook API (due to the use of the facebook-Graph-api tag) there is no way. Since version 2.1 of the API, unless mistaken, the identifiers are individual, so…
-
1
votes2
answers421
viewsA: Problem when mounting JSON with database return
A simple way to fix the problem, with the help of Mysql is to use the GROUP_CONCAT() and then use the explode() of PHP. This way it would be: SELECT nome, group_concat(data) FROM pessoa GROUP BY…
-
1
votes1
answer1139
viewsA: My bot in Telegram is looping messages
Use the offset Telegram to only get new messages, ignoring already read messages, see https://core.telegram.org/bots/api#getupdates. Identifier of the first update to be returned. Must be Greater by…
-
1
votes3
answers115
viewsA: How to access an array and export variables?
You can use the list(). However, as you do not use numeric Dexes you will need to use the array_values, as an example: list($cliente, $entrega, $utilizacao, $norma) =…
-
3
votes1
answer546
viewsA: Abort script without closing bat
If you’re on Windows, try using: $WshShell = new COM("WScript.Shell"); $WshShell->Run('%COMSPEC% /C '.$file, 0, false); If you don’t want to entrust in the %COMSPEC% specify which "interpreter"…
-
0
votes2
answers203
viewsA: Error while recovering a textarea by jquery
Exchange the .children('#texto') for .find('#texto'). The #texto is not the direct son of .resposta, but rather of the .resp, soon: $(this).siblings('.resp').find('#texto'); Like the .resp and the…
-
1
votes1
answer49
viewsA: Find img tags in text
Just use str_replace, to exchange the src=' for src='img/'. str_replace('src=\'', 'src=\'img/', $s); Test this.…
-
1
votes3
answers7670
viewsA: Display logged in user name
What you can do is create two different types of "menu" one for when you’re logged in and the other for when you’re an uninlogged visitor. For example: session_start();…
-
6
votes1
answer648
viewsA: How to change a comma, by a point, to a decimal number inside a string
PHP: Use the REGEX: /(?<=\d),+(?=\d)/ Use the function preg_replace of PHP: preg_replace('/(?<=\d),+(?=\d)/', '.', $string); Test it out here. Mariadb: Requires support for ?. Use the REGEX:…
-
1
votes1
answer684
viewsA: Show lowest value in Mysql
Use the LEAST(): SELECT LEAST(1,2,3); Upshot: 1 It will return the lowest value between the values inserted in the function. In your case do: SELECT LEAST(ColunaA, ColunaB, ColunaC) FROM Tabela This…
-
6
votes2
answers1238
viewsA: What’s the difference between using password_default and password_bcrypt?
Right now there’s no difference. The difference is that the PASSWORD_DEFAULT was designated to change when new algorithms are added, but at this time (now latest version is PHP 7.1 for reference)…
-
3
votes2
answers110
viewsA: PHP logic problem
You can simply use && (empty($modality) || $plans_available[$key]['modality'] == $modality). $found = 0; $get_arr_key = array_search($idplan, array_column($plans_available, 'plan'));…
-
0
votes2
answers185
viewsA: Full Calendar does not run PHP file
You’re passing a JSON "like string" in: $vetor[]= "{id:{$linha['event_id']}, title: {$linha['title']}, start: {$linha['start']}, end:{$linha['end']}}"; You have some options, one would use: $vetor[]…
-
0
votes2
answers62
viewsA: PHP Comparison between fields
Use the mb_strlen to know how many characters it has and compare with the minimum number of characters required. For example: if(mb_strlen($postcomment) > MINIMO_DE_CARACTERES &&…
-
4
votes1
answer155
viewsA: How to check duplicate files?
One of the ways is comparing the cryptographic hash of each of the files, if they are the same is because the file is identical. For this you can use the crypto and the fs to open the file. I…
-
1
votes2
answers12186
viewsA: How to send a json via post with PHP?
The page is protected for connected users, so you will most likely need to send session cookies (the name of the session, apparently, is ASP.NET_SessionId), a simplistic way is to use: $cabeçalho =…
-
6
votes2
answers2252
viewsA: How to check real-time database change with php websocket?
You have several ways. Mysql: Using sys_exec(). It can be used as a Trigger, whenever the data is added it is triggered and therefore can trigger a file, such as a PHP, this PHP sends the…