Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by kicken

  1. You need to use of not in when doing the equivalent of foreach in php. for (let item of config_data.excludes) { regexes.push(new RegExp(item)); } in loops over the properties of an object, not the values of an iterable.
  2. Use JavaScript to make the link work as a back button instead of a normal link back to the page. You can leave your link as it is now so users that have JS disabled will still go back, just not to the same position. HTML: <a href="previous.html" class="return-link">Return</a> Script: //Using jQuery $('.return-link').click(function(e){ e.preventDefault(); history.back(); });
  3. As you noted, Adding display: inline prevents the width: 25% from having an effect on those elements.
  4. You shouldn't be trying to save a "time remaining" value at all. That's a value you'd want to calculate on the fly when you need it based on the current time. Either save the sub_date and the amount of time they are allowed, or save an expiration date for the subscription and calculate the difference between now and that expiration date to determine the time remaining.
  5. Going back to the original statement of ending the other user's sessions, you can get PHP to do that for you by setting the session lifetime to 0 and invoking a garbage collection pass. //You must end the current session before you can change the lifetime settings. session_write_close(); //If you want to preserve your admin session, save a copy of $_SESSION $sessionCache = $_SESSION; //Make the lifetime 0 so every session is considered expired. ini_set('session.gc_maxlifetime', 0); //Re-start your admin session, GC requires an active session. session_start(); //Restore the saved $_SESSION if desired. $_SESSION = $sessionCache; //Run GC to delete other sessions. session_gc();
  6. FYI, if you're using Mysql 8.0 series you can simplify the query by using the window function. One of rank, dense_rank, or row_number would probably give you what you want. For example: SELECT name , total_received , total_donated , rank() over (ORDER BY total_received DESC, total_donated ASC) as the_rank FROM donation rd1 WHERE total_participant = 1 ORDER BY the_rank; | name | total_received | total_donated | the_rank | | ------- | -------------- | ------------- | -------- | | Dasher | 500 | 250 | 1 | | Cupid | 400 | 370 | 2 | | Prancer | 400 | 370 | 2 | | Comet | 380 | 370 | 4 | | Dancer | 200 | 510 | 5 | | Vixen | 100 | 200 | 6 | | Donner | 100 | 510 | 7 | If you're not on Mysql 8.0, you'll have to stick with Barands way.
  7. Probably you should talk to the company hosting the API as it seems your request is going through fine so if there's a problem it's likely with the data you are sending not being what they expect. They are the only ones that can really tell you for sure if there is a problem with the data. If I had to take a guess, it would be that you seem to be trying to post multiple records when they probably only expect one. If you decide you're query string, you'll see you are posting data like this: 0[id]=6653&0[participacion]=6936&0[beneficio]=cine&0[fecha]=2018-04-16+14:41:59&0[promo]=33&1[id]=6654&1[participacion]=3318&1[beneficio]=payp That seems unusual to me. What would seem more likely is that you'd send one at a time with data such as this: id=6653&participacion=6936&beneficio=cine&fecha=2018-04-16+14:41:59&promo=33
  8. Is there a particular problem you're having, other than 'It doesn't show in the network console.'? Seems like you're request is going through just fine and you're getting a response back.
  9. Exactly, because as I said: There's nothing in pure CSS that lets you go back or up when selecting, only forward and down. If you want to modify some previous element or a parent element, you usually need to get Javascript involved. Depending on how you structure your layout and your columns, you might be able to accomplish what you want by watching for :hover on the parent element and styling the child columns accordingly. For example: .parent:hover > .col { visibility: hidden; } .parent:hover > .col:hover { visibility: visible; } The problem with that is if it is possible to hover over the parent element without hovering over one of the child columns, then all three will vanish. As such, it only is really viable if you can ensure the parent is exactly the size of the three columns with no gaps between them.
  10. If just setting it to true doesn't provide any extra output, then try this: curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_STDERR, $fp = fopen('php://temporary', 'w+')); curl_exec($ch); rewind($fp); fpassthru($fp);
  11. You'll probably need to use Javascript to add/remove a class which will change the opacity of the ones you want hidden. CSS will let you select a next sibling, but not a previous sibling so there's no native CSS way to select the first and second columns when you're hovering over the third column. A simple script like this should do the trick. //using jQuery const $allColumns = $('.col'); $allColumns.on('mouseover', function(e){ $allColumns.addClass('faded'); $(e.currentTarget).removeClass('faded'); }); $allColumns.on('mouseout', function(){ $allColumns.removeClass('faded'); }); With markup that is like this: <div class="col">Column 1</div> <div class="col">Column 2</div> <div class="col">Column 3</div> <style> .col { float: left; height: 100px; margin: 0 20px; border: 1px solid black; } .faded { opacity: 0; } </style> If you want your columns to just fully disappear, you can use visibility: hidden; instead of opacity. If you want to have a faded look or transition animation then you can use opacity.
  12. The browser's network console only shows the requests made by the browser. It will not show requests made by PHP / CURL as it has no idea they even happen since that all happens on the server before the browser gets any of the page's response data. If you want to get extra debugging info about the request, you can enable CURLOPT_VERBOSE in your code. CURL will output a bunch of extra info to the browser as it does the request.
  13. That syntax works just fine. Why do you think it doesn't?
  14. Create your array of domains, then use the in_array function to check if $alloweddomain is contained in that array.
  15. Since you want "sets of images", I would say create a table for your sets of images. You could even store metadata about the set itself that way if you wanted too. create table image_set ( id int not null primary key auto_increment, username varchar(100), createdOn datetime ); create table image_set_image ( id int not null primary key auto_increment, image_set int not null, sortOrder int not null, category varchar(100) not null, image_name varchar(100) not null ); see example Each time someone uploads a batch of images, create a new set for them. Add each of the images to that set. The image_set_image.sortOrder column is just a numeric value you can use to sort the images within that set, you can auto-generated it or let the user specify it somehow. The image_set_image.category column would be your 'BIRD' / whatever value. If you want all the images to be in one category you could move this to the image_set table instead. When you then query the images for display you can then sort the results so each users images are grouped together an just auto-generate a sequential numbering system for the results. With newer mysql versions you can do this right in the query itself.
  16. If you're going to create separate cron tab entries for your jobs, you can pass them as part of the command like just like you would any other app. >setTaskCommandLine('php -f content/admin/admin_task.php "vendor_box" "selected_language" "selected_options" "selected_cid" "parsed_data" "selected_products"') You'd read them using $argv in your script. $vendor_box=$argv[1]; $selected_language=$argv[2]; $selected_options=$argv[3]; $selected_cid=$argv[4]; $parsed_data=$argv[5]; $selected_products=$argv[6]; $feed_import_helper->processProducts($vendor_box, $selected_language, $selected_options, $selected_cid, $parsed_data, $selected_products); You have to be very careful doing something like this though as if you do not properly escape the parameters you open up the potential for a user to run any arbitrary command as part of the cron job. This is one of the reasons why I suggest you do not create dynamic crontab entries and just manually create one that checks for work elsewhere. Doing it that way, passing parameters needs to be part of whatever you code for your job management setup. A common way of handling this would be to simply json_encode an array of data and save it to your file/db then have your crontab worker json_decode that data back into the necessary parameters.
  17. why do you want to try and generate a shared sequence? Why not just use random names and/or give each user their own separate sequence?
  18. If you're using mysql 8.0.19 or newer you can generate your temporary table inline like so: select userList.flower from (values row('rose') , row('carnation') ) userList (flower) left join pretty_flowers on pretty_flowers.flower=userList.flower where pretty_flowers.flower is null see example.
  19. The nice thing about Open Source Software is you could modify it to support your requirements. There are answers out there for how to make it work with MediaWiki.
  20. You should specify the full path to your php file in the cron task. Relative paths are not useful as you don't know what the base directory will be when the task is executed. Rather than adding/removing tasks from your cron file via code, manually configure a task to run at a specific interval and then have that task's code check for work either in a DB or in a file somewhere. Then have your code add/remove tasks by updating that DB/file.
  21. I usually define functions that correspond to the types/blocks in the defined file format and use those to read it piece by piece. For this, I created some readDWORD, readWORD, and readGUID functions. The GUID took a bit to figure out, and I'm still not 100% sure it's correct but it makes some sense and matches your example. <?php $file = 'test.utx'; $fp = fopen($file, 'rb'); $sig = readDWORD($fp); if ($sig !== 0x9E2A83C1){ die('Invalid file format'); } else { echo 'Valid file.' . PHP_EOL; } echo 'Version: ' . ($version = readWORD($fp)) . PHP_EOL; echo 'License mode: ' . readWORD($fp) . PHP_EOL; echo 'Package flags: ' . readDWORD($fp) . PHP_EOL; echo 'Name count: ' . readDWORD($fp) . PHP_EOL; echo 'Name offset: ' . readDWORD($fp) . PHP_EOL; echo 'Export count: ' . readDWORD($fp) . PHP_EOL; echo 'Export offset: ' . readDWORD($fp) . PHP_EOL; echo 'Import count: ' . readDWORD($fp) . PHP_EOL; echo 'Import offset: ' . readDWORD($fp) . PHP_EOL; if ($version >= 68){ echo 'GUID: ' . readGUID($fp) . PHP_EOL; } function readDWORD($fp) : int{ return read($fp, 4, 'V'); } function readWORD($fp) : int{ return read($fp, 2, 'v'); } function readGUID($fp) : string{ $time_low=readDWORD($fp); $time_mid=readWORD($fp); $time_high_and_version=readWORD($fp); $clk_seq_hi_res=read($fp, 1, 'C'); $clk_seq_low=read($fp, 1, 'C'); $node=fread($fp, 6); return sprintf('%s-%s-%s-%s%s-%s' , bin2hex(pack('N', $time_low)) , bin2hex(pack('n', $time_mid)) , bin2hex(pack('n', $time_high_and_version)) , bin2hex(pack('C', $clk_seq_hi_res)) , bin2hex(pack('C', $clk_seq_low)) , bin2hex($node) ); } function read($fp, int $length, string $code){ $bytes = fread($fp, $length); $parsed = unpack($code . 'parsed', $bytes); return $parsed['parsed']; } The file specification you linked says the file is encoded in Little Endian. The UUID RFC says the representation is in Big Endian so we read the multi-byte components as little endian then convert them to big endian for display. output Valid file. Version: 127 License mode: 29 Package flags: 33 Name count: 31 Name offset: 72 Export count: 7 Export offset: 753 Import count: 6 Import offset: 711 GUID: e484d857-00b7-4107-a58a-36ff29f6a3a5
  22. Cron is fine, you just have to use some care when implementing it. You have to devise some way of passing information to your cron job, for example by writing things out to a DB table which the cron job then checks when it runs. There will be some amount of delay between when you add the task to the queue and when then cron job next runs to process it. Running the job every minute to check for would would minimize that delay. If you're running your job every minute, you need to make sure that while one instance is processing the task, later instances do not attempt to pick up and process the same task. You'll probably want some way to re-try the task in case the instance processing it crashes and does not complete the task. Make sure you use the php cli interface to run your job and you can configure different limits. Max execution time is disabled by default for CLI.
  23. That's a symptom of session locking. You can work around that by having your long-running process call session_write_close before it starts. Assuming your long delay is an actual problem and any a symptom of poor code, there are a variety of ways to handle moving the task to a background process. Cron is a common and generally easy way to handle it. Another way is to use a job queue / message queue and separate worker services. Examples would be gearman, beanstalkd, rabbitmq, zeromq, and others.
  24. Don't try and do this manually, use a library such as PHPMailer or Symfony Mailer. There are a lot of specific formatting rules you need to follow for doing proper mime emails and it's not worth the time and effort to try and figure it all out yourself when libraries such as those can handle it all for you in an easy to use interface. For example, with Symfony mailer you would have code like this (using SMTP): $dsn = 'tls://smtp.example.com:587/'; $mailer = new Mailer((new EsmtpTransportFactory())->create($dsn)); //Create a new email object. $email = new \Symfony\Component\Mime\Email(); $email->from($from); //Set the from address //If $from is not an address you control, set the return path to one you do. //$email->returnPath('system@example.com'); $email->to($to); //Set recipient. if ($cc){ $email->cc($cc); //If you need to CC someone } if ($bcc){ $email->bcc($bcc); //If you need to BCC someone. } $email->subject($subject); //Subject line $email->html($message); //HTML Body //$email->text($message); //Plain-text alternative if you have one, or don't want HTML. if ($attachment['error'] === UPLOAD_ERR_OK){ //Attach uploaded file. $email->attachFromPath($attachment['tmp_name'], $attachment['name'], $attachment['type']); } //Send email $mailer->send($email);
  • 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.