PHP code example of jdvorak23 / visits

1. Go to this page and download the library: Download jdvorak23/visits library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jdvorak23 / visits example snippets


    // DI továren - konstruktor, inject, ...
    private readonly VisitCardsFactory $visitCardsFactory,
    private readonly VisitIpsFactory $visitIpsFactory,
    private readonly VisitPagesFactory $visitPagesFactory

    protected function createComponentCards(): VisitCardsControl
    {
        return $this->visitCardsFactory->create();
    }
    protected function createComponentIps(): VisitIpsControl
    {
        return $this->visitIpsFactory->create();
    }
    protected function createComponentPages(): VisitPagesControl
    {
        return $this->visitPagesFactory->create();
    }

protected VisitManager $visitManager;
    public function injectManagers(VisitManager $visitManager): void
    {
        $this->visitManager = $visitManager;
    }

    protected function beforeRender(): void
    {
        parent::beforeRender();
        $this->addVisit();
    }
    protected function addVisit(): void
    {
        $remoteAddress = $this->getHttpRequest()->getRemoteAddress();
        $page = $this->getHttpRequest()->getUrl()->getPath();
        $this->visitManager->addVisit($remoteAddress, $page);
    }