werer

November 13, 2025
<?php
  // Original price
    $price = 5.16;

  // Percentage to add
    $percentage = 12;

  // Check if $price is numeric before performing calculations
    if (is_numeric($price)) {

      // Calculate newPrice with the percentage added and limit to 2 decimals
        $newPrice = round($price + ($price * $percentage / 100), 2);

      // Output the result
      echo "New Price: $newPrice";
  } else {
      // Handle the case where $price is not numeric
      echo "Invalid price value";
  }
    ?>

Verify CSV integrity

November 13, 2025

Example code:

    <?php
// Verify CSV integrity from URL if it contains the specified header columns
function verifyCsvIntegrity($url) {

$headerColumns = ['Cod produs', 'Denumire', 'Categorie principal', 'Descriere produs', 'Imagine 1', 'Pret 2(RON)', 'Stoc'];

// Fetch the CSV file from the URL
$csvData = file_get_contents($url);

// Convert the CSV data into an array of rows
$rows = str_getcsv($csvData, "\n");

// Get the header row
$headerRow = str_getcsv($rows[0], ",");

// Initialize an array to store error lines
$errorLines = [];

// Check if the header row contains all the required columns
foreach ($headerColumns as $column) {
if (!in_array($column, $headerRow)) {
echo "Error: Missing column - $column\n";

// Store the error line
$errorLines[] = 1; // Header row line number is 1
}
}

// Verify CSV integrity for all data in specified header columns
for ($i = 1; $i < count($rows); $i++) {
$rowData = str_getcsv($rows[$i], ",");

// Check if the row has the same number of columns as the header row
if (count($rowData) != count($headerRow)) {
echo "Error: Invalid row - $rows[$i]\n";

// Store the error line
$errorLines[] = $i + 1; // Adding 1 to account for header row
}
}

// If there are no errors, display a success message
if (empty($errorLines)) {
echo "CSV integrity verification successful. No errors found.\n";
}

// Return the error lines
return $errorLines;
}

// Report errors
function reportErrors($errors) {
foreach ($errors as $error) {
echo "Error on line $error\n";
}
}

// Example usage
$url = 'test.csv';
$errors = verifyCsvIntegrity($url);
reportErrors($errors);
?>

Prevent access to the previous page

November 13, 2025

To prevent access to the previous page in the browser after calling session_destroy(), you can use several approaches:

Redirect after session_destroy(): After calling session_destroy(), redirect the user to another page using header() function in PHP or JavaScript. This will clear the browser history and prevent users from going back to the previous page.

  <?php
session_start();

// destroy session
session_destroy();

// redirect to another page
header("Location: new_page.php");
exit;
?>

JavaScript redirection: You can also use JavaScript to redirect the user after destroying the session. This approach ensures that even if the user tries to go back, they'll be redirected to the new page.

  <script>
// destroy session
<?php session_start(); session_destroy(); ?>

// redirect to another page
window.location.href = "new_page.php";
</script>

Prevent caching of pages: You can also include headers in your PHP scripts to prevent caching of pages, which might help in avoiding users accessing cached versions of the previous page.

  <?php
// prevent caching
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 1 Jan 2000 00:00:00 GMT");
?>

Choose the method that best fits your application's requirements. Keep in mind that using a combination of these methods might provide better security and user experience.


Add-percentage-to-price

November 13, 2025

This code checks if the original price is numeric before performing calculations to avoid the warnings.

   <?php
    // Original price
    $price = 5.16;

    // Percentage to add
    $percentage = 12;

    // Check if $price is numeric before performing calculations
    if (is_numeric($price)) {
        
// Calculate newPrice with the percentage added and limit to 2 decimals $newPrice = round($price + ($price * $percentage / 100), 2); // Output the result echo "New Price: $newPrice"; } else { // Handle the case where $price is not numeric echo "Invalid price value"; } ?>

Create your own content

November 13, 2025

Start writing your own content or edit the current to fit your needs. To create, edit or remove content you need to login to the admin panel with the username `admin` and the password you set in the installation process.