-
Posts
15,232 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Post code and error messages.
-
Create PHP for Rest API concept. Need someone review my coding
requinix replied to nitiphone2021's topic in PHP Coding Help
RewriteConds only apply to the single next RewriteRule. They are not being applied to the second one. You can combine both RewriteRules by making the trailing slash optional, as in /? Why use a _FUNC constant? Just require each file inside the switch and be done with it. if(isset($_POST['user']) != 'lung'){ Copy/paste fail? isset() returns true or false. It does not return the value so comparing it to 'lung' does not work. Make the !isset check be first, then change this check to use a regular comparison. echo json_encode($error);die(); If you are sending JSON then you need to include a Content-Type header with the value of "application/json". Additionally, if you want to include a HTTP status code like 422 or 401 then you should actually send a HTTP response code.- 1 reply
-
- 1
-
Could what be on Linux? Windows computers can find Windows computers via a method that is not DNS. I don't believe Linux supports that mechanism. So if you want Windows->Windows to work with http://computername then that should happen for you. If either of them is Linux then you'll need either a hosts file entry (for each computer wanting to access it) or an intranet DNS server.
-
Using the EXEC() function to contain an IMageMagick Command
requinix replied to Fishcakes's topic in PHP Coding Help
Best way to do what? Is that a question? Because no, I don't believe you have to install anything to use exec(): it's part of the core PHP and it's not something Linux distros separate out into installable packages (as opposed to stuff like JSON, which is "core" but often separated). -
Using the EXEC() function to contain an IMageMagick Command
requinix replied to Fishcakes's topic in PHP Coding Help
That's very much not correct. Go back to what I posted. You might be encountering file permission problems. 1. Decide what directory you want to put the thumbnails in. If you're using upload/ then I suggest either (a) upload/thumbnails or (b) changing the filenames to be like example.jpg for the original and example.thumb.jpg for the resized version, and they both go in upload/. 2. If you want a subdirectory, create it and then chmod 0777 it - or do whatever it is you did with upload/ to allow copying the file there. Because I'm 80% certain you did have to do something. Also, checking if the $_FILES "name" isn't empty is not enough. Look at the "error" and make sure it has the value UPLOAD_ERR_OK. If not then maybe there was no file (UPLOAD_ERR_NO_FILE) or there was some other problem during the upload. -
Using the EXEC() function to contain an IMageMagick Command
requinix replied to Fishcakes's topic in PHP Coding Help
Couple issues here. First is the matter of putting variables into strings. "{['filename']}" is just not going to work at all. I mean, there's gotta be a $ somewhere. Second is that you have to use the right values for convert. Because of the move_uploaded_file, you need to convert $targetFilePath. Not whatever "filename" was supposed to be. Then, just like with variables in SQL queries, you need to make sure that the $targetFilePath doesn't cause problems with the convert command. There is no "prepared commands" concept like SQL has so you have to escape it yourself - fortunately there's a built-in function to do that. $targetFilePathArg = escapeshellarg($targetFilePath); exec("convert $targetFilePathArg -resize 300x200 ./Thumbnails/testphp.jpg"); -
That statement doesn't really make sense. Are you using password_hash when storing the password? Because you need to be: not just because it's the correct thing to do, but because that is the counterpart to the password_verify you're currently using when checking the password. Gotta have both of them for this to work.
-
What's the code for saving the passwords into the table in the first place? It uses password_hash, right? Also, don't put variables into queries like you're doing with $userid. Learn about prepared statements and start using them immediately.
-
Move an input with Jquery after setting as a variable
requinix replied to Adamhumbug's topic in Javascript Help
You can't mix HTML strings and HTML elements together like that. Construct the HTML as a string if you wish, if that's easier to do, but you'll have to .append fn and whatever into it separately. For example, var row = $("<div class='row'>...</div>"); row.find("label[for='basic-url'] + div").append(fn); $(".content").append(row); -
Given that browsers tend to decide for themselves whether to use a cached version of a page or not (though you can influence that), the most reliable method would be to do two things: 1. Randomize the order of questions in a reproduceable way. shuffle() is always random and you can't control it, but if you moved the randomization into your SELECT query (which is possible) then you could get the same "random" ordering every time. You would then need some identifier in the URL that you can use or turn into a number suitable for this purpose. Exactly how depends. 2. Instead of telling people to go back, give them a link to click to "return" to the questions. This is a great idea because not only do you eliminate the Back button problem, you can give people a link that shows what their answers were and which ones were correct or incorrect. (If you want to.)
-
Updating Textbox2 based on Textbox1 Autocomplete
requinix replied to Moorcam's topic in Javascript Help
Stop that. Do it now. It does not have to be all-or-nothing, it's okay if older parts of your code don't and the newer parts do. Like Barand's code shows, it's easy to implement. No excuse for not doing it. -
Help with statement to select row where dates previous to today.
requinix replied to Robbiez's topic in MySQL Help
Well there's your first problem. Store it as an actual DATE and format it when you display the value to the user, then working with it in your SQL will be much easier - and faster, more efficient, using fewer system resources, etc. -
Updating Textbox2 based on Textbox1 Autocomplete
requinix replied to Moorcam's topic in Javascript Help
$query = "SELECT * FROM locations WHERE location_name LIKE '{$_GET['term']}%' LIMIT 25"; Stop that. You have mysqli so use its prepared statements. If you want the phone number to show up somewhere then you're going to have to return it with your AJAX. Look into the documentation for your autocomplete plugin to see how you should proceed. For example, one possibility is that your AJAX (autocomplete.php) returns an array of [location_name, phone number], you tell the plugin that it should use the "location_name" value, and you provide a callback function when an entry is selected so you can take the phone number and set it in the textbox. -
CSS Switcher works local but not online
requinix replied to MartinBurrito's topic in PHP Coding Help
The error message says it's switch.php and that you're starting the session on line 10. That doesn't match up with what you've posted. -
If you want to take the value "2021-06-21 01:00" and get the time portion then look at strtotime and date.
-
Is that what you want to do? Access it through http://computername?
-
Have you set up DNS inside the network yet? Do that, and add a DNS entry for the site.
-
1. Figure out which one was just submitted. Best method would be to create the location, note the location ID (you have an ID, right?), and check $r for a match (after you've added that ID column to the query). 2. As you output <option>s, mark the new one as selected. <option data-location_name="..." data-location_phone="..." value="..." selected>
-
PHP 5 code not running in commandline, runs in browser in PHP 7.2
requinix replied to paul_97's topic in PHP Coding Help
If you have errors then the solution would be to fix those errors, wouldn't it? -
Debug_backtrace notice-what’s causing it in my code?
requinix replied to dwest100's topic in PHP Coding Help
next() operates on array variables. You are trying to give it an array that is not a variable. It's trying to get the second item in that backtrace array. Use regular array offset [ ] notation instead - yes, you can do it right after a function call. -
Yes to the Database/Entity stuff, yes to the constructor. Maybe yes to the composition. See what Doctrine wants you to do. The whole point of separating Database/Entity from Business is that your database classes don't need to fight against your ORM. So the question is not what you think you should do but what Doctrine says you should do.
-
Impossible. The only way is_uploaded_file will return false is if you give it a file path for something that is not $_FILES[something]["tmp_name"]. Which, if it happens, is a sign that the code is very fundamentally broken.
-
Nope. At least not the typical image formats - I wouldn't be surprised if SVG could do that, but that's a special image format that doesn't work like the others. It's all about compression. Raw images aren't, JPEG images use algorithms that are very well suited to photographs but will lose some information to do that, PNG images compress in different ways that don't lose information, and so on.