How to get all request in a specific file without .htaccess and server configuration in php

how to get all request in index.php without any server configuration.

I tried that with .htaccess but I notice some problems,like .htaccess does not work on all server by default, and save configuration does not work in nginx.

How php handle request itself? can we modify that behaviour ?

Is it possible?
If not, any other way available? but without .htaccess. I don’t hate server configuration files. But many times users doesn’t have access to server settings.

Downloading Multiple PDF Files

Good day Everyone,

I hope you are all doing well. Please kindly help me, I need to download PDF Files simultaneously by selecting textboxes and clicking on a Download button. For now, I am able to click the Download button next to each item to download the item. I need to have another button which will be used for bulk download of the files.

Below is the code for the Download button next to each item.

<td><a href="print_voucher.php?em_id=<?php echo $row['voucher_id'] ?>" download="print_voucher.php?em_id=<?php echo $row['voucher_id'] ?>"> Download </a></td>
Below is the code for the whole table displaying the items to download.


<form action="createzip.php" method="post">
                        <table id="selection_table" class="data-table table stripe hover nowrap">
                            <thead>
                                <tr>
                                    <div class="col-md-6">
                                    </div>
                                    <div class="col-md-1">
                                    </div>
                                    <div class="col-md-2">
                                    </div>
                                    <div class="col-md-3 pd-10 text-center">
                                        <a class="btn btn-primary" name="createzip" id="createzip" value="createzip"> DOWNLOAD ALL </a>
                                    </div>
                                </tr>
                                <tr>
                                    <th class="table-plus datatable-nosort"> <input id="select_all" style="max-height: 20px; max-width: 20px;" type="checkbox" class="form-control" value="Select All"/> <p> Select All </p></th>
                                    <th> COMPANY NAME </th>
                                    <th> EMPLOYEE NAME </th>
                                    <th> DOWNLOAD LINK </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>

                                    <?php
                                    
                                        $sql = "SELECT * FROM vouchers WHERE voucher_id BETWEEN '$empID' AND '$endEmpID'";
                                        $query = mysqli_query($conn, $sql) or die(mysqli_error());
                                        while ($row = mysqli_fetch_array($query)) {
                                        $id = $row['voucher_id'];
                                     ?>  

                                    <td class="table-plus">
                                        <input style="max-height: 20px; max-width: 20px;" name="fieldid[]" id="checkbox<?php echo $row['voucher_id'] ?>" value="<?php $row['voucher_id'] ?>" type="checkbox" class="form-control">
                                    </td>
                                    <td><?php echo $row['paid_by']; ?></td>
                                    <td><?php echo $row['paid_by']; ?></td>
                                    <td><a href="print_voucher.php?em_id=<?php echo $row['voucher_id'] ?>" download="print_voucher.php?em_id=<?php echo $row['voucher_id'] ?>"> Download </a></td>

                                </tr>
                                <?php }?>
                            </tbody>
                        </table>
                    </form>

Please help me to download the files simultaneously.

php division is not getting the right answer

I am trying to achieve a division in PHP but it is not giving me the correct answer. My try is:

$a = 0.09;
$b = 2505;

$res = $a/$b;

which is giving me ‘3.5928143712575E-5’ answer in PHP while this is not the exact answer.
How to achieve the right answer?

How can I aggregate the values from JSON array in PHP [closed]

I’ve a sample JSON array

array:3445 [
   0 => {#605
     +"id": 4074
     +"name": "Suraj J"
     +"type": "ABC"
  }
  1 => {#604
    +"id": 4074
    +"name": "Suraj J"
    +"type": "ABC"

  }
  2 => {#532
    +"id": 4074
    +"name": "Suraj J"
    +"type": "DEF"
  }
  3 => {#533
    +"id": 4075
    +"name": "Aster"
    +"type": "ABC"
  }
]

How can I get an aggregate count based on id and type in the JSON array. To be more clear, the id 4074 has three objects and has 2 different type 2 ABC’s and 1 DEF’s, so my aggregate JSON array would like

