How to protect a direct download link in a Laravel API

I’m new to Laravel and I’m trying to protect some file downloads trough Laravel.

All I’ve read about it is about sending files as “blob” but this solution has issues when I download Blob in my React App: some files stop the download before the entire file is received.

The methode I used

return response()->download($file, 'Test File', $headers, 'inline');

Thanks for the help

How can I merge just parts of a PHP array?

I have a system that should forward incomming SMS to email. (Currently the script just forwards the file as is… Not very elegant.)
This system deals with a text file with multiple lines. I read it with file() directly into an array. The top few lines have a format as below, and I want to pick some parts out and format them into the email. The message is at the bottom of this text file, and may be over several line including blank ones.

How do I merge just the last few parts (message lines) of the array not knowing the number of lines that it has in total? I think I know which line to start at…

From: 479064xxxx
From_TOA: 91 international, ISDN/telephone 
From_SMSC: 479200xxxx
Sent: 22-02-09 13:34:05
Received: 22-02-09 12:34:29
Subject: GSM1
Modem: GSM1
IMSI: 2420266xxxxxxxx
IMEI: 8643940xxxxxxxx
Report: no
Alphabet: ISO
Length: 5

Actual message comes here!

How to check if at last post and navigate to first post

I have page arrows (Previous and Next ) on every single post however when I reach the last post I want to still keep the Next button which will link to the first post and vice versa if I’m on the first post I want to keep the previous button which would link to last post.

This is my .twig file which currently simply navigates to next or previous post if there is one.

<div class="post-prev">
    {% if post.prev %}
          <a href="{{ post.prev.link }}">Previous</a>
    {% endif %}
</div>
<div class="post-next">
    {% if post.next %}
          <a href="{{ post.next.link }}">Next</a>
    {% endif %}
</div>

and my PHP file which orders posts by date.

$context = Timber::get_context();
$context[ "main_menu" ] = new TimberMenu('main');

$context['page'] = new TimberPost();

$args = array(
    // Get post type project
    'post_type' => 'post',
    // Get all posts
    'posts_per_page' => -1,
    // Order by post date
    'orderby' => array(
        'date' => 'DESC'
    )
);

Dynamic Loading Interface Until The Data Is Processed

I am writing a php program that takes URL as input from the users and finds out the dead links from that webpage of the URL. Sometimes, if the webpage is too big then my execution speed of the program takes some more time. So how can I make a dynamic interface like loading (until the data program is fully executed)?

Symfony 5: 500 errors are not catched in prod environment

I have a strange problem in a symfony 5.3.10 app and i can’t wrap my head around it.

If i trigger a 500 error, like so:

/**
 * @Route("/", name="pvr_index", methods={"GET"})
 */
