Why does PHP make me do all that Iāve literally never had to do that before. (I also have like no clue how to work with classes)
Why though?
Why does PHP make me do all that Iāve literally never had to do that before. (I also have like no clue how to work with classes)
Why though?
I believe it has to do with the fact that some other external function ends up accessing the same variable outside its scope for an unintended purpose which is what you dont want to happen.
It is quite easy to get started with, depending on what level you are:
https://www.php.net/manual/en/language.oop5.basic.php
I donāt know if it is just me but the PHP manual is very confusing to look at.
However, I was able to figure it out!
I donāt know if itās the most efficient way to do this but if you guys see anything wrong with it, please let me know. Also thank you for your help Admin.
I see no reason why try to pass the arguments to the every method (read: functions of a class)
You need to define the constructor method:
function __construct($mysql, $login) {
this->mysql = $mysql;
this->login = $login;
}
And then pass the parameters to the class:
$usrRstrcts = new UserRestrictions($mysql, $login);
And in order to call a method of it:
$usrRstrcts->banned();
On a side note: the code that you have done is vulnerable to SQL injections, take care of it using the prepared statements.
Yeah, I was thinking about that. My only problem with that is that using prepared statements adds a lot more lines to my code.
Sarcificing security for the sake of simplification is a bad idea, your choice!
Donāt worry, I only didnāt use prepared statements on this because I was lazy. For everything else, I have used prepared statements.
You can also use the mysqli::real_escape_string()
function with $login
as parameter if you really want to not add more lines to your code; the documentation is this:
I would prefer to execute the whole query in a separate method in order to prevent repeating it in all of the other methods.
Define the variable:
private $restrictions;
And put the lines regarding fetching data from the database inside the constructor method (below anything else in it) (by those lines I mean the first 5 lines of the banned
method for example) and put the results inside the variable above:
$this->restrictions = $result->fetch_assoc();
You must be the PHP OOP classes master, thank you very much for your help!
You are welcome
No problem
Iām also glad to help you out with that little I gave if I helped at all!
My site isnāt redirecting to https although I have .htaccess. How do I fix it?
Whatās your .htaccess, and whatās your site?
@ChrisPAR the day must have been busy af.
It is redirecting me, yes.
Indeedā¦
EDIT: itās still not redirected to https on my side for some reason
I checked and seems like the .htaccess
isnāt being taken in considerationā¦ Can you try using the snippet from this article instead?
Oh, also make sure itās uploaded properly.