-
Posts
15,288 -
Joined
-
Last visited
-
Days Won
436
Everything posted by requinix
-
URL rewriting does not affect what happens in <a> links. You have to write those with the URLs you want. <a href="/detail/4">
-
Loop through line items (Stripe) pulled from database
requinix replied to tunnelboy's topic in PHP Coding Help
[ ] is shorthand for array( ) so the thing at the top is an array. Which is good because arrays are easier to create than objects. You can use that syntax for your own arrays if you want, or if it helps you can edit the sample to use "array("s instead. Look at how the array structure you need is set up: 1. line_items is an array of items 2. Inside the array is another array 3. That inner array has a price_data and a quantity 4. The price_data is an array with a currency, product_data, and unit_amount 5. product_data is yet another array with a name and description To mirror that, 1. Create a $line_items array 2. Put inside it more arrays, which you'll be getting from your database 3. Each item has an array - let's call it $line_item - with price_data and a quantity. You already know the quantity. 4. There's only the one price_data, so you could use a variable or you could put it directly inside your $line_item, and it has currency (presumably always "USD") and unit_amount (the price per item) and the product_data 5. There's also just the one product_data, and it has a name (which looks like a sku) and a description (which is obvious) -
PHP OOP classes, abstract classes, interfaces and traits
requinix replied to Borkg85's topic in PHP Coding Help
In no particular order, and not restricting my commentary to just OOP issues or your question of compactness, - Inheritance represents an "is a" relationship. When you say "class X extends Y" then that means "X is a Y". It seems like Dbh is a database connection class. Would you say that Products "is a" database connection? I would not. - PHP supports types for function arguments and return values. Use them. Types on class properties are generally a good idea too but they come with some nuances to consider. - I don't think "price", "weight", "height", "length", or "width" are strings. - It seems ridiculous that everything with a weight must be a book, or everything with a size is a DVD, or everything with a height is a fur. - Your methods to get a book/DVD/fur have nothing to do with Products. You don't use the Products class for anything besides as a place to put these methods. - Catching exceptions and then returning their error messages is... not good. If you are not going to actually handle the exception then do not use try/catch at all. - You have interfaces and traits but aren't using them. - If your Product's sku, name, and price are private and you don't provide any setter methods then how are those going to get values? - It might make sense considering the weight/size/height problem, but since multiple traits cannot redefine the same method, your Withsize and WithWeight traits are mutually exclusive. - What you're doing when you call the setter methods is not correct. Having gone through that, I would say that you're not at the point where "compactness" should be a concern. In fact, compactness is almost never a thing that should be concerned at all. Focus more on whether your designs and architectures make logical sense: if they do then you will have compact code. -
Your code does not make sense. The price in your <select> has nothing to do with YouTube or Facebook. You also seem to have no idea how getElementById works or what window.location.assign does. And the markup with the <option>s is confusing. You need to learn about things before you can use them. <form id="abc"> <select name="foo"> <option value="bar" selected>Bar</option> </select> </form> <script> alert(document.getElementById("abc").elements["foo"].value); </script>
-
Since your example does not make sense, I'm going to guess you don't actually want to do this and just need something to demonstrate your question. The most obvious option here would be to change the target of the link when you change the value of the SELECT: give the button an ID and modify its HREF. <a id="buynow" class="btn-main" href="#">Buy Now</a> document.getElementById("buynow").href = "https://www.youtube.com"; Another option is to use the change_price() function to literally browse to that URL, using window.location. window.location.assign("https://www.youtube.com");
-
If you want to use Laravel for something then you install just laravel/laravel and Composer will get the other dependencies - unless it can't reach GitHub in which case yes, you have to download all of those separately, and then download all of their dependencies, and so on. That is not going to be fun. And what about mpdf?
-
Composer needs to do other work besides just download from GitHub. If you can download it yourself manually then you should be able to put it on your computer somewhere and tell Composer to read from it instead of GitHub. I forget the exact method but I believe you put a custom "repository" in your composer.json.
-
Using PHP-FPM 5.x and then 7.x?
requinix replied to Shohreh's topic in PHP Installation and Configuration
Which binaries do you expect? The ones for Apache support? The FPM daemon? FastCGI? Just the CLI? Debian/Ubuntu separate PHP into multiple subpackages. "php5.6" is a metapackage with only a handful of files itself. You typically install the more specific packages in addition/instead. nginx and php-fpm are separate. You install and configure both individually. Apache and mod_php are not separate because that approach has PHP as an Apache module so they're directly related. It's the traditional configuration, and one that's mostly fallen out of favor. -
Using PHP-FPM 5.x and then 7.x?
requinix replied to Shohreh's topic in PHP Installation and Configuration
Wow, it's so old it claims to be compatible with PHP 6. If you're starting from PHP 5.x then you're probably around 5.3 or 5.4. Going to 5.6 as the next step is good and probably won't be too bad. Going to 7.4 is a significant leap that you may want to split into 7.0 first and then 7.4 after. Because breaking the upgrade process down into steps like that helps make it manageable - going from 5.x directly to 7.4 could easily be a tough slog that will take a long time without the end in sight. I assume there's more than just installing the most recent version of phpBB? Which is apparently still in active development? -
The query is going to be very much invalid and thus won't run. You've also got PHP syntax errors, and if you're seeing a white page then you don't have error logging and/or displaying set up. Use prepared statements.
-
Using PHP-FPM 5.x and then 7.x?
requinix replied to Shohreh's topic in PHP Installation and Configuration
Do you actually have both php5.6-fpm and php7.4-fpm available to install? -
VS Code - Open PHP in Browser Extension
requinix replied to ajaxStardust's topic in Editor Help (PhpStorm, VS Code, etc)
I don't follow: you're talking about /usr/bin/php but the error message is talking about google-chrome. If you're running things in the browser then the path to PHP doesn't matter. Unless you want to use its development server, but I don't think that's the case. So what's the problem here? -
We aren't sitting at your computer watching you work. We have no idea what it's doing or what you expect it to be doing. Saying it "doesn't work" is helpful to you but doesn't mean anything to us. What is "not working"?
-
Problems matching with preg_match on Swedish characters ÅÄÖ
requinix replied to ChrisFredriksson's topic in Regex Help
https://3v4l.org/ddIcd Is your $variable using UTF-8 encoding? -
Any errors in the browser console? Can you see in the developer console the browser making a network request to shipline.php?
-
You made it more complicated than it needs to be: /[A-Z]/
-
Single sign-on means one place that you use to log in. It does not necessarily mean that you use it to sign in once and then nothing has to ask for your account again. In fact it shouldn't: the place with your account should be asking you each time whether you want to allow $app access to your account. If you coded the account stuff yourself and you're being asked multiple times then it means your app is not remembering you. If you wanted, you could have it remember you (like with a cookie) so that next time all you'd need to do is click a button to allow access. One way or another, you really should make sure that you have to click a button or do something - don't make the authentication completely automatic when a different app wants you to sign in. For example, in addition to remembering you, your site can also remember which apps you've allowed access to: if the same app wants access then that could be automatic, but if a different app wants access then your site should tell you first.
-
That's not headers. You have something in place that is preventing the request, and you're the only one who would be able to find out what it is. Check your server or PHP logs for a hint. In the meantime, 1. Why use POST if you're not sending anything? Use GET. 2. XMLHttpRequest is so last decade. Use fetch.
-
I can't tell what you're describing. Screenshot? Is this viewable on the internet right now?
-
Best way to add noindex header tag to robots.TXT files
requinix replied to Abhishekdhruw's topic in PHP Coding Help
Impossible to know from just the code that you posted. It depends how get_robots_data is used. To be clear, here. You're talking about making /robots.txt itself noindexed, right?