Jump to content

requinix

Administrators
  • Posts

    15,229
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. What about states other than Florida?
  2. Variables defined outside of functions are not available inside of functions. You need to use function arguments to get values in, then return whatever single value you want out of it.
  3. array_merge will renumber arrays if they have numeric keys. Are your product_codes numeric? Honestly, all that code is far more complicated than it needs to be. You're checking if the product_code exists in the cart so you can update its quantity, and then you run a loop over everything in the cart? And when you want to add the (new) item to the cart, you use array_merge instead of just adding the item directly to the cart array? Try spending some time thinking about what's happening in there and whether there's any way you can reduce the number of lines to, say, half of what's there now.
  4. Precedence is like automatic grouping with parentheses. You know how multiplication has higher precedence than addition? That's why 1 + 2 * 3 is 7 and not 9: because it's like 1 + (2 * 3). Since ?? has higher precedence, the statement seems like it should do return ($cache[$class] ?? $cache[$class]) = new $class;
  5. Oh. About shortening code, it can go one step further: static $cache = []; return $cache[$class] ?? $cache[$class] = new $class; If you want to have a good time, figure out how that works. If you want to have a really good time, figure out how that works given that ?? has higher precedence than =
  6. +1 to $cache. Because that's what it is.
  7. Splunk should be returning to you XML, not text. What is a sample of the XML? There's a better way to search for the DHCPACK than regular expressions.
  8. Do not optimize for memory unless you're running in a constrained environment. Which you aren't. PHP is perfectly capable of cleaning up unused variables. This design pattern is fine as long as you're using it for the right reason: because each $unit/$class should only ever be created once (in this context) and it's acceptable, if not desirable, to reuse instances in multiple places. Without knowing your usage, I would expect that it's better not to use a registry/singleton pattern like this, and that you should be creating and destroying data as needed. Also: that's not a stack so don't call it one.
  9. Let me pull out the PHP code and narrow it down for you: ?schoolname={$school_page}?action=add
  10. <form action="student_order.php?schoolname=<?php echo $school_page; ?>?action=add&product_code=<?php echo $product_array[$key]["product_code"]; ?>" method="post"> Take a very, very close look at that line.
  11. The easiest option is to split your file into two parts: one for all the content before the external_block (including the opening tag for it) and one for the content after it (including the closing tag). Put each into a function. Then your regular scripts include this common file, call the first function, output what they want, and call the second function. To pass information into the header, like the title of the page, use function arguments.
  12. Multiple possible issues here, but to aim for the one that's on-topic: You cannot redirect and output a message at the same time. Only one can happen. I don't know your application or how this script is being used, but my first suggestion would be to forget the redirect and instead show a whole HTML page with the message.
  13. I feel like I need to emphasize the last thing I wrote a little bit more. By using URLs like /ClientOrganizationName, where you have only one "segment" of the path, you are limiting what you can do in the future. Anything else that's one segment will look like a company name. That means you can't do stuff like /about or /Contact-Us because those will look like companies. You should namespace the URL so that you can safely dedicate the entire pattern to companies without worrying about it conflicting with anything else. Doesn't have to be complicated. I'm thinking like /shop/ClientOrganizationName: you're able to add a new keyword in there and it's still easy for anyone to understand.
  14. You can definitely do /ClientOrganizationName being treated as /productpage.php?companyName=ClientOrganizationName. Note the two names are the same. The concept is called URL rewriting and there's a lot of information on the internet about it. What you do is tell your web server that requests for a URL in a certain pattern should be "rewritten" to another URL. In your case, you would tell it that a URL that is a name without any "directory" (so /Client matches but not /foo/Client or /Client/foo) takes that name and gives it to productpage.php. If you're using WordPress, IIRC it has a URL rewriting feature by itself (the web server was told that everything should go through WP, and then WP itself decides what to do) so you would tell WP that pages in that pattern should be treated a certain way. There is one restriction, though: this URL pattern needs to be dedicated to this one particular feature. Otherwise the URLs would be ambiguous.
  15. Try explaining what your problem is using paragraphs and complete sentences.
  16. [^.] means anything that isn't a period. That will include slashes.
  17. Not necessarily. I'm saying I don't know so experiment with it and find out.
  18. I don't know the answer to this one. Create a file with a non-ASCII character, make sure that you can access it through the web server (without PHP), then see what readdir() shows you.
  19. <VirtualHost *:80> If you're supporting HTTP and HTTPS, make sure you have everything on the HTTP side redirecting to the HTTPS side. So don't serve anything over HTTP except for redirects.
  20. Can I assume the rest of the site works? Did you put these rules into your virtualhost configuration or .htaccess?
  21. Don't need to delete. You can just reply and say "oh, hey, by the way, figured it out, it was ___".
  22. It's rare. It has some significant problems, and is only really excusable when you have absolutely no other choice. And there's always another choice. For the most part you should be storing the content in a representation-agnostic way. Meaning no HTML. For example, Markdown is popular because it allows an author to dictate structure (like headings and lists) without saying exactly what they look like. An application can then render the Markdown into whatever actual format, like HTML or RSS. Markdown is also a lot easier for non-technical people to read and write, and unlike HTML a malicious author cannot write anything that could compromise the website hosting the content. Your example could be written as # Page Header This is article 1's first paragraph of text. * ![some image](image.jpg "CAPTION") Side note: the page header should be separate from the content - you'll want it for <title>s and tables of content and other things. You can render it yourself easily enough. Even XML would be better than HTML (but it's not as easy to write). There are actual standards for this, but I'm too lazy to look them up for an example so <?xml version="1.0" encoding="utf-8"?> <content> <paragraph>This is article 1's first paragraph of text.</paragraph> <numbered-list> <item> <image src="image.jpg" caption="CAPTION" /> </item> </numbered-list> </content> You can transform XML into HTML with two steps: the first is writing a specific thing that an XML translation library understands (difficult) and the second is writing a bit of PHP code to perform the translation (easy). I did this once years ago as an experiment for a website. Rather fun.
  23. Remember? There's nothing to remember. Javascript is passing the value to PHP as a whole, not to a specific file. More technically, the value is in $_POST (because you're using the POST method) and that can be accessed from any PHP code regardless of which file the code lives in. It's just a reference to the character in my avatar.
  24. Virtually every single website on the internet works like this. In fact it's such a common thing, you should try looking for a tutorial on how to use PHP and databases, because one of those will cover the URL stuff automatically. $_GET (which is a variable, not a function) can give you the ID. You do a database query to find the information according to that ID. If found, you grab the data and display it on the page. (If not, you do something appropriate.)
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.