public function index(): Response
{
    echo $a;

Where $a is not defined, in dev environment i get a nice error page.

I’d expect that in prod i would get a not so nice error page that just tells me that i have a 500 error. And this would happen correctly until some time ago, when something changed, but i don’t know what.

Now instead i get no error, not even in the symfony server console, and the script execution would keep on going like nothing happened.

What i tried:

Adding the supposed exception inside a try/catch:

try {
        echo $a;
    }
    catch (Exception $e)
    {
        dump($e);
        die();
    }

Nothing happens, the catch isn’t triggered.


Creating an exception listener:

In services.yaml i have:

exception_listener:
    class: AppEventExceptionListener
    tags:
        - { name: kernel.event_listener, event: kernel.exception }

And in ExceptionListener.php i have:

class ExceptionListener
{
    public function __construct(Environment $engine) {
        $this->engine = $engine;
    }
    public function onKernelException(ExceptionEvent $event)
    {
        dd($event->getThrowable()->getMessage());
    }
}

Still nothing happens, the listener isn’t triggered.

Everything works as expected in dev environment, the problem presents itself only in prod.

Looking at a phpinfo(); page i see that the error reporting is enabled, so i think that the problem lies in the symfony configuration.

I’m using php 7.4 and have no real access to the php.ini file

How do I cache a page with file_get_contents?

I’m pretty new among you.

How do I cache a page with file_get_contents?

$site = file_get_contents('https://price.mysite.com/gold.php');

echo $site;

How can I print the output of this page to the cache file?

I want to show prices found here on another web page. Prices are updated every 30 minutes. On the page I will create, I want to use cache instead of constantly querying here. How can I do that?

Develop Webapplications for SAP S4 HANA without UI5 Framework [closed]

I’m looking for a smooth way to develop simple webapplications for SAP HANA without using UI5 Framework.

I know the common way to develop Fiori Apps is using either the Business Application Studio or Visual studio. Both require the SAPUI5 Framework, both consume OData Services and both are most likely based on CDS Views.

I want to avoid this “common” way because it requires a deeper knowledge of above mentioned technologies, which i currently don’t have.

My solution so far is using an external webserver, communicating via SOAP webservices and just point to that webserver when clicking the Tile in the Fiori Launchpad.

enter image description here

Is there an alternative to SAPUI5 for Fiori App Development, that does not require an external webserver?

php7.4 unable to read memcached data saved by pylibmc

I keep getting these errors trying to read memcached variables stored by python3 scripts runnnig pylibmc.

PHP Warning: Memcached::get(): could not decompress value: unrecognised compression type in xxx

I’m saving some test data using this python3 script:

#!/usr/bin/env python3
import json
import pylibmc

mc = pylibmc.Client(["127.0.0.1"], binary=True, 
     behaviors={"cas": True, "tcp_nodelay": True,"ketama": True})

mc.set('testvar', json.dumps('{"greeting": "Hello", "title": "Mr"}'), 3600)

Using telnet to fetch the variable from memcached shows the data is NOT compressed, but saved in clear text:

ubuntu@server:~/bin$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
get testvar
VALUE testvar 16 81
"{"greeting": "Hello", "title": "Mr"}"
END
^]
telnet> quit
Connection closed.

I have set the compression limit in the php-memcached settings to a huge number:

/etc/php/7.4/cli/conf.d/25-memcached.ini contains:

extension=memcached.so
; You need to install php-igbinary package to use igbinary serializer
; and php-msgpack to use msgpack serializer
memcached.serializer=php
memcached.compression_threshold=9999999999

The PHP script trying to read the data:

<?php
    echo ini_get("memcached.compression_threshold") . "n";
    $mc = new Memcached();
    $mc->addServer('localhost', 11211);

    $data = json_decode($mc->get('testvar'));
    echo $data;
    echo "n";

?>

and the output:

9999999999
PHP Warning:  Memcached::get(): could not decompress value: unrecognised compression type in /home/ubuntu/bin/memcache_get.php on line 6

This is on a freshly installed Ubuntu 20 LTS system with python 3.8.10 and pylibmc Version: 1.6.1

Any hints anyone?

Issues with Posting System PHP

Now, I have a posting system. There’s an input field and a submit button. After entering something in the field and clicking the button, it gets displayed as a post.

Now, let’s say you make multiple posts (two or three), all of them should be the same (except for the body of the post). However, the issue I’m encountering is that the first post has a background-color of Silver (#C0C0C0), but the second or third posts don’t. However, the body, and other content in the post such as the like and comment buttons are there.

To fix this, I inspected the first post and it highlighted only the first post, not the second or third posts, when I hovered over the post div in the console. The posts should have a background color of silver, and if you have multiple posts, there should be some white space in between the posts. But if I increase the height of the background-color, it covers both the first and second post, without any white space. And when I did this (increased the height of the background-color) of the post and inspected the second post, it highlighted both the first and second post as <div class="textPost">, without any white space in between the two posts. I want there to be if, someone enters more than one post, the posts should have white space between them, and it should be like there’s multiple separate posts, and all the posts have a background-color of #C0C0C0 (Silver). How can I accomplish this? Please help.

Code:

<div class="textPost">
  <?php

  $sql = "SELECT * FROM posts";
  $result = mysqli_query($connection, $sql);
  if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {

  ?>
  <div class="textpostFormat">
    <-- All the post content (body, like button, comment button, etc.) -->
  </div>
  <?php

  }
}

  ?>
</div>

<style media="screen">
   
.textPost {
  margin-top: 170px;
  width: 650px;
  height: 400px;
  background-color: #C0C0C0;
  position: fixed;
  margin-left: 685px;
  border-radius: 15px;
}

