New answers tagged

0

In your crypt alternative, you construct the salt using mt_rand. This is not recommended, because the cryptographic quality (i;e. it is not random enough) is not sufficient. This is explicitly documented: CAUTION: This function does not generate cryptographically secure values, and should not be used for cryptographic purposes. If you need a ...


0

It seems you have a fairly standard use case and you don't have a lot of experience with API's. In that case it might make sense to use one of the available frameworks which supplies you an API so you can focus on the business requirements. It also looks like a safer way to go and will give you some experience on possible implementations. The security ...


7

There is something called Copyright Law which already protects you from this. In general, if people are willing to break the law, they will probably also be willing to break whatever mechanism you put in place to prevent them from breaking the law. If you want someone to be able to run your program, you have to give them the program. There is no way around ...


-2

There is not need to store username in both table. store all details in user table. table structure should be //User Table Structure User user_id username . . //Approval Table Structure Approval user_id . . <?php //php code goes here $username = $user->username; $exist = User::where('username', '=', $username)->get(); if(!empty($exist)) { if(!...


0

There is nothing wrong with empty methods. The right way to say that a method does nothing is an empty body. I believe your feeling that empty method are ugly is just a bad point of view. An interface method which depending the case is implemented as doing something or nothing (by an empty body) is typical of hooks, which depending on the use case might do ...


0

(I'm not too well versed in PHP, but this advice should overcome language barriers) How would you test this class considering the header and the exit directives? So if that's the case, what would you be testing for this redirect method, the only option I can think of is testing if it's callable with $url and $data, is that all for unit testing? ...


-1

Of course you can. Try: $url = $_SERVER['REQUEST_URI']; //returns the current URL $parts = explode('/',$url); print_r($parts); EDIT: $url = $_SERVER['REQUEST_URI']; //returns the current URL $parts = explode('/',$url); $dir = $_SERVER['SERVER_NAME']; for ($i = 0; $i < count($parts) - 1; $i++) { $dir .= $parts[$i] . "/"; } echo $dir; This should ...


2

$a is a variable. It should be obvious from the name alone that its value can vary. The PHP interpreter treats variables as symbols, so the logic goes like this: $a = 5; // set the value of the variable symbol $a to 5 $a = $a + 1; // set the value of the variable symbol $a to the value of $a, plus 1 echo $a; // write out the value of $a The ...


0

I understand your concern that you want to keep JS code to bare minimum and rely on HTML and plain HTTP for all server calls. If your purpose is solved by doing so you can well keep out of AJAX. But it will be wrong to say that AJAX is useful only in content rich environments. Asynchronous requests not only provide a faster User Experience but are useful ...


-2

Yes it is. AJAX requests the HTTP too, but what's the best you can do it without reloading page. In example a system where you need to delete single users one-by-one it's more effective to delete them without reloading page, because you don't have to wait until page is loaded when choosing more users to delete. AJAX is more user-friendly.


0

I am not very sure about what you want from your question, but here are two methods I can think of, with the objectives to: provide optimum performance maintain flexibility through type abstraction About your method: Why did you create the pageData class? Why couldn't you store them in a dynamic object/associative array? Then create an abstract method ...


2

Of course you need to create objects somewhere. In theory, applications are divided into two parts: the business logic part - the fun parts, creating rules for behaviour by using classes together, the factories - the necessary evil, a magical place where classes are newed to create objects and wired together. Now, the business logic part is where the ...


1

Yes. Other answers are missing the fact that PHP is single-threaded and blocking. You generally process one HTTP request per process at a time. You can use more than one connection at a time if you really need to, but usually you won't. So it's perfectly fine to have a single connection per process. Now if this was, say, Node.js, then yes, you should use ...


2

It is bad practice to denormalize as you state. Depending on your search criteria, any one of the four tables could be chosen by the query optimization routine. If you are selecting on a package selected from a drop-down list, there should be no reason to add the packages table to the query as you can match the package_id in the package_durations table. ...


1

There has been some development with event loops in PHP, mainly ReactPHP, that kind of work like Node.js, by loading an environment, running an application (during the setup you may load data which you know will be the same throughout the entire application lifecycle) and then reacting accordingly on various programmer-defined inputs. The problem with PHP ...


0

In PHP there is two way to hold data. Sessions and Cookies. Depending about your application choose your mechanism. You can't use the theory of JAVA in PHP. These two are different language and different process to use. The way you can use JAVA is not same for PHP and vise versa. I don't know from which programming language background you are, but if you ...


2

There's nothing missing from the language itself that would prevent you from doing functional programming. The only thing missing from the runtime is tail call optimization, and you can actually do quite a bit of FP before hitting that limitation. What's really going to hurt you if you try to do FP in PHP is lack of library support for it. You need a ...


0

The real question here is "what is the consequence of failure?" If you delete something and it's not there, who cares? You wanted it gone anyway. If you want to insert data and it fails, what can you possibly do? Nothing, really. How, or even if you communicate errors largely depends on the fault tolerance of that transaction. Deleting something that ...



Top 50 recent answers are included