Jump to content

gizmola

Administrators
  • Posts

    5,867
  • Joined

  • Last visited

  • Days Won

    139

Community Answers

  1. gizmola's post in Regex pattern with extra extension for urls was marked as the answer   
    Seems pretty cut and dry that you just need to add an OR to optionally match the "shorts/".  I don't know if the rest of the code will also return the data you are looking to scrape or not.
     
    preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:shorts/)?|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $linkurl, $match);  
  2. gizmola's post in Get a list of todays events from a recurrence column was marked as the answer   
    Without an actual spec for what the format of the output would be, here's a simple function that returns an array of the days indicated.
     
    function toDayofWeekArray(string $schedule) { $days = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]; return array_combine($days, str_split($schedule)); }  
    It's important to note that this must be a string in the database, because, if you for example have this:   0000100 from the database, and PHP turns that into an integer, the function above won't work, because your leading zeros will be lost.  It must remain a string for this to work correctly.
     
    Little test:
    $i = "0001001"; var_dump(array_filter(toDayOfWeekArray($i))); // Should return this array(2) { ["Thursday"]=> string(1) "1" ["Sunday"]=> string(1) "1" }  
    This is a simplified and combined version, that includes the filtration, and removes the left over array values:
     
    function toDayofWeekArray(string $schedule) { $days = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]; return array_keys(array_filter(array_combine($days, str_split($schedule)))); }  
  3. gizmola's post in Storing Images was marked as the answer   
    Scalability is also a concern.  Here is some food for thought.
    What is important for scalability is only the maximum number of concurrent users per second.  You need tools to help you simulate this type of load before you really can get an understanding of any potential bottlenecks or what concurrent load your system can handle and still operate.
    Assumption #1: you have a monolithic server. 
    What this means is that your application will run in a stack where everything (other than the database) will run on the same server.
    Sessions will use the filesystem images will be stored on the filesystem Database can be running on the same server or not Reverse proxy will run on the same server (assuming you are employing one). This sort of setup is typical, and has limited scalability, and suffers from contention issues when load increases.  If this is how your production will run, you at least want to learn a bit about how your setup performs as load increases.  Everything takes memory, and databases don't work well if they run out of memory or resources.  A frequent mistake people make in setting up a database is to provide inadequate memory allocation.  Databases are pretty much always given their own dedicated machine to run, for anything that isn't a hobby or non-commercial endeavor.
    Advantages to storing data on the filesystem:
    Filesystem already buffers data and is highly efficient The cost of returning data is only IO + bandwidth Stored in a database, a read of a blob requires IO + network delivery to application + network delivery to client Stored in the db, blob storge and retrieval is often non-optimal Stored in the db, blobs balloon the size of the database dataset, making database caching less effective, and can also slow down queries that touch the table(s) with the blobs in them.   In terms of security, you will need to store the files in a location that is not within web space (ie. under the webroot).  It is easy enough to write the routine you need that returns the data from a location on the filesystem. 
    Storing in a database does have this advantage, in terms of the potential for scalability:
    Making the application scalable is simpler, as you can have 1-n application servers connecting to the same database (and this is the 1st level typical of a move to a scalable architecture from what started as a monolithic app) This is another reason to start with a reverse proxy even with a monolithic architecture. Once you have app server #2 you have broken sessions You can move sessions into a database or distributed cache like memcached or redis Moving sessions into a DB can add a lot of load to the db You can use the reverse proxy to pin sessions (ie. "sticky sessions") to a specific app server.  Usually this is done using a cookie that the reverse proxy adds and subsequently uses to keep traffic coming back to the same app server once an initial connection is made. The other ways to scale an application that uses images stored on a filesystem:
    Use an NFS server or NAS appliance I've worked for a number of companies with large amounts of data and files.  In some cases, the problem could be solved with a NAS device, which servers can then mount using NFS as a client. Use a file storage service A good example of this is AWS S3. Some ISP's have their own alternative, and there are even consumer grade services like Dropbox you can make use of if you look into it.  Whether or not this is smart or feasible comes again down to the application infrastructure, but as a rule of thumb, you are more likely to have the app experience feel similar if the object storage is local/within your hosting infrastructure.  For example, if you had a server hosted by Linode, they offer an S3 compatible alternative service, and I'd look into that.   The downside here is additional costs for the storage of the assets and possibly egress costs to retrieve.  There are a lot of different "Object Storage" companies out there, and they are intrinsically scalable, so it wouldn't hurt to do some research. Take this list with a grain of salt, but here's a way to start looking at the possible vendors: https://www.g2.com/categories/object-storage-solutions  
  4. gizmola's post in Not displaying any results from the database was marked as the answer   
    The SQL statement you had was definitely wrong.  LIMIT constrains a result set, and is not a valid part of a WHERE clause.  Whatever you might have fixed, you also must have fixed that issue.
  5. gizmola's post in PHP Form Won't Send - Missing PHP for Submit Button was marked as the answer   
    As an aside, when I see code like this....
     
    $buntingRefolding = $_POST['bunting-refolding']; $firstName = $_POST['your-first-name']; $surname = $_POST['your-surname']; $emailAddress = $_POST['your-email']; //etc  
    I always wonder why.  Did they not understand PHP variables?  How to interpolate an array? 
    Well at any rate, before we can even begin to consider the issue, you need to define what "stopped working" means.   If it means that you used to get emails and you now don't, and nothing in the code has changed, the most likely culprit is that something in your hosting setup changed so that it no longer allows emails to be sent from your server (or they are being spam filtered because you don't have the things needed for a server and domain to allow.
    This code uses the mail() function, which is the lowest common denominator for sending mail, and is reliant on other MTA configuration in the OS.  There isn't a lot of visibility into what happens once the mail is dropped off to the MTA, which is a big reason that more sophisticated email libraries exist.  I don't know how old this code is, but wordpress has its own mailing function wp_mail() which wasn't used, so when you say that the other mail works, I would check that those routines were written the same way.  They might be using wp_mail() which wraps the phpmailer library.
  6. gizmola's post in Adding a where clause to query was marked as the answer   
    It also looks like you want to group the prior fulltext searches, so something like this?
     
    SELECT *, l.link_id , l.url , l.title , t.term , l.content_type , d.content , d.link_id , SUM(MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) + MATCH(url, title) AGAINST('w00t') + MATCH(d.content) AGAINST('w00t')) as `rank` FROM links l JOIN terms t ON l.link_id = t.link_id JOIN links_description d ON d.link_id = l.link_id WHERE (MATCH(t.term) AGAINST('w00t' IN BOOLEAN MODE) OR MATCH(url, title) AGAINST('w00t') OR MATCH(content) AGAINST('w00t')) AND l.content_type = 'docume') GROUP BY title ORDER BY `rank` DESC LIMIT 200;  
     
     
     
  7. gizmola's post in Mysql event didn't execute in a particular day but started to execute afterwards, how to find the root cause? was marked as the answer   
    Off the top of my head 2 possibilities that might explain the issue:
    Event scheduler was not started in server Server is UTC, and event was UTC time, leading to confusion as to when the first event should have occurred. These are just guesses, but looking at the mysql error log, looking at the events table and commands like SHOW CREATE EVENTS and SHOW EVENTS might help you.
  8. gizmola's post in Curl rate limits and time outs, limit rate under a certain amount for get requests was marked as the answer   
    What the heck is this code?
    $customer["id"]; $customer["firstname"]; $customer["lastname"]; $customer["fullname"]; $customer["business_name"]; $customer["email"]; $customer["phone"]; $customer["mobile"]; $customer["address"]; $customer["city"]; $customer["state"]; $customer["zip"]; $customer["business_and_full_name"]; $customer["business_then_name"];  
    I have no idea why you would think that adding 5ms of sleep would help anything.
    Your PDO code should be using a prepared statement.  
    Then you simply execute the statement in a loop, passing the data each time.
    It is well known that MySQL inserts are much faster if you do multiples:
    INSERT INTO Table (col1, col2) VALUES (?, ?), (?, ?), (?, ?).... This is one place where PDO doesn't have a built in solution, so you have to build your own, as Barand helpfully provided an example.  It is possible to have limits on the size of a query, but would require a lot of data.  Changing of that limit is dependent on what mysql library you are using, so I leave that to you to research.  For example, if you are using mysqlnd, then a PDO runtime parameter changing that size is ignored.
    A good hybrid option would be to create a batch system where you load an array of the values inside the outer foreach, build the statement from that array, and prepare the statement and pass the array to the bind.
    However, the first stab I would take, would be to simply do a prepare and execute loop with a single transaction.  
    $query = "INSERT INTO Customer (SyncroID, CompanyName) VALUES (?, ?)"; try { $pdo->beginTransaction(); $stmt = $pdo->prepare($query); foreach ($customers as $customer) { if (!empty($customer['business_name'])) { $stmt->execute([$customer['id'], $customer['business_name']]); } } $pdo->commit(); }catch (\Throwable $e){ $pdo->rollback(); throw $e; } Todo this type of thing effectively you need to make sure that the PDO connection has $conn->setAttribute( PDO::ATTR_EMULATE_PREPARES, false ) and $conn->setAttribute( PDO::ERRMODE_EXCEPTION, true).
  9. gizmola's post in Setting up an account on Web app was marked as the answer   
    In general, this would be called provisioning. 
    For the most part, this requires that your application have an underlying architecture that supports this.
    In terms of DNS, you can set up a wildcard DNS entry for *.myapp.com.
    Internally, your application needs code that accepts a request, examines the requested url, extracts the subdomain, and executes the routing accordingly, or you can also have a rewrite that will look for subdomains other than 'www' and rewrite those to https://myapp.com/shop1.
    When a new user creates a store, you will run provisioning code in your application that does any required setup (make new database user, create database with new user assigned rights, save credentials in user profile configuration file or in database.)  There are strengths and weaknesses to each approach so you have to consider the tradeoffs and security implications of each approach.  For example, you could just use the primary database access user, and not create a separate database user for each customer database.  There isn't one right answer for each application.  
  10. gizmola's post in Oracle SQL certification path? was marked as the answer   
    Oracle database has been around a long time, and has a lot of features and extensions that are specific to it.  If you are not going to use it immediately, or need a certification for a job, I wouldn't recommend going down that rabbit hole, even though I do think that Oracle database is a great RDBMS in many ways, but it is commercial and expensive.  You often see it paired with java/enterprise java applications.  For reasons I won't go into, besides cost, very few people pair PHP with Oracle database.   The open source database closest in design and features to Oracle is Postgresql, so if anything, exploring postgresql would be a step in that direction.
    Since you use SQL Server, I would suggest getting certs in that, and in particular, learn about the specific things you listed, like transactions and concurrency (locking), and Views, stored procedures and triggers.  Sprocs and Triggers are very important and highly used in SQL server development (Transact-SQL aka T-SQL), and in Oracle (which has an entirely different stored procedure language).  MySQL also has stored procedures & triggers, but they are not commonly used, in comparison to the way that they are very often baked into applications that use sql server on the backend, as is the case with a lot of .NET applications.
    I don't think you can really say you are confident in your SQL knowledge until you are confident in the many ways you can use joins (including self joins), and the use of grouping and aggregation, as these are some of the primary reasons people use relational databases.  It also helps to learn about the way rdbms's work in terms of datatypes, constraints and indexes.  You want to have a good working understanding of the different types of indexes and the ways they overlap with primary key/unique constraints.  You also really need to understand concurrency and locking, as it pertains to each database, and an understanding of transactions as well as "2 phase commit" support.  
    While all the major relational database engines have configuration options that can be used to alter the concurrency/locking models, MySQL (and forks like MariaDB)  is particularly different in that it allows for the use of different engines.  For example, the original MySQL engine (myisam) is very different from the popular InnoDB engine that most companies use.  It's a simple example, but MyISAM has no support for transactions, so you can write code that starts transactions and commits or does a rollback, and mysql will happily except that code, when in fact it actually ignores those statements entirely and doesn't support transactions whatsoever.  
    You also want to understand how you install and configure these databases, and what options and tradeoffs might be involved in how you set them up.  This affects how a database might/might not recover from a crash/ lose some data/transactions (or not), have backup options, or support replication in various flavors.   With the existence of Docker, it's now much easier to experiment and learn about these databases, and create local test configurations.  
    I think it helps to keep in mind, that there are categories of developers (DB Architects & Administrators & DB developers) who specialize in these products, and they have extensive levels of depth to them.  There are some well known experts with books you might be interested in.  A couple off the top of my head, are Joe Celko, who wrote some well known SQL books, and Tom Kyte, who authored many books on Oracle, and was well known for his "Ask Tom" column where he answered oracle questions and demonstrated ways certain problems could be solved.
    PHPFreaks is fortunate to have a number of developers who have consistently shared their expertise with relational database design and SQL, so this is still a great place to get advice and in many cases example code.
  11. gizmola's post in query not working as expected was marked as the answer   
    It would not work any better in Oracle, because your logic is faulty.
    Keep in mind that inside your parens, if any of those items are TRUE, then the entire group is true.
    team_name is not null or team_name !='' or team_name NOT LIKE '%[teamname]%') In the row you don't expect, consider each condition
    team_name is not null ---> true
    team_name !='' ---> true
    team_name NOT LIKE '....'  ---> false.
    So you get the row, despite the fact that the 3rd condition is false.  What it appears you really want is:
    team_name is not null AND team_name !='' AND team_name NOT LIKE '%[teamname]%')  
  12. gizmola's post in What is the purpose of the begin and end ^ and $ characters, when should I use them and what do they do? was marked as the answer   
    If you are looking for -- exactly, a line that starts ... then has something you want to match, followed exactly by the end of a line, then you may want to use those anchors.  
    Regex is integrated into a lot of different languages and subsystems, for a number of different purposes.  For example, it might be that your use case is to find, within a bunch of lines of text, a particular pattern like a phone number or a url.  
    Another use case, might be entirely different, as in the case of a password which must meet certain criteria.  In the case of a password, you would want an exact match, including the start and end anchors, whereas, if you're looking for a phone number or a url within a bunch of other text (perhaps in a forum like this one) then you certainly would not want the match to only be made including the start and end line anchors.  
    In some subsystems (apache mod_rewrite for example) the context of the data available to be evaluated with regex, already assumes start and end anchors, and actually trying to apply them won't work, so that might lead to some confusion, when rewrites don't work the way you expect.
  13. gizmola's post in Why can't I GROUP BY emp_name only in this query? But why am I able to GROUP BY orderid alone? was marked as the answer   
    The column(s) you select will generate one row(group) per unique value of that column.  
    Simple example of orders, assuming the order contained a column for the country_code of the customer that placed the order.
    You want a result with the "Total value of orders by country".
    So you would want to GROUP BY country_code.  
    Your result set will then have 1 row for each country, but a SUM(amount), of course will provide you the total value of orders for that country. 
    Let's say instead, you want a sum of orders by country, but you want the total for that country by year.  
    SELECT country_code, YEAR(order_date) as year, SUM(amount) FROM ORDERS GROUP BY country_code, YEAR(order_date) ORDER BY country_code, year At that point you're going to get a row for every country_code/year combination, and the SUM(amount) is relative to that grouping.
  14. gizmola's post in Understanding subqueries! was marked as the answer   
    Simple subquery article:  https://www.guru99.com/sub-queries.html
    A subquery is exactly what the name describes:  An inner (sub) query that is run, with a result that is then used by an outer query.  It is not complicated.
    In order for it to be used in a "WHERE column =" the subquery must return at most 1 value.  If it can return multiple rows/values, then you need to use  "where column IN" or possibly NOT IN.
    My 1st tip:  a subquery can't possibly work as a subquery, if it doesn't run by itself in standalone fashion.  You want to investigate, whether or not you can use a HAVING clause without a GROUP BY.
  15. gizmola's post in Loading Youtube video in Magnific pop up window was marked as the answer   
    Yes you are missing something obviously different, which is that you are including jquery and the magnific popup code in the wrong order AND loading it in the body rather than the head section.  Try changing it to this:
    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> Document </title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script> <script src="jquery.magnific-popup.js"></script> <link rel="stylesheet" href="magnific-popup.css"> <script> $(document).ready(function() { $('.popup-youtube').magnificPopup({ type: 'iframe' }); }); </script> </head> <body> <div> <a class="popup-youtube" href="https://www.youtube.com/watch?v=Euy4Yu6B3nU">Air</a> </div> </body> </html>  
  16. gizmola's post in rating system was marked as the answer   
    So what people are trying to say is that something must run the submit_rating.php when a review is posted.   The same script needs to be run when a page is loaded, as it returns the data you need for your page to update the numbers you want to see updated in a json structure.
    We can surmise that the way to do the ajax calls is with jquery, since jquery was included in the html you provided.
    Here is the jquery documentation.  Read through that and try and adapt their examples.  Just to simplify things for you you can focus on the $.ajax() method, as the other methods are just HTTP request type wrappers around $.ajax.
    The html page you provided needs some jquery code to:
    define the handler code you need that will submit the form data to submit_rating.php bind that handler to the submit button of the form define a function that takes the json results returned from submit_rating.php (which are the actual stored ratings) and using those to update the various places in the Dom where the relevant numbers are required.  Doing that can also be done with jquery, which has various methods to select and then manipulate DOM elements. Currently there is no code to do these things, that you have presented.  If you need to write that code yourself, then you now have a basic step by step guide as to what you need to do.  It's also a pretty standard way of doing things, although jquery has fallen out of favor in recent years as javascript frameworks like vue and react have become popular.  Neither of those frameworks are relevant to your code though.
    I will mention in closing, that it would be very helpful for you to understand submit_rating and it's dual purpose.  That script is designed both to update the statistics if the review form was submitted, and to also get the statistics, and those 2 functions are not mutually exclusive.  You must understand how to construct a POST structure in your function that is meant to handle a form submission, by getting the input from the field(s) needed and passing that in the post.  Make sure you understand how to get that code to be triggered when the form is submitted, and not triggered when it's not needed (ie when it's just a GET request to load the page).  
    Hope this helps you move forward.
     
     
  17. gizmola's post in Error message copying data from one database to another on the same server was marked as the answer   
    You are clearly new to doing queries with the php mysqli extension.
    First of all, why are you including extraneous parens and punctuation in your query?
     
    What you are doing:
    $sql= "select * from cic_remus.contacts where (id='$id');"; What it should be:
    $sql = "select * from cic_remus.contacts where id=$id"; Your problem is likely a logic issue as Kicken has pointed out, but you should also address the underlying issue for debugging purposes:
    This is telling you that you have an uncaught exception, so try surround the code with a try..catch block for that and then display the actual exception message and query next time you do this.
    try{ // sql query code } catch(Exception $e) { echo "Error: " . $e->getMessage(); }  
    I'm not sure why you are doing what you are doing, when instead you can just do a query:
    INSERT INTO cic_kenobi.contacts AS select * from cic_remus.contacts ON DUPLICATE KEY IGNORE If the tables don't exactly match (you can craft the individual values statement in the same way you already have been).  You can run this from PHP but unless you are doing this frequently, having it scripted within php doesn't have a lot of value to it.
  18. gizmola's post in how to add extension in php? was marked as the answer   
    I don't know what you found on SO, but it's unrelated to the intl extension.
    What operating system are you running? What version of php? How is your development environment configured? Are you using Docker?  
    Note: The library you are trying to use states that it is "depreciated"  (sic).  It was also forked by the originator to a different repo, with the intention of passing it on to other maintainers.
    Since you are using Laravel, this one might be a better fit for your project:  https://github.com/TechTailor/Laravel-Binance-Api
    It states it is still in alpha, but depending on what you intend to do it might be a better fit for you.
  19. gizmola's post in Meta data programmatically was marked as the answer   
    Search engines just look at the final http response data.  They have no visibility into the internals of how a page is rendered.
    There is no problem doing what you want to do, and in fact many cms's, forums and frameworks do this exact thing.
    Just to be clear, meta tag keywords are ignored by google, so you may or may not want to include those in your page rendering.
  20. gizmola's post in Adding a count to a basic player with mysql and php was marked as the answer   
    Yes, so implementing kicken's suggestion, this should work probably:
    $('audio').on("play", function(){ let requestSent = [] return function(){ let a_id = $(this).attr("id") if (requestSent.includes(a_id)) { return; } requestSent.push(a_id) $.ajax({ url: "count-play.php?id=" + a_id , success: function(result){ $("."+ a_id + "count").html(result) } }); }; }()); Hopefully you understand what this code does, which makes use of some tricky javascript concepts, namely:
    Javascript closure An IFFE
  21. gizmola's post in PHP coded button was marked as the answer   
    There's a lot to work through here, so I'll start with this:
    With CSS, always start with more general rules, then more specific ones.  You have multiple embedded style blocks here, and I'm not sure why, but your general rules were added after the specific ones Keep in mind that styles "cascade" per the name. You don't need to re-declare all the attributes for a modification.  Just use a modification class Many popular css frameworks like tailwind depend on this idea   Getting familiar with a naming convention for css like BEM will help you create clear and logical css class names and avoid pitfalls and making your css inconsistent spaghetti It also will help you keep things clear.  Use camel case for your PHP variables, and for class naming and general code formatting and style start with PSR-1 and perhaps graduate to PSR-12 It might not seem that important to you starting out, but it will help you get the most out of whatever editor/IDE you are using Most people are using either PHPStorm (the choice of most pro's) or Visual Studio code with the Inteliphense plugin installed If you go with vscode/Inteliphense make sure to read the installation instructions carefully and disable the built in plugin as directed Take a look at my changes to your css and html markup to see how I implemented these ideas on your code You rarely will want or need to use css id rules.   ID's are reserved for a single instance on an page.  For buttons, you are typically re-using those styles throughout the page, so use css classes for those and not id's Most css pros rarely/never use #name css styles.  If this is tutorial type stuff, might tell you something about the freshness of the tutorial PHP code runs on/in the PHP server.  It does not run in the browser like javascript code that is included or embedded in the html page. In other words, your PHP code will be run in response to a request, and returned immediately. You can intermix html and PHP blocks inside a php script, and that will work fine, but the PHP code needs to be in a PHP block, which starts with <?php  As you should be able to see here, you have commented out all the PHP code you wrote using html comments.  Thus none of that is going to run. There is an alternate syntax that can be used to make everything look a bit cleaner if you plan to do a lot of intermixing You can look up those options in the PHP manual.  It allows shorthand for echo, and if - then -else type constructs and other PHP loop For superglobal array variable or array keys (or any other variable that may or may not exist) you want to check before blindly trying to utilize it.  There are various language helpers that you can use to get around the situation where a variable doesn't exist. isset empty() function null coalescing operator Take care with PHP blocks inside if-then or if-then-else constructs.  In general, it's a good idea to always make sure you have a block { ... } to handle each case.   Your blocks don't look correct. Try not to chain if-then else, when instead you can use multiple if blocks.  The code is easier to read and update in most cases.    
    The issue with the code presented is that you have buttons but no form, so this invokes a lot of confusing default behavior and questions you might want to ask yourself like:
    Why/where is the form submitted? What type of submission is it? For example, if the type of submission is not a POST, can you expect $_POST variables to exist?  
    I don't address these questions for you, but I expect you will need to figure them out soon.
     
    Here's some modifications to your code illustrating these thoughts:
    <meta charset="utf-8"> <title>Work intergrated learning</title> <style> body { font-size: 30px; } p { font-size: x-large; } .btn { padding: 10px; font-size: 20px; border-radius: 10px; font-weight: bolder; transition: background-color 2s ease Os; cursor: pointer; } .btn--submit { background-color: red; } .btn--submit:hover { background-color: green; } .btn--cancel { background-color: yellow; } .btn--cancel:hover{ background-color: orange; } </style> Rest of code...
    <p>Creating a button</p> <br> <?php if (isset($_POST['btn-atc'])){ echo 'You have added an item to your shopping chart'; } ?> <input type="submit" name="btn-atc" value="Add to Cart"> <?php $btnSubmit = isset($_POST['btn-submit']); if ($btnSubmit) { echo 'Your query has been successfully submited, our consultant will get in touch with you as soon as possible'; } $btnCancel = isset($_POST['btn-cancel']); if $btnCancel { echo 'You have cancelled your query.'; } ?> <input type="submit" name="btn-submit" class="btn btn--submit" value="Submit query"><br> <input type="submit" name="btn-cancel" class="btn btn--cancel" value="Cancel">  
  22. gizmola's post in how to properly store an ip address? was marked as the answer   
    I'm guessing something like this might work for you (assuming you have a reverse proxy or load balancer).
     
    protected function getClientIP() { // This assumes a classic AWS Load Balancer is proxying if (filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && !filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { $ip = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); return $ip[0]; } else { return $_SERVER['REMOTE_ADDR']; } }  
  23. gizmola's post in How do I think about recursion? was marked as the answer   
    I should probably add that the secret to determining if recursion allows for something elegant, is to determine if you can reduce the problem down to a discrete examination.  In the case of my solution, the insight I depend upon is that I only need to check the outer 2 letter of the string in order to determine if it *might* be a palindrome. 
    Another solution using this insight could also be coded using map and reduce. 
    It also needs to be said that the overhead of recursion means that it is almost never employed, although there are some problems involving nested arrays where I see people using it in PHP.  
  24. gizmola's post in [docker] error_log() not work was marked as the answer   
    The PHP process may not be able to write to the /var/log directory.  Assuming it's the apache user that php is running as in this case.  Connect to the container and check out the perms for /var/log.  
  25. gizmola's post in How to Push an Empty Array into an Object was marked as the answer   
    And everything I wrote previously still applies.
    let json_array = {} json_array.excludes = [] // Use array method json_array.excludes.push("a") json_array.excludes.push("b") //array syntax json_array["excludes"].push("c") console.log(json_array)  
    I Updated the codepen as well with this example code.
×
×
  • 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.