How to remote control a C# interface?

I have a php code that used from multiple clients and I have another C# interface that running through a batch file.

I want to remotely control the C# interface instance of specific client (run process, kill process, restart process…) using third party that work automatically without dealing with the C# code or php code.

What are the best and simplest solutions to do that?

How To get a new Access using Laravel Socialteprovider

i’m using

I’m getting access_token and refresh_token after authentication but I want to refresh a token after its expiry, which I’m not able to find a way to do or any method in the library, any help would be appreciated.

/*Google OR Azure */

       switch ($provider) {
                case 'google':
                    $scopes = [
                        'https://www.googleapis.com/auth/plus.business.manage',
                        // 'https://graph.microsoft.com/user.read',
                        /*List of scopes to add if needed */
                    ];
                    $parameters = ['access_type' => 'offline', "prompt" => "consent select_account"];

                    break;
                case 'azure':
                    $scopes = [
                        'offline_access openid',
                          'https://graph.microsoft.com/user.read',

                    ];
                    $parameters = ['access_type' => 'offline_access'];

                    break;
            }
return Socialite::driver($provider)->scopes($scopes)->with($parameters)->stateless()->redirect();

  public function handleProviderCallback()
    {
      $providerUser = Socialite::driver('azure')->stateless()->user();

           return $data = [
                'status' => 'success',
                'access_token' => $providerUser->token,
                'refresh_token' => $providerUser->refreshToken,
                'expiry_time' => $providerUser->expiresIn,
                'auth_provider' => 'azure',
                'email' => $providerUser->email
            ];
         
    }

i have tried a couple of ways but none of them seems to work for me as below

//       $a =  Socialite::driver('azure')->refreshToken($refToken);

//        $a = (object) Socialite::driver('azure')
//            ->setScopes(['offline_access'])
//            ->getRefreshTokenResponse($refToken);

       // $a= (object) Socialite::driver('azure')->user();
        //$a= (object) Socialite::driver('azure')->getAccessToken();
       // $a= Socialite::driver('azure')->stateless()->user();
      //  $a=  Socialite::driver('azure')->userFromToken($accessToken);
      //$a= Socialite::driver('twitch')->refreshToken($storedRefreshToken) 
print_r($a);

PHP Paypal SDK with Payment Data Transfer

In Paypal developer account I have configured Payment Data Transfer settings and acquired Identity Token. (Return URL is also added)
I am using PayPal PHP SDK.
Which class and where in PHP code I can pass Identity Token?

What is the backend logic of a browser game like Ogame?

I’m doing a browser game project with WAMP, using HTML CSS PHP SQL. The game needs to display resources every second, because there is a production rate.
I won’t show any code, it’s a design problem.

I know basics of PHP, I can load/store data from DB, show it in html tags. I know Javascript/Ajax too.

But here is my problem : let’s say I use Javascript to update the resources: it works well until I refresh. The scripts relaunch after every refresh, I don’t know how to fix that.
Some people use cookies to synchronise, but then I would need to crypt them to prevent cheating with editing cookies, is that a good solution ?

I also stumbled upon websockets and server-sent event, but I’m not sure how it applies here.

Any help about using realtime features will be appreciated, thanks !
I just need to know the proper technology, so I can learn it then.

How to modify a form on Symfony

so I’m creating an e-commerce website using symfony and twig. Right now The client can enter manually the quantity he wants of a specific product, but i want that quantity to not exceed the stock we have of that product. So for example if we have 5 chairs, i want him to choose between 1 and 5.
For that i created a dropdown :

 <div class="field select-box">
                            <select name="quantity" data-placeholder="Select your quantity">

                               {% for i in 1..produit.stock %}
                                   <option  value="{{ i }}" >{{ i }}</option>
                         
                                    {% endfor %}
                            </select>
                        </div>

I want to use the selected value to put it inside a form,, or maybe find another way to set the quantity asked without using the form or even just change the way the form looks because right now it only takes input. Should i generate another form ?

Hopefully i was clear.

Here’s what my formType looks like :

class ContenuPanierType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder->add('quantite');

     
    }

    public function configureOptions(OptionsResolver $resolver): void
    {
        $resolver->setDefaults([
            'data_class' => ContenuPanier::class,
        ]);
    }
}