array:3445 [
 0 => {#605
   +"id": 4074
   +"name": "Suraj J"
   +"abc_type_count": 2
   +"def_type_count": 1
 }
 1 => {#604
   +"id": 4075
   +"name": "Aster"
   +"type_abc_count": 1
 }

]

Combining Submit and Upload buttons [closed]

everyone. I just want to ask if is it possible to combine the submit and upload buttons into one button? For example, I have a form that have fields (name and email), and I can also upload files.
I don’t have a code for this but I’m asking if this was possible?

In the upload, it only has the select file button and doesn’t have any upload button. So, when I input my name and email in the fields and chose a file, I want that one button to submit it to the database.

I did try having a separate button for upload but when I upload files, the information I input in the name and email fields will be erased.

Comment box (and comments) not displayed in WordPress Divi Theme

I’m troubleshooting my client’s WordPress (Divi) – the comments and comment box have been disappeared from all the posts.
I went through all WP missing comments troubleshooting steps (double checking comment settings, safe mode) but no joy.
I have checked single.php file and there’s code as below

do_action( 'et_after_post' );
    if ( ( comments_open() || get_comments_number() ) && 'on' === et_get_option( 'divi_show_postcomments', 'on' ) ) {
        comments_template( '', true );
    }

To the best of my knowledge this is what should give a comment box and display comments. Yet, when checking HTML source code of any page with a blog post the only thing related to comments is

<div class="jp-carousel-comments"></div>

and some more code related to JetPack carousel, none of the regular HTML related to comment box.

What other files do you suggest checking? Many thanks!

PS Comments are still visible in WP admin panel, just not on the the website.

I went through all WP missing comments troubleshooting steps (double checking comment settings, safe mode) but no joy.
I have checked single.php and comments.php – the code as above.
I have checked HTML source code of the page.

update sql row with time 1 hour before NOW()

hi i am having trouble updating a sql row

i want to set it so it updates row lastmergedate 1 hour before now

UPDATE `Table` SET `lastmergedate` = NOW() works for setting the time as now

but e.g UPDATE `Table` SET `lastmergedate` <= NOW() 1 interval hour does not work

any help would be much appreciated

tried

UPDATE `Table` SET `lastmergedate` <= NOW() 1 interval hour

but get mariadb errors

Getting last event per day from mysql database with CodeIgniter

we have a CRM Application to monitor employees check ins and check outs of every location (clients)

I’m requested to get the last check out of a specific employee per day.

My database looks like this:

| employee_id | check in time | check out time |
| ———– | ————- | ————– |
| 90 | 1666536812 | 1666537080 |
| 90 | 1653467778 | 1653474758 |
| 90 | 1653467444 | 1653474321 |
….

Every employee has multiple check outs per day, i need to get the last one per day.

My attempt so far:

$this->db->order_by('check_out_time desc');
$this->db->where('employee_id', $user_id);
$query = $this->db->get('events',50);

foreach($events as $event){
   // Change event(check out) time from epoch format to normal format
   $checkOutTime = new DateTime("@".$event->check_out_time);
   $event->check_out_time = $checkOutTime->format('Y-m-d H:i:s');

   // get day if this event
   $day =$checkOutTime->format('Y-m-d');

   // set the "visits[day] to max value of that day
   if (!isset($visits[$day]) || $visits[$day] < $event->check_out_time )
      $visits[$day] = $event->check_out_time;
}

Output:
enter image description here

the output is visually what i want but the data is incorrect

integrating a round up to my php time code

🙂 So I do have edited some code I found online to this:

function timeZone_funch( $atts ) 
    {
        extract(shortcode_atts(array('timezone'    => 'Europe/Berlin'), $atts)); 
/* Europe/Berlin is default Timezone */
        $output             = '';
        if (in_array($timezone, DateTimeZone::listIdentifiers()))
        {
            date_default_timezone_set($timezone);
            $currentTime = date( 'H:i', strtotime('+30 minutes'));
            $output = $currentTime;
        }
        else {
            $output = "Invalid Timezone";
        }

        return $output;
    }
    add_shortcode( 'current_time', 'timeZone_funch' );

