PHP loadHTMLFile not loading HTML file

I am calling loadHTMLFile from within a php fucntion but no data is being loaded. When I call loadHTMLFile at the root level of my php program the data is loaded.

Why is this happening? Is there a work-around to this problem?

Thanks in advance.

php – Prevent gobbledegook submissions to web contact forms

I think pspell is the wrong approach: misspellings can and do happen — and of course there are words like proper nouns that even if spelled correctly might trigger an error in pspell.

We had a similar issue with account signups on our website. More or less random information was being used to create the account. It turned out (not surprisingly) that all of these fake submissions were created by bots, so we added a captcha to our sign up form and the problem was solved. It wasn’t a huge problem to begin with, but we went from a couple of dozen fake accounts a day to basically zero.

For our purposes, we decided to use reCAPTCHA v3 because it doesn’t even require any user interaction, it was easy to set up, and it was free (see: https://developers.google.com/recaptcha/docs/versions). That said, there are dozens of alternatives should you prefer. Regardless, judging by the type of data you’re getting, I’m pretty certain your issue is being caused by bots too and a captcha or other human-verification system should solve your problem.

As an aside, you may wish to check your log files to see which networks, countries, etc. are responsible for these fake submissions. My guess is you’ll start noticing some patterns. We did. So we tightened up the security checks for certain types of data coming from certain countries — and banned other networks entirely from accessing our system (think: large, shady server farms in countries where internet lawlessness is rampant.) If you decide to go the ban route, you can do so on the application level (such as in your PHP scripts), in your web server configuration (e.g., httpd.conf) or by using a third-party service such as CloudFlare. (In addition to doing IP checks, CloudFlare allows you to ban entire ASNs which I find super useful.)

Good luck!

php – ¿Como insertar datos desde dos formularios distintos a una misma tabla?

quisiera saber como puedo insertar datos desde dos formularios a una misma tabla este es el primer formulario

  <?php

if(isset($_POST('Enviar'))) {
  
    include"config.php";
    
     if (isset($_FILES('foto')('name'))) {

                $nombre=$_POST('nombre');
                $email=$_POST('email');
                $contrasena=$_POST('contrasena');
                $cedula=$_POST('cedula');

    
                $tipoArchivo=$_FILES('foto')('type');
                $nombreArchivo=$_FILES('foto')('name');
                $tamanoArchivo=$_FILES('foto')('size');
                $imagenSubida=fopen($_FILES('foto')('tmp_name'),'r');
                $binariosImagen=fread($imagenSubida,$tamanoArchivo);
                $binariosImagen=mysqli_escape_string($conexion,$binariosImagen);
                $destino='fotos/';
                $file = $destino.basename($_FILES('foto')('name'));
                move_uploaded_file($_FILES('foto')('tmp_name'), $file);

   
    
                $repitacontrasena=$_POST('repitacontrasena');
                $fecha= date("d/m/y");

      if ($contrasena != $repitacontrasena) { 

           echo '<script>alert("Las contraseñas no coinciden");</script>';
  
      } else {
           $conexion->query("INSERT INTO $tabla_db1 (Nombre, Email, Contrasena, Cedula, Foto,Fecha) values ('$nombre','$email','$contrasena','$cedula','$binariosImagen','$fecha')");

           echo '<script>alert("Se a registrado con Exito");</script>';

                  header( "refresh:0.5; url=Avatar.php" );

         }      

}
}
`
y este es el segundo formulario

`

            <form action="" method="POST" enctype="multipart/form-data">
                <h1>Foto de Perfil</h1>
                
                
               <div class="imga">
                  <img src="Imagenes/dafault.jpg" height="180px" width="190px" style=" border-radius:100px; border: 1px solid #d0d0d0;"  name="imagen" />
               </div>

                 <br/>
               
               <input type="file" name="foto" required>
                 <br/>
              
                 <br/>

               <input type="submit" value="Siguiente" name="Enviar">
                 
                
                     
            </form>
               

        </div>
        
        
            <?php 

              if (isset($_POST('Enviar'))) {

                if (isset($_FILES('foto')('name'))) { 
                include ("configuracion/config.php");
                
                $tipoArchivo=$_FILES('foto')('type');
                $nombreArchivo=$_FILES('foto')('name');
                $tamanoArchivo=$_FILES('foto')('size');
                $imagenSubida=fopen($_FILES('foto')('tmp_name'),'r');
                $binariosImagen=fread($imagenSubida,$tamanoArchivo);
                $binariosImagen=mysqli_escape_string($conexion,$binariosImagen);
               
                $destino='foto/';
                $file = $destino.basename($_FILES('foto')('name'));
                move_uploaded_file($_FILES('foto')('tmp_name'), $file);
               
               $conexion->query("INSERT INTO vende (Perfil) values ('$binariosImagen')");

                header( "refresh:0.5; url=IniciarSesion.php" );

                }
              }

            ?>
          </section>'


    

y esto es lo que pasa en la base de datos

lllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllintroducir la descripción de la imagen aquí

php – Website get slow sometimes and fixes by itself

Since about 2 months ago, I’ve experienced my website slows down (timeout problem), however I’ve made some checking on the server and my settings and behavior is this (LAMP, VPS 6GB Ram – 4 cpu cores, but I’m not expert on Linux or apache):

When it suddenly starts to hang, I’ve check the browser network behavior and I’ve found that images takes up to 24-30 seconds to load (small images from 4K to 180K), some of them fail to load. It also happens to .css files sometimes (10 seconds to load). During this period, only 1 core is used and RAM stays at 1.4GB tops. The server is hosting a website based on CMS (Joomla – SSL – gzip set). Check browser network tab here

I have apache MPM as prefork with these settings:

KeepAlive On
KeepAliveTimeout 3
MaxKeepAliveRequests 500

   StartServers        5
   MinSpareServers     5
   MaxSpareServers     10
   ServerLimit         100
   MaxClients          100
   MaxRequestsPerChild 3000

I have mod_security enabled, but there isn’t any suspicious behavior. I have also server-status enable, and I’m not sure but it doesn’t look very loaded (most of process in K and W). The access log shows the usual behavior and no error logs found.

The Database is MariaDB, no hanged queries during this periods and nothing in slow query logs.
The website gets 1700 visits per hour (aproximated)

The thing is, even if I restart the apache service, the website still hangs. So I tried restarting the server (shutdown -r) and when the server and services are up again, it also hangs. Sometimes when I’m not monitoring the website, it comes back to normal after 20 minutes, but sometimes takes even 3 hours. The problem is that it’s a production server and it’s not always that happens. Sometimes it happens 2 days in a row, then after 3 or 4 days, sometimes happens twice in the same day.

Any idea what could be happening here? I’m out of clues right now. Thanks in advance

php – Is it bad to let a file be downloaded using its direct path on WordPress?

I have a scenario that I want to let people that visit my WordPress website download some PDFs. These PDFs go to my website as products of the Woocommerce plugin, so they are stored on the folder uploads/woocommerce_uploads.
At the moment, I don’t want people to go through all the process of buying a free product. If the user is already logged in, and has the necessary privileges, I show a custom download button, which points directly to the PDF’s path in the uploads folder. Something like this:

http://nameofmysite.com/wp-content/uploads/woocommerce_uploads/2020/09/pdfname.pdf

Does this direct link to a PDF files as a way to let people download them open any vulnerability or harm in any way my WordPress website?

Custom PHP / WordPress Developer with 15+ yrs experience

Hi All,

I have been a long time member here in DP since 2007 serving clients across globe.

[​IMG]
SEMrush

As a Professional Freelancer with over 15+ yrs of experience I do offer following services:

CUSTOM PHP/MySQL Services:
# Complete Website Design & Development
# Bug Fixing & Maintenance
# Fine tuning & Performance Optimisation for speed
# Takeover someone’s Website code & do provide maintenance / upgradation service

WORDPRESS SERVICES:
# Complete WordPress site Design & Development
# Theme Development & Customisation
# Plugin Development & Customisation
# Website Maintenance & Bug Fixing
# Website Audit Report
# WordPress Website Customisations

Checkout my portfolio linked in my signature to know more about my skill-sets / experience / projects & client references.

[​IMG]

If you are interested with my services , I would be happy to help you on long-term.

Looking forward to hear from you fellow DP members.

Thanks & wish you all the best.

 

Imprimir Indices de un arreglo (PHP)

La siguiente linea es lo que me arroja en pantalla al imprimir:

Array ( (success) => (error) => Array ( (code) => Exception)

En este array lo que quiero Imprimir es sólo lo que tiene success

Utilizo:
print_r ($params );
y al utilizar Foreach sólo me imprime la leyenda Array.

¿Qué me recomendarían?

Gracias.

php – An action in my controller has too much responsibility

(Disclaimer : I’m asking this question here because as it is opinion-based, it have been closed from https://stackoverflow.com/questions/64050308/an-action-in-my-controller-has-too-much-responsibility)

Summarize the problem

This question has come to me because I write a function to set a current cart for a user.

Specifications :

A user can have multiple shopping cart open.
He can grab a few items for one cart and then set it aside to fill another.
As soon as he wishes, he can return to any current cart to fill it again or validate it.

Some code

So I have been writing the following Controller :

#src/Controller/CartController
class CartController extends AbstractController
{

/**
* Add product to given cart. If $cart_id equal to 0, create a new cart.
*/
public function addProduct(int $cart_id, int $product_id, Request $request, EntityManagerInterface $entityManager) : RedirectResponse {...}

/**
* Set given cart as the current one for the user
*/
public function setCurrentCartForUser(int $cart_id, Request $request) : RedirectResponse {...}
...
}

This is fine, but now I want to use the function setCurrentCartForUser() into addProduct() like this :

public function addProduct(int $cart_id, int $product_id, Request $request, EntityManagerInterface $entityManager) : RedirectResponse {
   // ... Add product to cart ...
   if($request->query->get('assign_current_cart') === true) $this->setCurrentCartForUser($cart_id, $request)
   return new RedirectResponse($request->headers->get('referer'));
}

Problem

I wondering if that’s the better way to do it, because now addProduct() have a lot more responsability than just adding product to cart :

It create instance of new shopping cart if none given ($cart_id === 0)
It add product to cart
And it also will set the current cart if you give the assign_current_cart option.
I was thinking about solving that by moving some responsability to a new action like that :

public function addProductAndSetCurrentCart(int $cart_id, int $product_id, Request $request, EntityManagerInterface $entityManager, CartService $cartService){
   $this->addProduct(int $cart_id, int $product_id, Request $request, EntityManagerInterface $entityManager, CartService $cartService);
   $this->setCurrentCartForUser($cart_id, $request);
   return new RedirectResponse($request->headers->get('referer'));
}

But this seams not ok. I’m looking for the best way to proceed. I was just trying to do it the right way so I can progress, but having my question closed from stackoverflow makes me think that maybe I shouldn’t be asking myself so many questions.
If this one got close too, I’ll find the best way by myself, but I hope that I can learn from this community. Please point out my mistakes, it really help me.

I was thinking about :

  • Creating a new layer on top of the Controller, but that’s not MVC anymore I guess
  • I was thinking to create a new Service… But it’ll more act as a library.

What I really would like to have would be to make addProduct() only adding product, and setCurrentCartForUser() only setting current cart.
Then I’ll call them together when I need to for a maximum of flexibility. But as a user can call only one action at a time, the best approach so far seams to be this one :

public function addProduct(int $cart_id, int $product_id, Request $request, EntityManagerInterface $entityManager) : RedirectResponse {
   // ... Add product to cart ...
   if($request->query->get('assign_current_cart') === true) $this->setCurrentCartForUser($cart_id, $request)
   return new RedirectResponse($request->headers->get('referer'));
}

php – newsletter subscription export error Magento 1.9

I have more than 6000 records of subscription user I am using the Magento core module for that
while exporting all the records my screen shows [https://prnt.sc/unj950]

can anyone help me what’s the issue?

**NOTE: ITS MAGENTO CORE MODULE NO OVERRIDE OR ANY EXTENSION INSTALLED **

php – How can i insert the data of the subscription renewal order using “woocommerce_subscription_renewal_payment_complete” hook

I have a custom table in my db and i need to insert the product_id, user_id & order information to that table on the time of subscription renewal payment using the hook “woocommerce_subscription_renewal_payment_complete”. is that possible to implement this way? or anyone knows any other idea for the same??

i checked with the below code, and its not inserting into the table

function data_woocommerce_renewal( $subscription, $last_order ) {

if ( ! $subscription )
    return;
    
$order_id = $subscription->get_parent_id();
$order = wc_get_order( $order_id );
$user_id = $subscription->get_user_id();

$order_items = $subscription->get_items();

// Loop through order items
foreach ( $order_items as $item_id => $item ) {
    // To get the subscription variable product ID and simple subscription  product ID
    $product_id() = $item->get_product_id();
}

// if( 'completed' === $order->get_status() ) {       
    
    $user_details = array(
        'token' => 'ygfvygrffburb',
        'true_or_false' => TRUE,
        'product_id' => $product_id(0),
        'customer_id' => $user_id
    );
    
    data_insert_test_data($user_details);
    
// }
}
add_action( 'woocommerce_subscription_renewal_payment_complete', 'data_woocommerce_renewal', 10, 1 );

Insertion function below

//insert test data
function data_insert_test_data($user_details) {

    global $wpdb;
    $table_name = $wpdb->prefix . "test_data";
    $result = $wpdb->insert($table_name, $user_details);


    if ($result) {
        return true;
    } else {
        return false;
    }
}