Most voted "php" questions
Use this tag when the question refers to some resource, information, or problem relating exclusively to the PHP programming language. For example: questions about classes, methods, functions, syntax and general use of this language. Do not use this tag if PHP is used circumstantially, but has no relation to the question problem. For example: do not use this tag for questions about HTML formatting, CSS or Javascript code.
Learn more…27,244 questions
Sort by count of
-
247
votes6
answers12507
viewsWhy shouldn’t we use mysql_* functions?
A very common question is why should we stop using mysql_* functions? For example mysql_query(), or mysql_connect(). I see that many people use them, or stop using them but do not know the real…
-
199
votes9
answers12451
viewsHow to prevent SQL code injection into my PHP code?
I developed a PHP page for internal use of the company I work with and only very few people use it. Through this page it is possible to make some queries, insertions, changes and removals of data…
-
123
votes9
answers13997
viewsHow to create a website without reloading every click on a link?
I’m looking to develop a site that runs all in the same file, but I’m not sure how to look for study material for this. Thus: Normal site->I’m on the Index.php page. When I click on the…
-
120
votes4
answers127987
viewsHow to make the date() function format a date in English?
In my project I’m using the function date(), however I would like it to be in Portuguese, the departure date of the moment is: Thursday 6th, I would like it to be on the same model but in…
-
117
votes3
answers57155
viewsCharset iso-8859-1 and utf-8 compatibilization problems
The 1st Image I use the charset=iso-8859-1 In this 2nd image I use utf8 I have a news system where you can paste html or text from other pages. On the page where the news are presented I use the…
-
106
votes6
answers32253
viewsWhat is the best way to create a PHP login system
I’m making a small system, and to access it, the user enters the login and password. What is the best way - safe and simple- to do the login and password system?
-
87
votes8
answers75484
viewsError - "Cannot Modify header information - headers already sent"
I have the following code using the function header() of PHP: header("location: painel.php?spv=nav/regMove"); exit; and when it is triggered reports the following error: Cannot Modify header…
-
76
votes6
answers20131
viewsDifference between single and double quotes in PHP
What is the difference between single and double quotes in PHP? Yesterday I was working with a string from a google json I used explode('\n', .. to separate a string. When I used the explode in "Mon…
-
70
votes5
answers17559
viewsMysqli vs PDO - which is the most recommended one to use?
With the mysql_* entering the state deprecated, the PHP documentation recommends using PDO and Mysqli. What do you recommend for use? PDO seems to be best suited for working with object oriented…
-
68
votes8
answers67841
viewsHow to export an HTML/PHP page to PDF
How to export an HTML page to a PDF file? Having a standard document where you can change variables within that template and then export that page to a PDF file in A4 format, without spoiling the…
-
60
votes2
answers2892
viewsPHP mixes object-oriented codes and procedural language?
I am learning PHP, and by the example I have seen on the internet there is a mixture in the coding of programs, of object orientation and structured procedures. Is that really common or am I…
-
55
votes4
answers1510
viewsWhy in PHP does the expression "2 + '6 apples'" equal 8?
I found the example funny, but the question is valid in the sense of understanding why PHP behaves this way. When we do the following example sum (an integer added to a string): $numero_macas = 2 +…
-
54
votes5
answers7178
viewsWhat is the advantage of using recursive functions?
Recently discovered the famous (or not so famous) Recursive Functions and I found the concept very interesting. However, during my reading I had some doubts regarding the use of such. What is the…
php loop software-engineering recursion encoding-styleasked 9 years ago João Paulo Vieira da Silva 1,933 -
51
votes6
answers59467
viewsHow to calculate the difference between two dates?
What is the most practical way to find the time difference between two dates in the default format used by Mysql (YYYY-MM-DD)? Ex: Date 1: 2013-12-11 Date 2: 1994-04-17…
-
47
votes5
answers28367
viewsWhen to use self vs $this in PHP?
I see it as a very frequent doubt: When should we use the self::, or the $this in PHP. Which form is best suited for use and what is the difference between the 2 situations?…
-
45
votes3
answers3408
viewsHow to find out if a hexadecimal color is dark or light?
I have a status listing that is displayed and each status has an assigned color. These colors are saved in my database in hexadecimal format. Example: #add555 I have a small problem: If the color is…
-
43
votes7
answers3681
viewsWhat are the implications of not declaring variables in PHP?
In php I can do this without declaring/defining variables: echo($foo); //resolve: vazio, sem nada $foo++; echo($foo); // resolve: 1 Using var_dump() the same gives, respectively NULL and 1. If I use…
-
43
votes4
answers53481
viewsHow to decrypt MD5?
If I have the following code $senha = md5("senha") and send it to the database $senha, it should be possible to recover this MD5 at the bank and show "password" back on an information update form,…
-
43
votes1
answer2932
viewsIs using PDO the safest way to connect to a PHP BD?
I’m a beginner in PHP and would like to know if PDO(PHP Data Objects) is the safest way to connect to a database? I also need an example of how to make this connection and enter/select data.
-
42
votes2
answers5738
viewsWhat is PHP Injection? How does it differ from SQL Injection? And how do you avoid it?
What is PHP Injection? What difference does it make to SQL Injection? How to avoid PHP Injection in my application? What are the main forms of PHP Injection type attack? Updating Observing:…
-
41
votes3
answers1787
viewsWhat does the code below (written by a Cracker) do?
Today one of the company’s websites on which I work has been hacked, as have several others who are using archaic development methods and full of security holes... The person who hacked left beyond…
-
41
votes3
answers57228
viewsWhat to use require/include/require_once/include_once?
I am developing an application in PHP and would like to know when and why to use require or include or require_once or include_once? I also noticed that you can make these shapes and it works:…
-
41
votes2
answers838
viewsWhat is the overhead of using object orientation?
In the company where I work today we are strongly encouraged to avoid object-oriented programming for both old and new projects. For old projects I agree that it is a bad practice to start inserting…
php oop performance software-architecture characteristic-languageasked 9 years, 11 months ago jlHertel 4,733 -
41
votes2
answers1150
viewsHow to count the objects present in the image with PHP?
The original photo of the bean is this: It lowers the resolution of the photo, I’ve already applied a grey-scale filter and increased the contrast to maximum to turn black and white. Then I examined…
-
40
votes5
answers10782
viewsWhat is a Mysql Transaction for?
I was studying some examples of Mysql with PHP and came across as following code snippet: try { $db->beginTransaction(); $db->query('query 1'); $db->query('query 2'); $db->query('query…
-
40
votes3
answers39993
viewsHow to implement google reCAPTCHA on my website?
I’m trying to implement the reCAPTCHA from Google on my site, and I can’t do the integration Server-Side (I use the language PHP). How can I make reCAPTCHA work, and perform the validation before…
-
39
votes3
answers859
viewsI am suffering attacks of type SQL Injection
Ever since I started an online project, I’ve been having problems with hacking, where someone is making direct entries into the database. This is what gave me the initiative to put in all the…
-
37
votes4
answers37758
viewsWhat is the difference between "&&" and "||" and "and" and "or" in PHP? What to use?
I have that question, what’s the difference between && and || and between and and or? Which one should I use?
-
37
votes2
answers2324
viewsWhy do they say using arroba to suppress errors is bad practice?
In PHP, we can suppress errors using arroba before certain expressions. This can be seen in: What is the function of@at the beginning of PHP expressions I already watched some Hangouts on PHP and…
-
36
votes8
answers7830
viewsIs giving a "SELECT" before an "INSERT" a safe way of not having duplicate records?
I have a table with a column codigo. I cannot set as primary key. In a system it receives many notifications before it checks with a SELECT to see if that code already exists in the table. If it…
-
33
votes1
answer522
viewsDoes the size of a function affect memory performance and consumption?
Does the fact that a function is higher or lower affect the performance of the application? Especially in PHP. If you need performance, it would be better to perform large or small? And memory…
-
33
votes7
answers10590
viewsHow do I know if today’s date is Saturday or Sunday (weekend) in PHP?
I want to know the simplest possible way to find out if today’s date is Saturday or Sunday in PHP. What are the possible ways to do this?
-
33
votes2
answers564
viewsPerformance in PHP: consider or not?
I see great connoisseurs here of Sopt, saying the phrase: "Want performance, forget PHP" For example, questions about PHP: "How can I improve the performance of that?" Of course we know that…
-
31
votes2
answers1282
viewsWhat does <<< EOH in PHP do?
I see it in several third-party classes. Remembering that the closure is usually the EOH, but without <<<
-
31
votes2
answers5413
viewsWork with Session without cookies to prevent session theft
When the session is started, it creates a cookie with PHPSESSID, making the ID public. Knowing that to prevent session hijacking it is best to hide the session ID from other users, then PHPSESSID…
-
30
votes6
answers10949
viewsHow to measure code performance in PHP?
To measure performance and compare two codes in javascript, I do it like this, in the browser console: // Vamos testar o código 1 console.time('teste1'); for (var i = 0; i++ < 10000;) { $('#table…
-
30
votes5
answers21909
viewsHow do I check if an email actually exists?
I made an email field for the user to register, and now I need a system to check if this email exists. I need that when the user type his email a system check if it exists, if it even has this…
-
30
votes2
answers4104
viewsWhen should I use Inheritance, Abstract Class, Interface, or a Trait?
From PHP 5.4 we have the Trait, that "are mechanisms that help (and greatly) the reuse of code, and serve perfectly to solve the problem of lack of multiple inheritance". Example of Abastrata Class…
php interface inheritance abstract-classes traitasked 9 years, 6 months ago Wallace Maxters 102,340 -
30
votes4
answers4172
viewsCreating a CDN - content delivery network
Wikipedia Networked computer system via the Internet, which cooperate transparently to provide content. CDN are usually deployed in multiple locations. Benefits include reducing bandwidth costs,…
-
29
votes3
answers4056
viewsHow to get the value of the current percentage of an upload?
I’m working with PHP, but I imagine it can be done only with javascript/jQuery. When I upload the browser shows the percentage in the status bar. I would like to take this value and create from it a…
-
29
votes9
answers30430
viewsHow to debug code in PHP?
For example, in javascript we have the console.log to debug, find out where the bugs are, etc. And in PHP, which ones would be best manners?
-
29
votes3
answers10218
viewsHow to create a real-time notification system similar to Stack Overflow?
I am developing a Help Desk system, and would like some ideas on how to create a notification system similar to Stack Overflow itself, whenever some new support is registered. I intend to use PHP,…
-
29
votes2
answers13485
viewsComposer - Autoload and PSR-0 vs PSR-4
I’m starting to study Composer and am developing a system where I separate files from the core of the application files, as follows: / root |-- /src |-- /App |-- /DBConfig |-- /Controller |-- /Model…
-
29
votes3
answers847
viewsDoes merging PHP files into one only increase performance?
I get the impression that every time I execute the command dump-autoload to generate the autoload of the classes via composer, an archive bootstrap/compiled.php is created. Within it, there seems to…
-
29
votes2
answers463
viewsWhat’s a loose comparison?
In the documentation of PHP, on the switch says: Note: Note that the switch/case does loose comparison. What is a loose comparison? And what is the difference between a loose comparison and a rigid…
-
29
votes1
answer544
viewsWhat happens in 1...1 in PHP?
On the web I came across the following piece of code: echo 1...1; Resulting in 10.1. I did the var_dump of the same and the return is: string(4) "10.1" Works with variable assignment: $x = 1...1;…
-
28
votes4
answers35105
viewsUse of ? and : in PHP
Can you explain to me what it’s for ? and : in PHP? For example in this case: public function url_format($post,$extra=FALSE) { $title = isset($post->post_title) ? $post->post_title :…
-
28
votes3
answers619
viewsTimestamp limit January 19, 2038
How to fix this bug? echo date('c', mktime(1, 2, 3, 4, 5, 2038)); Upshot 1970-01-01T00:00:00+00:00
-
28
votes3
answers466
viewsComments weigh in?
Comments weigh? I leave comments throughout my code, will influence something on the site? I’m saying more specifically in HTML, CSS, Javascript, PHP.
-
27
votes4
answers15751
viewsHow to check if an image exists in a remote URL?
In order to have the administration of a website to be performed from a server other than the one where the website is hosted, the problem of dealing with remote images has arisen. Common problems:…