It works as it should. It displays the timezones hour and minute + adding 30 minutes.

What I want to do now is to make it round up to the nearest quater hour.

Similar to this thread: Round minute down to nearest quarter hour

I also believe that this thread contains my answer BUT due to my lack of knowledge and experience, I’m not able to work the code from the thread above into the code I have right now.

If anybody could show me how I can integrate it, this would be amazing!

Thank you for your time and maybe even your answer!

With kind regards
Chris

Finding the correct way to integrate the round up function inside of the code I’am using.

WordPress – 404 for archive page of custom taxonomy

We did create a custom post type called service and a custom taxonomy called service_category.
So we are trying to create the following structure;

Archive page of custom taxonomy = archive-service_category.php with url /onze-producten-en-diensten
Taxonomy page of custom taxonomy = taxonomy-service_category.php with url /onze-producten-en-diensten/{taxonomy_name}
Single page of custom post type = single-service.php with url /onze-producten-en-diensten/{taxonomy_name}/{single_post_name}

The taxonomy and single page are working, but the archive page of the custom taxonomy returns a 404 error.

This is the code we are using;

/**
 * Service custom post type
 */

add_action('init', function() {
    register_post_type('service', [
        'label' => __('Diensten', 'txtdomain'),
        'public' => true,
        'menu_position' => 5,
        'menu_icon' => 'dashicons-book',
        'supports' => ['title', 'editor', 'thumbnail', 'author', 'revisions', 'comments'],
        'show_in_rest' => true,
        'rewrite' => ['slug' => 'dienst'],
        'taxonomies' => ['service_category'],
        'rewrite' => array('slug' => 'onze-producten-en-diensten/%service_category%', 'with_front' => false), 
        'labels' => [
            'singular_name' => __('Dienst', 'txtdomain'),
            'add_new_item' => __('Nieuwe dienst toevoegen', 'txtdomain'),
            'new_item' => __('Nieuwe dienst', 'txtdomain'),
            'view_item' => __('Dienst bekijken', 'txtdomain'),
            'not_found' => __('Geen dienst gevonden', 'txtdomain'),
            'not_found_in_trash' => __('Geen dienst gevonden in de prullenbak', 'txtdomain'),
            'all_items' => __('Alle diensten', 'txtdomain'),
            'insert_into_item' => __('Dienst toevoegen', 'txtdomain')
        ],      
    ]);
});

/**
 * Service taxonomy
 */

add_action('init', function() {
    register_taxonomy('service_category', ['service'], [
        'label' => __('Dienst categorieen', 'txtdomain'),
        'hierarchical' => true,
        'has_archive' => true,
        'rewrite' => array('slug' => 'onze-producten-en-diensten'),
        'show_admin_column' => true,
        'show_in_rest' => true,
        'labels' => [
            'singular_name' => __('Dienst categorieen', 'txtdomain'),
            'all_items' => __('Alle dienst categorieen', 'txtdomain'),
            'edit_item' => __('Dienst categorie bewerken', 'txtdomain'),
            'view_item' => __('Dienst categorie bekijken', 'txtdomain'),
            'update_item' => __('Dienst categorie bijwerken', 'txtdomain'),
            'add_new_item' => __('Nieuwe dienst categorie toevoegen', 'txtdomain'),
            'new_item_name' => __('Nieuwe dienst categorie', 'txtdomain'),
            'search_items' => __('Dienst categorie zoeken', 'txtdomain'),
            'popular_items' => __('Populaire dienst categorieen', 'txtdomain'),
            'not_found' => __('Geen dienst categorie gevonden', 'txtdomain'),
        ]
    ]);
});

register_taxonomy_for_object_type('service_category', 'service');

We did try refreshing permalinks, but still no success.
Does someone know why the archive page of the custom taxonomy returns a 404?