Use Woocommerce session variable whitout reload

I’m having a problem, a need to apply a filter when user changes the selection of an input radio, I did this code, but it only works if I reload the page, what can I do to avoid reload and the page charge the filter whithout reloading?

` add_action( ‘wp_footer’, ‘wpmc_set_session_on_button_click’ );
function wpmc_set_session_on_button_click() {

session_start();
$array_selectores = $_SESSION['array_selectores'];
$json = json_encode($array_selectores);
?>
<script>
    document.querySelectorAll('input[name="horario-liga"]').forEach(function(input) {
        
input.addEventListener("change", function(e) {
    var jsArray = <?php echo $json; ?>;
    var horarioLigaValue = document.querySelector('input[name="horario-liga"]:checked').value;
    
    var data = {
        action: 'wpmc_set_session',
        dto_manana: 'dto'
    };
    var data2 = {
        action: 'wpmc_set_session',
        dto_manana: 'no'
    };
  if (jsArray.includes(horarioLigaValue)) {
    jQuery.post(
        '<?php echo admin_url('admin-ajax.php'); ?>',
        data,
        function(response) {
            console.log(response);
            //console.log('dto');
        }
    );
    
  }
else {
    jQuery.post(
        '<?php echo admin_url('admin-ajax.php'); ?>',
        data2,
        function(response) {
            console.log(response);
            //console.log('no');
        }
    );
}
});
});
</script>
<?php
}

// Manejador de petición AJAX para establecer la variable de sesión
add_action( 'wp_ajax_wpmc_set_session', 'wpmc_ajax_set_session' );
add_action( 'wp_ajax_nopriv_wpmc_set_session', 'wpmc_ajax_set_session' );
function wpmc_ajax_set_session() {
error_log(print_r($_POST, true));
echo $_POST['dto_manana'];

WC()->session->set( 'dto_manana', $_POST['dto_manana'] );
    
wp_die();
}


add_action( 'woocommerce_review_order_before_payment', 'detectar_radio_button_seleccionado' );
function detectar_radio_button_seleccionado() {
    
$dto_manana = WC()->session->get('dto_manana');
    
if (isset($dto_manana)) {
    echo $dto_manana;
}
}


add_filter('woocommerce_cart_calculate_fees', 'add_recurring_postage_fees',10,1);
function add_recurring_postage_fees( $cart ) {

$dto_manana = WC()->session->get('dto_manana');
    
if ( (! empty( $cart->recurring_cart_key )) && ($dto_manana == 'dto') ) {
    $cart->add_fee( 'Postage', 5 );
}
}`

If I go to checkout page I get the value ‘dto’ or ‘no’ but in order review only show the value of the last session, not the actual. I need to apply add_filter(‘woocommerce_cart_calculate_fees’, ‘add_recurring_postage_fees’,10,1); when I select in horario-liga any value include in the array

stream_select(), signals and Stdin in PHP

I am trying to write a native PHP cli application which reads data (log data) from stdin and does some handling after.

I got a first working version with a simple while-Loop:

while ($line = fgets(STDIN)) {
    // Do my stuff here
}

When installing signal handling via

function signal_handler(int $signo, mixed $siginfo) {
    // ...
}

pcntl_async_signals(TRUE);
pcntl_signal(SIGHUP, 'signal_handler');

this works partly: The signals are only processed after each fgets().

I tried to use stream_select() with NULL as timeout and some other stuff, but this lead to a massive system load 🙂

Is there any best practise to use stream_select() and fgets() on stdin to read data until it’s “ready” and wait/pause indefinitely else but let signals being processed?

php open pdf in Windows and Mobile

I am using below php to open pdf, it is working in Windows browser (eg. Windows Google Chrome), but failure to open by Mobile App (eg: Android Google Chrome), it will be download instead of open.

<?php
$com_no = $_POST['comno'];
$date = $_POST["date"];
$name_of_doc = $_POST["name_of_doc"]; 



// Store the file name into variable

$file = $com_no.'.pdf';
$filename = $date."_".$name_of_doc;
  
