Posts by Inkeliz • 20,671 points
671 posts
-
0
votes2
answers560
viewsA: datepicker does not work in dynamic form with Js
This is a feature of Javascript, I explained this in another question., in an extremely similar case. For it to work, you need to call the $('.data').datepicker() after the actual element exists.…
-
1
votes4
answers559
viewsA: Load url on same page
First use CURL to connect with another service. That way, for example: $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $link_para_chamar); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);…
-
2
votes2
answers73
viewsA: Checking if login already exists via AJAX
You are mixing PHP with Javascript in a "wrong" way. It is not wrong, but what awaits as a result is different from what will actually occur. The location will only affect AJAX, but will not trigger…
-
2
votes1
answer6265
viewsA: What is this net::ERR_NAME_NOT_RESOLVED error in php?
The problem is that the site does not have the subdomain www.. For this reason error of not finding the domain is shown, because it does not exist. Removing the www. URL will not exist error. ;)…
-
1
votes1
answer111
viewsQ: Javascript equivalent to PHP list()
Is there any Javascript function equivalent to list() of PHP? Suppose this JSON: { "ALERTA":[ { "TITULO":"Erro!", "MENSAGEM":"Seu nome parece estar incorreto" }, { "TITULO":"Erro!", "MENSAGEM":"Seu…
-
6
votes2
answers4450
viewsA: How to use openssl_encrypt encryption method?
This response has been completely modified in order to correct errors in the examples and avoid misuse of this resource. In addition, the use of PHP 7.1 and PHP 7.2 features, previously unavailable.…
-
1
votes2
answers188
viewsA: What is the difference between the following ways of using the jQuery ON and OFF methods
The .off() is mainly used to prevent duplication of the same action, see the example, SEM .off(): function button(e){ if($(e).hasClass('comOff')){ $(e).off(); } $(e).on('click', function() {…
-
2
votes1
answer139
viewsA: List the most liked posts
The API does not provide this, as far as I know. You should treat this in your application, you can use: $retorno = json_decode($curl, true); uasort($retorno["posts"]["data"], function($a, $b) {…
-
2
votes1
answer1421
viewsA: PHP and mysql time count
I will divide the questions to better answer, then solve the problem (or suggest a solution) to the case. Mysql only stores and who "does the job" is PHP in the case? Yes and no. Mysql is much more…
-
3
votes4
answers8644
viewsA: How to take the "src" value of an "img" tag through Javascript and copy it to clipboard?
You can use the library clipboard.js, click here to see your documentation. Solution using clipboard.js: // Inicia o Clipboard no elemento "button" var copiar = new Clipboard('button', { // Define o…
-
1
votes1
answer2148
viewsA: How do I restart apache on a web server?
This depends on the operating system used. If you have access to SSH: No Centos/RHEL If you use Cpanel you’re probably using the Centos! service httpd restart In Debian/Ubuntu sudo…
-
3
votes2
answers339
viewsQ: Is it possible to create a "synonym" of a function, two names for the same function?
I own a set of functions using a third-party API. From time to time I thought of making it available, since there is no library publishes in PHP and it makes no difference to keep as a closed source…
-
3
votes1
answer408
viewsA: Disconnect user when logging into another account
I believe that the best thing to do would be to store and query the database to check if there was no connection to another account. For example: When connect is created this: $_SESSION['conectado']…
-
1
votes3
answers600
viewsA: Creation of Array within Function
This is an alternative based on solution by @Andrei Coelho. I believe that more simplified. <?php function pais($codigo){ $pais = array( "default" => array(false, "Ocorreu um erro"), "pt"…
-
3
votes1
answer401
viewsA: Print de array php
You can use the exec for this purpose, rather than shell_exec. $exec = exec('ipconfig', $array); if($exec){ echo '<pre>'; var_dump($array); echo '</pre>'; } Will return: array(15) {…
-
2
votes3
answers227
viewsA: How to store the number of rows found from a Mysql query in a variable
First you are using an obsolete and discontinued function in the latest versions of PHP. Depending on which version of PHP you are using it is impossible to use mysql_query, as well as impossible to…
-
1
votes2
answers4795
viewsA: How to subtract hours from a javascript date?
You can get it using getTime(). Then subtract in milliseconds when you want to return. // Defina o quanto quer voltar: var Dia = 0; Dia = Dia*60*60*24 var Hora = 1; Hora = Hora*60*60; var Minuto =…
javascriptanswered Inkeliz 20,671 -
0
votes2
answers422
viewsA: Send form as active tab
When the tab is selected it contains the tab-pane active instead of just tab-pane. So just do it: $('button[type="submit"]').on('click', function(){ var modo =…
-
6
votes2
answers1107
viewsA: foreach can replace fetch_array?
You can use the mysqli_fetch_all(), thereby making a foreach of the data already obtained. Thus using: $sql = mysqli_connect(...); $Select = mysqli_query($sql, 'SELECT id, nome, idade FROM tabela…
-
1
votes2
answers109
viewsA: How to ensure that a SESSION expires if the user accesses a copy of the application that is in another directory
About the HTTP_REFERER: The HTTP_REFERER is extremely vulnerable in this case. Since it can be edited and erased peacefully on the client side, so don’t believe it, you can use the HTTP_REFERER as a…
-
7
votes1
answer16952
viewsA: Array generates "Undefined offset" error
The index problem occurs WHENEVER you are searching for an input in the non-existent array. Small examples: In the case of an array of numerical indices: <?php $array = array('Ricdun',…
-
0
votes2
answers74
viewsA: Error in search system with php
You can use the isset. Thus use: $min_length = 3; if ( isset( $_GET['query'][ $min_length - 1 ] ) ) { // Seu código quando existe mais ou igual a 3 caracteres }else{ // Seu código quando não existe…
-
0
votes1
answer199
viewsA: problems validating password hash in php
Your question was answered in the comment, I’m just rewriting and adding more details, in case someone comes to have the same problem. The function password_hash() has two supported algorithms,…
-
3
votes5
answers14748
viewsA: Take part of a string delimited between characters
You must use the preg_match_all when there are multiple values, see your documentation here! To "catch": This is to ONLY get the data between "/", so you can get "what you have" between "/". You…
-
1
votes2
answers73
viewsA: Random Array between Specific Values
There are several alternatives. random_int (PHP 7): $array = ['um', 'array', 'qualquer']; // Contagem de elementos da array: $contagem = count($array); // Gera a "randomização" (ex. '2'): $gerador =…
-
2
votes1
answer401
viewsA: Sript PHP with secure connection on all pages
You can change a lot of things to try to improve performance, but you need to have access to Root, or you can modify the Apache or Nginx configuration. How I came to use Nginx I will use as a base.…
-
3
votes2
answers1345
viewsA: How to store and retrieve the previous URL within the Cookie
If you want to redirect via "Favorites" use this: // Pega o link atual var link = window.location.href; // Redireciona para o site contendo o link…
-
12
votes5
answers9322
viewsA: How can I generate a 7-character alpha-numeric key?
The safest method to generate a pseudo-random combination is by using the random_bytes(). So use as follows: $numero_de_bytes = 4; $restultado_bytes = random_bytes($numero_de_bytes);…
-
4
votes1
answer1411
viewsA: 301="Moved Permanently" Curl php
You probably need to accept redirects. Add the parameter CURLOPT_FOLLOWLOCATION to Curl: curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); This will enable you to follow the "Location:" header of your…
-
5
votes1
answer2970
viewsA: PHP Checks Weekends and Holidays
There is no native function for this, but you can use the Holiday API, it supports holidays from Brazil and other locations, Portugal is not currently supported. For demo I made this Javascript:…
-
0
votes1
answer70
viewsA: Array with Mysql
I believe the best thing to do is to use the RAND. SELECT nome FROM CadMusicas ORDER BY RAND() This will return the records in a random order, it will depend on how your database is structured, each…
-
1
votes1
answer61
viewsA: Decrease a multidimencional array
You should do what you did before, but only capture what you want, in case $array[0] inside a loop, or not. Apparently already has knowledge about the for, so I’ll use it. // Sua array: $array =…
-
4
votes3
answers9533
viewsA: Remove whitespace between array values
If you want to remove all spaces use the str_replace(), see in the manual. str_replace(' ', '', 'DDF 00001778BRASILIA'); // Resultado: DDF00001778BRASILIA If you only want to remove repeated spaces,…
-
1
votes1
answer87
viewsA: Button that increases the limit of mysql_query
You must use OFFSET or use some other alternative, as shown here, making some minimal adaptations. SELECT * FROM albuns ORDER BY id DESC LIMIT 4 OFFSET 0 // Irá listar todos os itens de id 0 até 3.…
-
1
votes3
answers44
viewsA: How to order from what has more records to what has less
You can use the count(). That way it would be like this: SELECT *, count(ip) AS contagem FROM tabela GROUP BY id_produto ORDER BY contagem DESC That way you’ll tell the ip, declaring the name of…
-
1
votes1
answer23
viewsA: How to turn 2 forms into 1 only '
If you use an employee-based UPDATE you can use this: UPDATE tabela SET status = IF (`status`, 0, 1) WHERE funcionario = ? This way it will invert between 0 and 1. Example: <form…
-
3
votes2
answers3408
viewsA: Check if URL exists
Directly you can not do this. All websites in modern browsers can only have requests for themselves. To allow another site to connect to yours you need to define the Access-Control-Allow-Origin, can…
-
1
votes1
answer200
viewsA: foreach shows 1 wait file then clears and shows another php
The break; as mentioned it prevents the continuation of foreach(). An alternative is to use the sleep(), see manual. That way would be: //... foreach($xml -> item as $item){ echo "<div…
-
2
votes2
answers1777
viewsA: How to force the download of a text file?
The question has been answered, but there is another solution or complement. You can use the attribute download tag a: <a href="LocalDoArquivo" download="NomeDoArquivo"> Texto </a>…
-
4
votes1
answer188
viewsA: Security, what threats besides an SQL Injection do I have to worry about a search field?
SQL Injection, cited, would be the most severe from the perspective of data integrity, if there is such error could allow editing, erasing and reading information improperly. However, there is also…
-
3
votes2
answers1151
viewsA: Vulnerability in my system "forgot password"
The vulnerability is beyond that. I’m no security expert (not to say I’m not an expert on anything, really!), but I’ll list some errors I noticed in about 3 minutes: INPUT HIDDEN: (Very High Risk)…
-
0
votes2
answers60
viewsA: How to capture all images from an image field in XML to write to MYSQL?
There are several ways. The quickest way to do it, at least for me, would be to use the preg_match_all(), read about it here. That way it would be: preg_match_all('/<Item…
-
0
votes1
answer2935
viewsA: How to generate a sequential number in a PHP form without using a database?
Using the database is the best alternative. Using Javascript is impossible, it runs on the client side, not on the server, forget. What you can use is an alternative to the database, if you search…
-
1
votes2
answers398
viewsA: How to write data from two columns of a table using select?
E.Thomas' solution is valid. But I think you can use Mysql itself for this. Use only the codigoas value: <option value="<?php echo $marca = $res['codigo'];?>"><?php echo $marca =…
-
5
votes3
answers8946
viewsA: Search ZIP by PHP Street
I’m running out of time to comment, as I usually do. But as you made me discover this API, so I will try to help. Unfortunately using pure JS, for me, it is complicated after you get used to using…
-
0
votes1
answer674
viewsA: PHP + Jquery + JSON
This problem is the same as jquery ui autocomplete + php does not work You are generating more than one JSON. Change the PHP: Change this: foreach ($gUsuarios as $usuarios) { $agora =…
-
3
votes2
answers1018
viewsA: Input type image does not send the form?
Every case has a different problem. When you use the input of the kind image it generates two values, of X and Y. Example: <form method='post'> <input type='image'…
-
4
votes2
answers1873
viewsA: How to pick up the strings that are in brackets?
There are several ways. The one I would prefer, for being more practical (=P): Use the explode, which breaks the string where it determines. <?php $texto = 'lang[en-US].php'; // Seu $texto $texto…
-
2
votes1
answer2006
viewsA: How to take data from an array and use Rand without repeating?
You’re using the wrong resource. There is the shuffle for this, see in the http://php.net/manual/en/function.shuffle.php. The shuffle does just make the array in random order, so the defined order…
-
1
votes1
answer47
viewsA: Discover Keys array of a vector
You can use the preg_filter for this, so filter only by where "there is" the underline, or any other character. By default the regex returns only data that exist, but there is way to reverse this.…