Posts by Miguel Mesquita Alfaiate • 1,048 points
28 posts
-
2
votes1
answer1220
viewsA: PHP Built-in and htaccess - Route System / User Friendly URL
Let’s see if I can help, and if I understand the question. I leave here an excerpt of the code I use in a framework I developed over the years, and which I use in several PHP projects. First of all,…
-
3
votes2
answers204
viewsA: What is the name of the ... operator used in PHP 5.6?
This type of parameter is based on a similar type that has existed in C++ for a long time. The name of this type of parameter in C++ is even variadic arguments:…
-
5
votes1
answer130
viewsA: How to ignore an exception in php?
If the goal is to deal with exceptions, nothing better than try / catch: try { chamarMetodo(); } catch (Exception $e) { // lidar com erro } For more information, read:…
phpanswered Miguel Mesquita Alfaiate 1,048 -
1
votes3
answers1452
viewsA: Copy value between quotation marks C#
I think the easiest way is to use the String.Split of C#, dividing the string by quotation marks. string[] words = text.Split('"'); string[] parts = words[1].Split('.'); string result = parts[0];…
c#answered Miguel Mesquita Alfaiate 1,048 -
1
votes3
answers268
viewsA: Use reference in MYSQL query condition
Have you tried using Having instead of Where?
mysqlanswered Miguel Mesquita Alfaiate 1,048 -
1
votes1
answer234
viewsA: Create SQL timer column
I think it’s easier to solve this with a datetime column. So PHP queries the column, checks whether more than 24 hours have passed between the current date and the column date, and does what it has…
sqlanswered Miguel Mesquita Alfaiate 1,048 -
1
votes1
answer605
viewsA: What is the difference between long Lling and normal ajax?
To use long-Polling in this specific context, the ideal is the page that makes long Polling receive a parameter that corresponds to the last timestamp that the user has. With this, the page will…
-
4
votes1
answer751
viewsA: Indexing of Database
The difference can be analyzed using the explain. try to query over a table, using a Where field. Then try putting an index in that field and pulling out, and seeing the differences. explain gives…
-
4
votes5
answers6496
viewsA: Does not record records in my database
If you do print_r($_POST) you will see that there is no variable called 'submit' in the array of $_POST. That’s the problem. You have to set the ID/ Name of the submit button in HTML. <input…
-
1
votes1
answer87
viewsA: Code problem ( Find values between a date and another in the database )
Here is an example of how to mount the dynamic query: $parms = array(); $filter = array(); $query = "(...) WHERE "; if (isset($_GET["origem"]) && !empty($_GET["origem"])) { $filter[] =…
-
13
votes3
answers1203
viewsA: Why do parameterized SQL queries (name = ?) prevent SQL Injection?
$user = "1;DROP TABLE Users;"; $SQL = "SELECT * FROM Users WHERE User=$user"; If the $user variable is something filled by the user and the user puts in its value something like the one I have in…
-
7
votes4
answers15034
viewsA: Difference between mysql_connect() and mysqli_connect() functions in PHP
Mysqli is newer and has support for Features that the other does not have, such as Prepared statements, Multiple statements and transactions. You must use Mysqli. For further clarification:…
-
0
votes1
answer27
viewsA: Get Bin File Stored in Mysql
There’s something strange in that download code. You’re using a foreach, but then you only upload the file once. Why are you doing a foreach? Besides, what is this Documents? A class of yours? Or an…
-
1
votes3
answers102
viewsA: Variable in PHP read by all clients
You can store the value in a file the first time you access it, and from there read the value from the file and avoid continuing to write. $filePath = "/path/para/ficheiro"; if…
phpanswered Miguel Mesquita Alfaiate 1,048 -
0
votes2
answers357
viewsA: How to avoid SQL Injection attack in this query?
This code only has SQL Injection problems if this parameter comes from user input. If this Where does not come from the browser / user, no problem. If you are user input, you should always use…
-
2
votes2
answers6293
viewsA: How to properly deploy the user after a downtime?
php code is only executed once, when the page is loaded. This doesn’t do anything: if($segundos > $limite){ session_destroy(); echo "<script>alert('Sua sessão acabou!');…
phpanswered Miguel Mesquita Alfaiate 1,048 -
7
votes2
answers8573
viewsA: Working day script
I leave here an example for counting the holidays. Note that this has not been tested, so there may be some error. function getWorkingDays($startDate, $endDate) { $begin = strtotime($startDate);…
phpanswered Miguel Mesquita Alfaiate 1,048 -
5
votes3
answers5382
viewsA: capture information from websites
It depends on the sites, it’s not something generic. You may seek information from: Sitemaps information feeds (JSON for example) Apis crawling by the pages and links of the websites other…
-
5
votes2
answers91
viewsA: PHP reads two Txts files differently
They are probably encoding differently. In Notepad++ you can see the encoding of the file and even change it. Eventually one of them is in UTF8, and the other in latin1, ascii, or something like…
phpanswered Miguel Mesquita Alfaiate 1,048 -
1
votes2
answers642
viewsA: I cannot display my database information on the page
Variables are accessed with $ before the name: $result and no result
-
4
votes1
answer92
viewsA: Does not insert data into database
Good morning. It seems to me that there may be an error causing this problem. Forms uploading files must have a definition missing in this HTML: <form (...) enctype="multipart/form-data"> Then…
-
1
votes1
answer1161
viewsA: How to send information from a dynamic form?
Well, if you can do the jQuery part, that’s a start. From jQuery you can send the values to PHP through POST in various ways, JSON, array, csv, or other. Imagining a csv, to facilitate the example,…
-
2
votes1
answer3015
viewsA: How to redirect a subdomain using the Registry DNS service.br
This implies changing the settings of the web server you use. In the case of apache, they are Virtualhosts. Here is a link from the apache website, with instructions on how to proceed:…
-
0
votes2
answers1940
viewsA: Why don’t you open some websites?
It is possible to implement javascript code that detects whether the site is being opened in an iframe. I don’t know if Google uses this mechanism, but if it does, this could be the case. There are…
-
2
votes1
answer1129
viewsA: Long Polling performance with PHP, Mysql and Ajax
Unfortunately long Polling and PHP are not good companions. For each browser that is in long Lling requesting a request, a PHP process is running. This means that not only do you have a per user…
-
-1
votes1
answer209
viewsA: Fullcalendar- Show textbox when date is selected
You can use jQuery to display a form in a popup/ modal dialog. The jQuery website has examples of usage: https://jqueryui.com/dialog/#modal-form…
-
2
votes3
answers280
viewsA: How to compare data with accents in the database?
The ideal solution is for BD to be Accent insensitive. Changing the format is feasible? It may require repopulating the database and give work, but I have happened this problem in the past and go…
-
4
votes2
answers3308
viewsA: Block direct access to a directory and create condition to free access with . htacess
The ideal is to have a forwarding to the index.php page, or another, which serves as an entry page to the site. The validation logic should be placed inside this page. If there is no $_SESSION set…