Thanks for your time!

Telegram bot is not reacting on command “/start”

I am making telegram bot on php. Webhook is set. Bot is not reacting on command “/start” but it is working good with inline_keyboard.

Webhook file:

//Piece of code that works good:
$update = json_decode(file_get_contents('php://input'), TRUE);
$user_chatId = $update['callback_query']['message']['chat']['id'];
$user_first_name = $update['callback_query']['message']['chat']['first_name'];
$user_last_name = $update['callback_query']['message']['chat']['last_name'];
$date = $update['callback_query']['message']['date'];
$str = $update['callback_query']['message']['text'];
$messageText = $update["message"]["text"];

if (isset($update['callback_query'])) {
    if ($update['callback_query']['data'] == 'Done') {

        // Text for a message
        $params=[
            'chat_id'=>$user_chatId,
            'text'=>'Thank you!',
        ];

        // Sending message on telegram
        $ch = curl_init($website . '/sendMessage');
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $result = curl_exec($ch);

        if ($result === FALSE) {
            echo 'An error has occured: ' . curl_error($ch) . PHP_EOL;
        }
        else {
            echo $result;
        }
        curl_close($ch);
    }

//Piece of code that doesn't work:
if($messageText == "/start") {
    $conn_new_user = $dbh->prepare('INSERT INTO chat_ids (chat_id) VALUES (:user_chatId)');
    $conn_new_user->bindParam(":user_chatId", $user_chatId);
    $conn_new_user->execute();
}

If I get rid of statement if: “if($messageText == “/start”)” and leave just database insert than everything works and I get data to database when only inline_button is pressed but I still get nothing on “/start”
Is there any way to fix that?
$messageText is not empty. Inside of “if($messageText == “/start”)” I was putting a code that was inserting the $messageText to another file, everything was working fine. The database statement is right. It works just fine when user presses button on inline_keyboard

How to manipulate multi-dimension array in PHP?

I have a multidimensional array and I want to change it to my final array. Below is the array I have.

$test = array(
            array(
                "supplier" => "TEST DEPO",
                "rolanID" => array(123, 234, 456),
                "itemCount" => 3
            ),
            array(
                "supplier" => "ANOTHER DEPO",
                "rolanID" => array(123, 786, 345),
                "itemCount" => 3
            ),
            array(
                "supplier" => "ROLAN",
                "rolanID" => array(123, 234),
                "itemCount" => 2
            ),
            
        );

So, with this array I want to output like the below array.

As we can see, if all rolanID is equal to one of the supplier then I don’t want to add that array into the final array.

For, an example the supplier “ROLAN” array is removed completely in the final array as its all rolanID is in the supplier “TEST DEPO” but the supplier “ANOTHER DEPO” has some rolanID that is not in the supplier “TEST DEPO” so, it is included that in the final array.

Array
(
    [0] => Array
        (
            [supplier] => TEST DEPO
            [rolanID] => Array
                (
                    [0] => 123
                    [1] => 234
                    [2] => 456
                )

            [itemCount] => 3
        )

    [1] => Array
        (
            [supplier] => ANOTHER DEPO
            [rolanID] => Array
                (
                    [0] => 786
                    [1] => 345
                )

            [itemCount] => 2
        )

)

PHP relative paths

suppose that I am working on a similar server PHP, with more projects, each of them with multiple subfolders and includes. Let’s concentrate on proj1:

/var/www/html
    /proj1
        /inc
            header.php
       /assets
            styles.css
            script.js
        page1.php
        index.php
   /proj2
    ...

Now, I want to include the css and the js with a relative path (not absolute) from header.php, but if I use $_SERVER["DOCUMENT_ROOT"] it returns to /var/www/html.
What do you think it could be the better solution to echo "script.js" in such scenario, without relying on absolute paths?
Thanks

PS: For the sake of clarity, we work on nested directories and structures, so I am searching for a way in which the relative path can change on these different folders, so it needs to be dynamic.