Jump to content

kicken

Gurus
  • Content Count

    3,629
  • Joined

  • Last visited

  • Days Won

    100

kicken last won the day on January 20

kicken had the most liked content!

Community Reputation

509 Excellent

2 Followers

About kicken

  • Rank
    Wiser? Not exactly.

Contact Methods

  • Website URL
    http://aoeex.com/

Profile Information

  • Gender
    Male
  • Location
    Bonita, FL
  • Age
    33

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. You just do whatever you need to do to log them in as part of the member creation step. There's no need to make the user go through some login process. $userId = createMemberRecord(); $_SESSION['activeUser'] = $userId; After that, create your order and process the payment. Every member on your site should have some sort of page they can access that will show them their order/payment history and allow them to update their payment details / change subscription. If the payment fails, you send them to that page with an appropriate error message and a form to re-enter their payment details.
  2. If this is true, then why is there a problem? Make a users account, process their payment, and move on. If the payment fails just don't grant them any entitlement. Just because you put everything on one page for the user to enter their information doesn't mean you have to process it as an all-or-nothing thing. You can still process it as separate actions and handle any problems appropriately. For example, if the payment fails keep the account information and just send them to a payment form (similar to what you'd do for a member who's subscription is expired). You need a way for someone to be registered without an active subscription. Whether or not that user can do anything is up to you. Allowing a little bit of bonus abilities for simply registering is a common and good way to get people to hop on board. Registered users are easier to track and manage than a bunch of anonymous people. If you ever want to do something like sell ads or potentially the website as a whole having statistics about usage will be very beneficial and registered users can give you some good statistics.
  3. Free doesn't mean anonymous though, and that's the point. You should have a way for members to create an account without having paid. You kind of need one anyway for a scenario that it seems you haven't thought about yet. What happens when someone does sign up and become a member and pays your $50/year fee, but then next year decides they don't want to pay again. Now they are in exactly the situation you're trying to avoid. They have a member account but haven't paid you. Can't login because apparently that isn't allowed and can't re-register because their email is already in use. You need to accept that once you decide to start charging people money things will get more complex and you have to deal with it. The simplest thing to do is like requinix is saying and separate your registrations from your subscriptions. Even if you don't want to do that middle tier as he suggestion and keep your cut off, make the determination of what a user has access to based on whether they have paid, not on whether they have registered. This could be something simple like a HasPaid flag on their account (limited use) or more complex like a separate table to track subscription data (more flexible but more complex).
  4. I've not used any of the listed options. The couple API's I've worked on have just used Symfony since that's what I typically use for other applications. It's worked fine for me for the most part. There are various bundles dedicated to implementing REST API's that may be useful (ie, FOSRestBundle).
  5. Run their input through strtolower before comparing. You may also want to trim.
  6. I re-wrote your test script in a way that provides data that is easier to interpret (IMO) and doesn't require a database: <?php function display($memory){ $s = ''; $prev = array_fill(0, 5, 0); $headers = ['Message', 'Usage', 'Peak', 'Usage (Real)', 'Peak (Real)', 'Usage Delta', 'Peak Delta', 'Usage Delta (Real)', 'Peak Delta (Real)']; foreach ($memory as $m){ $data = [ $m[0] , fmt($m[1]) , fmt($m[2]) , fmt($m[3]) , fmt($m[4]) , fmt($m[1] - $prev[1]) //Usage delta , fmt($m[2] - $prev[2]) //Peak delta , fmt($m[3] - $prev[3]) // Usage delta (real) , fmt($m[4] - $prev[4]) // Peak delta (real) ]; $s .= '<tr><td>' . implode('</td><td>', $data) . '</td></tr>'; $prev = $m; } echo '<table><thead><tr><th>' . implode('</th><th>', $headers) . '</th></tr></thead>'; echo '<tbody>' . $s . '</tbody></table>'; } function logger($msg){ global $memory; $usage = round(memory_get_usage()); $peak = round(memory_get_peak_usage()); $usageReal = round(memory_get_usage(true)); $peakReal = round(memory_get_peak_usage(true)); $m = [$msg, $usage, $peak, $usageReal, $peakReal]; $memory[] = $m; } function fmt($size){ static $suffix = ['B', 'KB', 'MB', 'GB']; $idx = 0; $negative = $size < 0; $size = abs($size); while ($size > 1024 && $idx < 3){ $size /= 1024; $idx++; } return sprintf('%0.2f %s', $size * ($negative ? -1 : 1), $suffix[$idx]); } function getData(){ $data = []; for ($i = 0; $i < 11; $i++){ $data[] = file_get_contents('1kb.txt'); } return $data; } class DataHolder { private $data; public function __construct(array $data){ $this->data = $data; //$this->data[]='bla'; <-- I believe this will force PHP to make a new copy of the array but I am not doing so } } $memory = []; logger('initial'); $bigArray1 = getData(); logger('after creating first data set'); $bidArrayCopy = $bigArray1; logger('after copying first data set'); $bigArray1[] = 'hello'; logger('after modifying first data set'); $dataHolders = []; for ($i = 1; $i <= 5; $i++){ logger("Copy Loop $i - Before"); $bigArray = getData(); $dataHolders[] = new DataHolder($bigArray); logger("Copy Loop $i - After"); } for ($i = 1; $i <= 5; $i++){ logger("Set Loop $i - Before"); $dataHolders[] = new DataHolder(getData()); logger("Set Loop $i - After"); } display($memory); Here's the results using values similar to the 11MB size you got. +--------------------------------+-----------+-----------+--------------+-------------+-------------+------------+--------------------+-------------------+ | Message | Usage | Peak | Usage (Real) | Peak (Real) | Usage Delta | Peak Delta | Usage Delta (Real) | Peak Delta (Real) | +--------------------------------+-----------+-----------+--------------+-------------+-------------+------------+--------------------+-------------------+ | initial | 419.97 KB | 456.24 KB | 2.00 MB | 2.00 MB | 419.97 KB | 456.24 KB | 2.00 MB | 2.00 MB | | after creating first data set | 11.45 MB | 11.47 MB | 22.00 MB | 22.00 MB | 11.04 MB | 11.03 MB | 20.00 MB | 20.00 MB | | after copying first data set | 11.45 MB | 11.47 MB | 22.00 MB | 22.00 MB | 376.00 B | 0.00 B | 0.00 B | 0.00 B | | after modifying first data set | 11.46 MB | 11.47 MB | 22.00 MB | 22.00 MB | 1.05 KB | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 1 - Before | 11.46 MB | 11.47 MB | 22.00 MB | 22.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 1 - After | 22.50 MB | 22.52 MB | 44.00 MB | 44.00 MB | 11.04 MB | 11.05 MB | 22.00 MB | 22.00 MB | | Copy Loop 2 - Before | 22.50 MB | 22.52 MB | 44.00 MB | 44.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 2 - After | 33.55 MB | 33.56 MB | 66.00 MB | 66.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | | Copy Loop 3 - Before | 33.55 MB | 33.56 MB | 66.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 3 - After | 44.59 MB | 44.61 MB | 88.00 MB | 88.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | | Copy Loop 4 - Before | 44.59 MB | 44.61 MB | 88.00 MB | 88.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 4 - After | 55.63 MB | 55.65 MB | 110.00 MB | 110.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | | Copy Loop 5 - Before | 55.64 MB | 55.65 MB | 110.00 MB | 110.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 5 - After | 66.68 MB | 66.69 MB | 132.00 MB | 132.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | | Set Loop 1 - Before | 66.68 MB | 66.69 MB | 132.00 MB | 132.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 1 - After | 77.72 MB | 77.74 MB | 154.00 MB | 154.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | | Set Loop 2 - Before | 77.72 MB | 77.74 MB | 154.00 MB | 154.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 2 - After | 88.77 MB | 88.78 MB | 176.00 MB | 176.00 MB | 11.04 MB | 11.05 MB | 22.00 MB | 22.00 MB | | Set Loop 3 - Before | 88.77 MB | 88.78 MB | 176.00 MB | 176.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 3 - After | 99.81 MB | 99.83 MB | 198.00 MB | 198.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | | Set Loop 4 - Before | 99.81 MB | 99.83 MB | 198.00 MB | 198.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 4 - After | 110.86 MB | 110.87 MB | 220.00 MB | 220.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | | Set Loop 5 - Before | 110.86 MB | 110.87 MB | 220.00 MB | 220.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 5 - After | 121.90 MB | 121.92 MB | 242.00 MB | 242.00 MB | 11.04 MB | 11.04 MB | 22.00 MB | 22.00 MB | +--------------------------------+-----------+-----------+--------------+-------------+-------------+------------+--------------------+-------------------+ The reason it only goes up a bit is because the individual items between the two arrays are shared. As such the new copy only needs enough memory to store pointers to all the original row zvals + 1 more. If you did a change that would affect every row then you'd end up with more usage. The size grows by 11MB because you're calling getData and generating a new 11MB data array. When you pass that to your DataHolder object all that happens is a new pointer to the existing zval is created. On the next loop cycle getData generates a new 11MB array with it's own zval and the $bigArray pointer is updated to point to that new zval (and no longer to the one being used in the previous DataHolder object. The exact same thing happens in the second block where you pass the data directly to the constructor, you just eliminate the bigArray variable. getData generates a new zval for the array and the new DataHolder object gets a pointer to it. Notice how both blocks see a growth of 11MB per loop. The memory usage keeps growing as the script runs because your keeping all your zvals alive by way of the DataHolder objects stored in the $dataHolders array. If you were not appending them to an array then PHP would end up just re-using the memory and your usage would stay more constant at 22MB. 11MBish for $bigArray1 and $bigArrayCopy and 11MB for $bigArray. +--------------------------------+-----------+-----------+--------------+-------------+-------------+------------+--------------------+-------------------+ | Message | Usage | Peak | Usage (Real) | Peak (Real) | Usage Delta | Peak Delta | Usage Delta (Real) | Peak Delta (Real) | +--------------------------------+-----------+-----------+--------------+-------------+-------------+------------+--------------------+-------------------+ | initial | 419.97 KB | 456.24 KB | 2.00 MB | 2.00 MB | 419.97 KB | 456.24 KB | 2.00 MB | 2.00 MB | | after creating first data set | 11.45 MB | 11.47 MB | 22.00 MB | 22.00 MB | 11.04 MB | 11.03 MB | 20.00 MB | 20.00 MB | | after copying first data set | 11.45 MB | 11.47 MB | 22.00 MB | 22.00 MB | 376.00 B | 0.00 B | 0.00 B | 0.00 B | | after modifying first data set | 11.46 MB | 11.47 MB | 22.00 MB | 22.00 MB | 1.05 KB | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 1 - Before | 11.46 MB | 11.47 MB | 22.00 MB | 22.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 1 - After | 22.50 MB | 22.52 MB | 44.00 MB | 44.00 MB | 11.04 MB | 11.05 MB | 22.00 MB | 22.00 MB | | Copy Loop 2 - Before | 22.50 MB | 22.52 MB | 44.00 MB | 44.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 2 - After | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 11.04 MB | 0.00 B | 22.00 MB | | Copy Loop 3 - Before | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 3 - After | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 744.00 B | 1.14 KB | 0.00 B | 0.00 B | | Copy Loop 4 - Before | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 4 - After | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 848.00 B | 0.00 B | 0.00 B | | Copy Loop 5 - Before | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Copy Loop 5 - After | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 848.00 B | 0.00 B | 0.00 B | | Set Loop 1 - Before | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 1 - After | 22.50 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 904.00 B | 0.00 B | 0.00 B | | Set Loop 2 - Before | 22.51 MB | 33.56 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 2 - After | 22.51 MB | 33.57 MB | 44.00 MB | 66.00 MB | 1.04 KB | 1.45 KB | 0.00 B | 0.00 B | | Set Loop 3 - Before | 22.51 MB | 33.57 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 3 - After | 22.51 MB | 33.57 MB | 44.00 MB | 66.00 MB | 424.00 B | 848.00 B | 0.00 B | 0.00 B | | Set Loop 4 - Before | 22.51 MB | 33.57 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 4 - After | 22.51 MB | 33.57 MB | 44.00 MB | 66.00 MB | 424.00 B | 848.00 B | 0.00 B | 0.00 B | | Set Loop 5 - Before | 22.51 MB | 33.57 MB | 44.00 MB | 66.00 MB | 424.00 B | 0.00 B | 0.00 B | 0.00 B | | Set Loop 5 - After | 22.51 MB | 33.57 MB | 44.00 MB | 66.00 MB | 424.00 B | 848.00 B | 0.00 B | 0.00 B | +--------------------------------+-----------+-----------+--------------+-------------+-------------+------------+--------------------+-------------------+ I'm not sure why the (Real) values do what they do. Their value depends on whether your running the script in a fresh instance of PHP (ie in CLI/CGI) or reusing an existing instance (ie, FastCGI/FPM).
  7. It is, as that's the only way you'd get that error. Your other call just may not be explicit which is why you can't find it. It's also why I provided a few hints toward what the problem most likely is, but you haven't seemed to pick up on them yet. So l let's repeat them here so maybe you can get it figured out. Hint the first: Hint the second (with more emphesis):
  8. I pretty much gave you the code already. All you need to do is include the jQuery library in your pages and you can learn how to do that by clicking the link I provided. You'd be incorrect. Pure native Javascript solutions to many things are often either messy or long-winded (less so now than years ago, but still...), that's why libraries like jQuery have been created to make common tasks more concise. If you want a native solution, again click the links I gave you and do some reading. Then you have something to learn. We're here to guide, not give you all the answers. I've given you some sample code and links to learn more. Go learn.
  9. I am a aware of that, but I prefer solving things in code since I am not an Apache expert. I pointed that out not because I recommend using it, but so that you're aware of it and can check it. You say you get this error on one sever but not the other. That kind of situation tends to be due to configuration differences, such as one being configured as session.auto_start=On and the other being session.auto_start=Off.
  10. No It doesn't matter how many times your page is loaded. What matters is what happens in your code on each individual request. On each request, your code can only call session_start() once. If you try and call it more than once, then you get your error. If you call session_start in your main page and also put calls to session_start in files that you include into your pages then you'll call it multiple times. First from your main script, then again for each include. The easiest way to accomplish this is to literally only call it once. In other words, if you were to search all the files in your entire project for the phrase session_start(), you should only get one result. So a simple way to accomplish that would be to put your session start code into some separate file, say session_start.php then replace all your existing session_start() calls with require_once 'session_start.php'; (path adjusted as necessary). If your code is correctly structured such that your only calling session_start once, then there should be no need to check the session status prior to calling session_start, though doing so may be beneficial in case the session.auto_start php.ini setting gets enabled.
  11. Using jQuery (recommended): jQuery(function($){ $('#yourUL > li').click(function(){ console.log('LI clicked!'); }); }); <ul id="yourUL"> <li>Hello</li> <li>World</li> </ul> If you don't want to use jQuery then it's more complicated. Use functions like addEventListener and querySelectorAll.
  12. session_start will automatically determine if your starting a new session or resuming one that already exists, but this is not what your error is referring to. The error you're seeing relates to calling session_start multiple times within the same request. The function is only intended to be called once at the start of your request, which is not the same as at the start of every *.php file you have. If you want to have your separate pages that people request and not re-design your application to use a common front-end script or some framework then what you should do is have a common include file that handles your session (and other stuff as needed) and include that in each of your main entry pages using require_once. So your entry points should be coded something like: <?php require_once './includes/common.php'; //whatever else your script does And your common include would just be <?php session_start(); //whatever other common code you want This common include could contain things like your session management code, database connection code, function definitions, etc. Note: there's also a php.ini setting called session.auto_start. If you've enabled that then you don't need to manually call session_start().
  13. If you're talking about the code in your OP causing a copy to be made, then it wouldn't as posted. If you un-comment that line that appends to the array then that would cause a copy to be created. A copy is only generated when your code does something that would cause the array to be different from it's original. Simply passing it around between functions/objects doesn't do this. Side note: $stmt->execute(); doesn't return an array (assuming $stmt instanceof PDOStatement). You'd want $stmt->fetchAll(); to get an array;
  14. Indeed, you should just be filling in both columns regardless of if they are the same or not. It doesn't make sense to do otherwise. You could use COALESCE to use whichever column is not null in your sorting. ORDER BY COALESCE(s2.city, s2.school)
  15. Make your join a LEFT JOIN and add the job id condition as part of the join. SELECT menu_name, menu_price, menu_item_name, menu_item_category, b.menu_item_id, a.menu_id, d.job_id, d.menu_item_qty FROM ssm_menu a INNER JOIN ssm_menu_connection b ON a.menu_id = b.menu_id INNER JOIN ssm_menu_items c ON b.menu_item_id = c.menu_item_id LEFT JOIN ssm_menu_order d ON c.menu_item_id = d.menu_item_id AND d.job_id=27 WHERE a.menu_id = 1 On a side note, consider re-formatting your queries. Your current style is quite difficult to read, something like what I put above is much easier.
×
×
  • 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.