Posts by Daniel Omine • 19,666 points
581 posts
-
10
votes5
answers7637
viewsA: Is Excel a programming language?
The routines in Excel are provided by VBA. VBA, yes, is a programming language. Excel, in short, is just a spreadsheet. We can say that it is a calculator. So the question is almost how to tell if a…
-
7
votes2
answers2271
viewsA: Is working with Session safe?
The session variables in PHP are server-side cookies, that is, they are cookies saved on the server. Ordinary users without administrative access to the server do not have access to the files as…
-
3
votes1
answer207
viewsA: Check closed connection
The function mysqli_close() returns boolean value true: indicates that you have successfully executed false: indicates that there has been an error. Basically, just check the return value. Return…
phpanswered Daniel Omine 19,666 -
5
votes4
answers4258
viewsA: How to prevent direct access to my PHP code?
A safe technique is by directory indentation. We can also solve with other techniques such as the definition of a constant or the rules of permission to access a public folder. This resource depends…
phpanswered Daniel Omine 19,666 -
5
votes7
answers811
viewsA: How to write variables in PHP?
Technically and practically, in both forms, no problem. What can define whether a technique, style or even a concept is more appropriate than another is the ultimate goal. The data will be used for…
-
2
votes1
answer40
viewsA: How do I take information from a website and distribute it in a view?
Just return with the return That line if($cnt == 1){ $dados = $exc->fetch(); } else { exit(header("Location: $hpg")); } trade her in for it if ($cnt == 1) return $exc->fetch(); else…
-
3
votes3
answers99
viewsA: Conditions do not return expected values
The flow is correct because the POST will exist as an array of objects even if the fields are empty. So the flow goes through empty($_POST). <?php if (isset($_POST)) var_dump($_POST);…
-
15
votes8
answers5012
viewsA: Printing a String until a space is found
Another way: $str = 'John Doe'; echo substr($str, 0, strpos($str.' ', ' '));
-
0
votes4
answers721
viewsA: foreach php inside <script>
An example of how to traverse a sequence of Ids. The magic begins at this point list = $('[id^=foo]');. With this, you get an array of objects whose ID starts with "foo". With the array in hand,…
-
1
votes3
answers1488
viewsA: Cut text and add ellipsis
An alternative containing conditionals to avoid error in the third function parameter mb_strpos(). So you don’t have to worry about the amount of characters in the original string /** O limite de…
phpanswered Daniel Omine 19,666 -
0
votes3
answers4519
viewsA: How to display part of a text stored in a TEXT column?
An alternative containing conditionals to avoid error in the third function parameter mb_strpos(). So you don’t have to worry about the amount of characters in the original string /** O limite de…
-
3
votes3
answers315
viewsA: Return in methods
Arguments of methods or functions do not define or determine the return type. Non-return functions and methods are called "null return" or "void Return". Example function Foo(){ $r = 1 + 1; } This…
phpanswered Daniel Omine 19,666 -
2
votes4
answers1466
viewsA: Camelcase conversion function
Example using regular expression: function StrToCamelCase($m){ return $m[1].strtoupper($m[2]); } $prepended_char = '-'; $str = 'link-para-uma-pagina'; echo lcfirst(str_replace($prepended_char, '',…
-
2
votes2
answers261
viewsA: Set the value of the input whose name has brackets
You can do it that way: $('input[name="[21].value"]').val("AAAA"); Fiddle with example: https://jsfiddle.net/e0r4LmnL/…
-
3
votes3
answers758
viewsA: Generate Single Check Serials
I usually prefer something simple using timestamp <?php // retorna 10 caracters numéricos: // exemplo: 1446815555 echo time(); The chances of collision It can occur when the environment is on the…
phpanswered Daniel Omine 19,666 -
17
votes4
answers53481
viewsA: How to decrypt MD5?
MD5, speaking in a popular language, is a hash one-way. No information to reverse the hash for the original value. A few years ago, several websites offered solutions to "reverse" the hash and this…
-
1
votes2
answers477
viewsA: Invalid URL server error 500
If you’re using Apache as a WEB server, add this line to the file .htaccess: ErrorDocument 500 http://yourwebsite.com/error-500 That file .htaccess must be at the root of the public directory of the…
-
4
votes2
answers761
viewsA: Dynamic name input name
Set the field name to array Instead: <input name="nomePopular.'.$id.'" type="text"> Switch to that way: <input name="nomePopular[<?php echo $id;?>]" type="text"> An observation,…
-
2
votes3
answers717
viewsA: How to add a PHP variable only if it is set?
There are several ways to solve. See an example using variable variables and array_sum() $sum = array(); $v = 'var1'; $sum[] = (!isset($$v)? 0 : $$v); $v = 'var2'; $sum[] = (!isset($$v)? 0 : $$v);…
phpanswered Daniel Omine 19,666 -
2
votes1
answer1934
viewsA: How do I get an image from an input file?
Pre preview before upload To display an image preview before uploading, see below for an example: function ImagePreview(input) { if (input.files && input.files[0]) { var r = new…
-
2
votes2
answers134
viewsA: how to use Order by in ENUM
For numerical data, whereas media is 1, ova is 2 and film is 3: am2.module -> 1 (average) am2.module -> 2 (move) am2.module -> 3 (film) ORDER BY am2.module ASC For char or varchar data,…
-
0
votes2
answers1736
viewsA: How to separate array in odd/even and calculate multiple number?
/** O array original com os números */ $arr = [11,22,31,41,53,67,71,89,90,106]; /** Organiza os números ímpares e pares num array. O termo "even" significa "par", o…
-
3
votes3
answers2040
viewsA: Check if a record was deleted when running DELETE query
Right after executing the query: $result = mysqli_query($dbc, $query)or die('não foi possivel acessar Banco de Dados'); Check how many columns were affected with the function mysqli_affected_rows().…
-
4
votes3
answers3386
viewsA: Check if there is a character inside a text
Lay down strict rules Do not allow the user to type the emails separated by some character like ; or , or any other. How to apply this? In the form, create a single field where 1 single email will…
phpanswered Daniel Omine 19,666 -
3
votes3
answers21104
viewsA: Wait x seconds and show a Ubmit
In the example below, I use Jquery due to the use of the ready function(). Everything inside this function will be executed only after loading all page objects. This is necessary to avoid…
javascriptanswered Daniel Omine 19,666 -
15
votes5
answers83787
viewsA: Passing variables through the URL using friendly URL via GET
I wrote the code below to show something more "sophisticated", as the challenge proposes. The first point that caught my attention was the following excerpt in the AP question by clicking on this…
-
5
votes2
answers1641
viewsA: When to use and not use AJAX when submitting forms?
The question has a certain ambiguity because the title gives a notion of a broader and generic theme referring to the use of ajax. However, the context brings a specific problem that is to keep the…
-
1
votes1
answer133
viewsA: Routing system bypassing subfolders
In the . htacess file, add the following RewriteCond %{REQUEST_FILENAME} !-d This code says you should ignore the rewrite rule if you find a valid physical directory. Another point is loading css,…
-
12
votes2
answers5421
viewsA: How to validate each data type received from a form?
Before you begin, it is important to eliminate a serious problem of misinformation. That’s why it was necessary to add an introduction about setting up environment logs. It is common for many…
-
4
votes6
answers10518
viewsA: Difference between php <?php tags and <?=
There is also asp_tags <%%>, which was created to facilitate ASP programmers migrating to PHP 15 years ago. There were also other purposes such as creating a template system compatible with…
phpanswered Daniel Omine 19,666 -
0
votes1
answer1057
viewsA: Variable table name in Mysql query with CONCAT()
I researched a lot on the subject and found several solutions, however, none of the solutions was suitable for this specific case. In general, one solution is to use the SQL Prepared statements. It…
mysqlanswered Daniel Omine 19,666 -
1
votes1
answer102
viewsA: New PHP line in fopen function
Use the PHP_EOL constant: fputs($arquivo, $texto.PHP_EOL); Alternatively, you can force it like this: fputs($arquivo, $texto." "); Another way is to use the Carriage Return \r together with the…
-
-1
votes1
answer119
viewsA: How to resolve this Session o_rdwr error?
Assign write permissions to the path specified in Session. On Linux/Unix environment, permission 0777. If you don’t have access to the directory, set up a proper path to a location where you have…
-
1
votes1
answer242
viewsA: Move files to production environment
The most common tools for such a task are version controllers. The most popular are GIT and Subversion, also known as "SVN". GIT offers the public repository on github.com. There are also plans for…
phpanswered Daniel Omine 19,666 -
1
votes2
answers143
viewsA: configure virtual host in apache2
In apache settings (httpd.conf), look for the directive NameVirtualHost. If there is one, deactivate it. In the Virtualhost tag, set the server ip: <VirtualHost 127.0.0.1:80> IP 127.0.0.1 is…
-
1
votes2
answers730
viewsA: What better option to protect directories and files in a root folder?
Place system files in a directory without public access Example The Documentroot is defined in /var/www/site/public_html/ Then just put the system files in any other directory that is not public.…
-
22
votes6
answers8335
viewsA: How to know if the form is sent
Suppose a form with input field called "foo": <form method="get" action="script.php"> <input type="text" name="foo" size="10" /> </form> The form will send the data to the file…
phpanswered Daniel Omine 19,666 -
0
votes1
answer1057
viewsQ: Variable table name in Mysql query with CONCAT()
It is possible to use CONCAT to form the name of the table to be consulted? Example: SELECT T1.id, T1.col FROM tbl AS T1 LEFT JOIN CONCAT('tabela_prefixo_', t1.col) AS T2 ON T2.id = T1.id The actual…
mysqlasked Daniel Omine 19,666 -
0
votes1
answer46
viewsA: Amendments with IOS 9
Just change it that way: [[NSManagedObjectContext alloc] initWithConcurrencyType:]
-
3
votes5
answers2310
viewsA: Why are other encodings used besides UTF-8?
Among the basic points to be observed when adopting standards, we must analyze the technical part and especially the business model. If you want the system to be plastered and limited regionally,…
-
2
votes3
answers9315
viewsA: Ask if the user really wants to leave the page?
Under the context that the alert should be displayed if the user has a field filled, below follows a functional example with Jquery: <html> <head> <script…
javascriptanswered Daniel Omine 19,666 -
1
votes4
answers2235
viewsA: Codeigniter and . htaccess in subfolder on server
We have yet to define the correct path to RewriteRule. Note that you specified RewriteBase, however, RewriteRule still pointing to the root. To settle, do it: RewriteRule ^(.*)$ /foo/index.php/$1…
-
2
votes1
answer1136
viewsA: How to batch update with PHP and Mysql
Use the REPLACE INTO. The REPLACE INTO works as INSERT or UPDATE in a single instruction. Example REPLACE INTO tabela (coluna_id, coluna_status) VALUES (1,0), (2,0), (3,0) Multiple records are…
-
4
votes2
answers604
viewsA: Ternary Operator, is_array, unexpected
Only delimites the ternary operation in parentheses. Example: $var = 123; echo 'valor de var: '.(is_array($var)? implode('-',$var) : $var);
-
1
votes3
answers1427
viewsA: Ways to Replace <Iframe> in HTML
The table does absolutely nothing. Remove it and set the size on itself iframe. CSS is also unnecessary. Remove everything and use just like this: <iframe width="100%" height="1140"…
htmlanswered Daniel Omine 19,666 -
3
votes2
answers1842
viewsA: how to separate array values by "," and "and"
$arr = ['janeiro', 'fevereiro', 'março', 'abril', 'maio']; $l = array_pop($arr); echo implode( ', ', $arr ) . ' e ' . $l; The function array_pop() remove the last element of the array and return its…
phpanswered Daniel Omine 19,666 -
3
votes2
answers3084
viewsA: Swap div of place with jquery
$('#Trocar').click(function() { $('#mae div:first-child').remove().insertAfter($("#mae div:last")); }); Full example: <html> <head> <script…
-
4
votes4
answers1277
viewsA: View last 5 lines of a PHP file?
And why not use the tail? $file = escapeshellarg('tmp.txt'); $rs = `tail -n 5 $file`; echo $rs; The test was done in a 2mb file, 92442 lines. Execution time: 0.107839 (1 millionth of a second) To…
-
4
votes4
answers6032
viewsA: line break inside the string
First, be aware of the difference between characters and bytes. The function strlen() returns quantity in bytes. If you want to count the number of characters, use the function mb_strlen() $str =…
phpanswered Daniel Omine 19,666 -
2
votes3
answers3091
viewsA: Why doesn’t getJson work?
Add a error handler to capture errors: In this example, we use the method fail() $(document).ready(function() { var jqxhr = $.getJSON( "js/json/select-menu.json", function(data) { console.log(…