.textpostFormat {
  margin-left: -640px;
  position: fixed;
}

accepts form even if 1 input is invalid php

I’m trying to make a simple registration form but, when I input a first name as a “123” or leave it blank and the last name having a normal string w/o nums, the form still accepts it as a valid data. but if I enter the “123” at the last name but a real name on the first_name. I get the appropriate response for this. any idea?

$_SESSION['errors'] = array();
    if (empty($_POST['first_name']) || is_numeric($_POST['first_name'])) {
        $_SESSION['errors'][] = "Invalid First Name";
        header("Location: index.php");
    }
    if (empty($_POST['last_name']) || is_numeric($_POST['last_name'])) {
        $_SESSION['errors'][] = "Invalid Last Name";
        header("Location: index.php");
    }
    else {
        header("Location: process.php");
    }

I want create a single php product page for all products

I’m trying to create an ordering website and I want to link all products to be ordered to one page where the customer will need to fill in some form for delivery, displays the particular product details which the customer clicked on to order.

 <?php session_start();
 include("menucon.php");

  $result = mysqli_query($conn,'SELECT * FROM appetizers WHERE id = 
  "'.$_GET['appetizers'].'"');

   foreach ($rows as $row) ;

  ?>

this the product details page view

   <section class="sec1">

  <div class="p-img">
  <h2 class=""><?php echo $result['food_name'];?></h2> 
   <img src="../images/<?php echo $result['newImageName'];?>" alt="">
  </div>
  <div class="p-desc">
      <h5>WHAT TO EXPERT</h5>
    <p><?php echo $result['description'];?></p></div>
   </section>

This is for the page for all products to be ordered

             <div class="col">
             <div class="bx">
                <img src="images/<?php echo $row1["newImageName"]; ?>" alt=""> 
                <div>
                    <h3><?php echo $row1["food_name"]; ?></h3>
                    <h3> <s>GHC<?php echo $row1["discount"]; ?></s> GHC<?php echo 
                 $row2["price"]; ?></h3>
                    <p class="desc" >
                        
                For Each
                </p></div>
                <a class="btn1" href="ord.html">ORDER</a>
                
              </div>
            </div>
           <div class="col">
            <div class="bx">
                <img src="images/<?php echo $row2["newImageName"]; ?>" alt=""> 
                <div>
                    <h3><?php echo $row2["food_name"]; ?></h3>
                    <h3> <s>GHC<?php echo $row2["discount"]; ?></s> GHC<?php echo 
                $row2["price"]; ?></h3>
                    <p class="desc" >
                        
                Full Set, Extra Cost For More
                </p></div>
                <a class="btn1" href="ord.html">ORDER</a>
                
            </div>
          </div>

Can’t call public method inside the action of the hook of the cron schedule wordpress

i added the cron job as the following and the action method called from the class which class is a custom payment gateway..

function cronJobSchedule() {
     
            return array(
                'in_per_minute' => array(
                    'interval' =>60,
                    'display' => 'In every custom Mintues'
                )
            );
        }
    
    
    /* Add Cron Job Event */
    register_activation_hook(__FILE__,'registerCronJob');
        
    //Schedule Cron Job Event-in_per_minute-every_minute
    function registerCronJob() {
            
        if ( ! wp_next_scheduled( 'cronPerMinutes' ) ) {
            wp_schedule_event( time(), 'in_per_minute', 'cronPerMinutes' );
        }
    }

    //trigger action based on period in minutes
    add_action( 'cronPerMinutes',array('plugin_name','action')  );

    //remove schedule event on deactivate
    register_deactivation_hook(__FILE__, 'unRegisterCronJob');

    add_filter( 'cron_schedules','cronJobSchedule');
    
    function unRegisterCronJob() {
        wp_clear_scheduled_hook('cronPerMinutes');
    }

and the action method in the class:
public function action()
{
  $orderObj = new WC_Order(50);
  $authenticationToken=$this->getAuthenticationToken();
  $orderObj->add_order_note($authenticationToken);
}

the problem that i can’t call any method ($this->getAuthenticationToken()) in this action hook … it doesn’t work!! when i call any method.