// Header content type
header('Content-type: application/pdf');
header('Content-disposition: inline; filename="'.$filename.'.pdf"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
  
// Read the file
@readfile($file);
  
?>

How shoule I rewrite it to support both open in the Windows and Mobile ?
Thank you very much !

Larvel querying relationship existence still returns empty records

I’m working in a Laravel 9 project and need to show only records where the deeply nested relationship has records, in my case, tiers.

My relationship right now is still returning me pingtree_entries even though tiers are empty, what am I missing?

Here’s my top level query:

$pingtree = Pingtree::where('company_id', $company_id)
                    ->where('id', $id)
                    ->has('pingtree_entries.tiers')
                    ->with('pingtree_entries.tiers')
                    ->first();

This should be saying something like:

Get me my Pingtree by company ID and ID with my tiers associated to the pingtree_entries for the Pingtrees where there is more than 0 tiers.

My Pingtree model defines:

/**
 * Get the pingtrees that the model has.
 */
public function pingtree_entries()
{
    return $this->hasMany(PingtreeEntry::class);
}

My PingtreeEntry model defines:

/**
 * Get the buyer tier that the model has.
 */
public function tiers()
{
    return $this->hasMany(BuyerTier::class, 'id', 'buyer_tier_id');
}

This is outputting the following via Postman:

{
    "model": {
        "id": 1,
        "user_id": 1,
        "company_id": 1,
        "pick_chance": 4,
        "name": "omnis iusto consequatur",
        "description": "Hic nihil suscipit error.",
        "is_enabled": false,
        "created_at": "2023-01-27T14:15:26.000000Z",
        "updated_at": "2023-01-27T14:15:26.000000Z",
        "deleted_at": null,
        "is_deleting": false,
        "pingtree_entries": [
            {
                "id": 1,
                "user_id": 1,
                "company_id": 1,
                "buyer_id": 2,
                "buyer_tier_id": 4,
                "pingtree_id": 1,
                "pingtree_group_id": null,
                "processing_order": 1,
                "is_enabled": true,
                "created_at": "2023-01-27T14:15:26.000000Z",
                "updated_at": "2023-01-27T14:15:26.000000Z",
                "deleted_at": null,
                "tiers": [
                    {
                        "id": 4,
                        "user_id": 1,
                        "company_id": 1,
                        "buyer_id": 2,
                        "country_id": 2,
                        "product_id": 3,
                        "name": "dignissimos voluptas et",
                        "description": "Dolore tempora et maxime nam.",
                        "processing_class": "et",
                        "is_default": false,
                        "is_enabled": false,
                        "created_at": "2023-01-27T14:15:25.000000Z",
                        "updated_at": "2023-01-27T14:15:25.000000Z",
                        "deleted_at": null,
                        "is_deleting": false
                    }
                ]
            },
            {
                "id": 3,
                "user_id": 1,
                "company_id": 1,
                "buyer_id": null,
                "buyer_tier_id": null,
                "pingtree_id": 1,
                "pingtree_group_id": 1,
                "processing_order": 1,
                "is_enabled": false,
                "created_at": "2023-01-27T14:15:26.000000Z",
                "updated_at": "2023-01-27T14:15:26.000000Z",
                "deleted_at": null,
                "tiers": []
            }
        ]
    }
}

Note that the last PingtreeEntry has no tiers. So I don’t want to show the whole PingtreeEntry model at all.

I want to get the both values from the code

html code

`<select name="vlcc"id="vlcc" class="form-control" required>`
`<select name="itemname" id="itemname" class="form-control" required>`
`<input type="text" class="form-control" name="balancestock" id="balancestock" >   `                 


`script code`
`$(document). ready (function () {`


`      $("#itemname"). change (function ()`
`{`
`      var itemname = $("#itemname").val();`
`      var vlccname = $("#vlccname").val();`
`      $. get ("stock_vlcc_out_load_totalstock.php", {vlcc: vlccname, item: itemname}'
`function(data) {`
        `//display the return data in browser`
          `alert (data);`
   `  })`
    `})`
`});`



`//stock_vlcc_out_load_totalstock.php file`
`<?php`
`$vlcc=$_GET['vlcc'];`
`$item=$_GET['item'];`
`echo $vlcc . $item ;`

`?>`

I cannot connect to database using php but I am able to connect using Navicat and ubuntu

I am using php 7.4 in ubuntu. and my mysql version is 8.0. I am able to connect to database in navicat using root but i cannot connect using php .

<?php
$servername = "localhost";
$username = "root";
$password = "P@ssword123";
$dbname = "test";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

echo "<br>";
// Check connection
if ($conn->connect_error) {
  die("Connection failed: ". "<br>" . $conn->connect_error);
}
echo "Connected successfully";

I try using oop and procedural but i dont think the problem is in the syntax.

What’s the problem with my WordPress ajax request

I want to add have a form in my WordPress dashboard that work with ajax but my request response is 400 Bad request

add_action('admin_footer', 'vitrin_admin_ajax');
        function vitrin_admin_ajax() {
        ?>
            <script>
                (function($) {
                    $('.vitrin-private-message-form').submit(function(event) {
                        event.preventDefault();
                        jQuery.ajax({
                            url: '<?php echo admin_url('admin-ajax.php'); ?>',
                            type: 'post',
                            data: {
                                action: 'submit_vitrin_pm',
                                ppmcontent: jQuery('#pmcontent').val(),
                                ppmusers: jQuery('#pmusers').val(),
                            },
                            success: function(data) {
                                // jQuery('#datafetch').html(data);
                                alert(data)
                            }
                        });
                    })
                })(jQuery);
            </script>
        <?php
        }
        ?>

I also add:

add_action('wp_ajax_submit_vitrin_pm', 'submit_vitrin_pm');
add_action('wp_ajax_nopriv_submit_vitrin_pm', 'submit_vitrin_pm');

and

function submit_vitrin_pm() {
    echo 'ssss';
    die();
}

PHP cURL not aible to show response

enter image description here

I am not able to retrieve the response of the SNOMED API. Works with my browser with the same URL.
I received no error message, just an empty response.

Tried to add these parameters without change
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( ‘Content-Type: application/json’));
curl_setopt($ch, CURLOPT_HTTPHEADER, array( ‘Content-Type: application/x-www-form-urlencoded’));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

procedural mysqli insert statement does not throw error, but no rows are inserted [duplicate]

I’m using this mysqli insert statement to dump some data in a table.

 $sql = "INSERT INTO searchqueue (guid, searchdata, type) VALUES (?, ?, ?)";
 $stmt = mysqli_prepare($conn,$sql);
 if ( !$stmt ) {
 die($conn->error);
 }
 else if ( !$stmt->bind_param("ssi", $guid, $dataArray, $type) ) {
 die($stmt->error);
 }
 else {
 mysqli_stmt_execute($stmt);
 mysqli_close($conn);
 echo $guid . " | " . $type . " | " . $data;
 }

I know the variables i’m binding are populated, as the echo response shows me the data (this page is called asynchronously from JS with post data).

I know the connnection string is correct, as it is used elsewhere for SELECT with no issues.
I’m getting no returned SQL errors… everything looks as if it is working correctly, however no rows are inserted into the table.

Column types in the db are varchar(32), text and int(11) respectively.

Can anyone see anything i’m doing wrong or point me in the right direction?

TIA

Call PHP function with less parameters then expected by function

I have the following PHP function which is working very well:

<?php
function my_test_function($par1, $par2, $par3) {
    $string = $par1.$par2.$par3;
    return $string;
}

echo my_test_function('Hello', 'how are', 'you');
?>

But if I call the function like this:

echo my_test_function('Hello', 'how are');

I’ll get an error message, because the function needs three parameters and I only send two parameters:

[29-Jan-2023 10:29:45 UTC] PHP Fatal error:  Uncaught ArgumentCountError: Too few arguments to function my_test_function(), 2 passed in /home/user/public_html/test_file.php on line 7 and exactly 3 expected in /home/user/public_html/test_file.php:2
Stack trace:
#0 /home/user/public_html/test_file.php(7): my_test_function('Hello', 'how are')
#1 {main}
  thrown in /home/user/public_html/test_file.php on line 2

Is there a way to send less parameters than expected by the function? I’d like to call the function with two parameters, although tree are expected.

I know, I could just make the third parameter empty but this isn’t my goal.