Forum Replies Created

Viewing 15 replies - 16 through 30 (of 40 total)
  • Thread Starter mrapi

    (@mrapi)

    Thread Starter mrapi

    (@mrapi)

    It was renamed,this is the complete code:

    <?php
    /*
    Plugin Name: Drew's Browser Detector Plugin
    Plugin URI: https://www.falkonproductions.com/browserDetector/
    Description: This plugin will store the user agents for later parsing and display
    Author: Drew Falkman
    Version: 1.0
    Author URI: https://www.falkonproductions.com/
     */
    
    function bdetector_activate()
    {
    	global $wpdb;
    
    	$table_name = $wpdb->prefix . 'bdetector';
    
    	// will return NULL if there isn't one
    	if ( $wpdb->get_var('SHOW TABLES LIKE ' . $table_name) != $table_name )
    	{
    		$sql = 'CREATE TABLE ' . $table_name . '(
    				id INTEGER(10) UNSIGNED AUTO_INCREMENT,
    				hit_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    				user_agent VARCHAR (255),
    				PRIMARY KEY  (id) )';
    
    		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    		dbDelta($sql);
    
    		add_option('bdetector_database_version','1.0');
    	}
    }
    
    register_activation_hook(__FILE__,'bdetector_activate');
    
    function bdetector_insert_useragent()
    { if (!isset($_COOKIE['exps_visited']))
     {
        setcookie('exps_visited',1);
    	global $wpdb;
    
    	$table_name = $wpdb->prefix . 'bdetector';
    
    	$wpdb->insert($table_name,array('user_agent'=>$_SERVER['REMOTE_ADDR'],
    	                                'hit_date'=>current_time( 'mysql' )
    	                                ),
     	                          array('%s','%s')
    	             );
    
       // echo '<!--WordPress Tracker-->';
     }
    }
    
    add_action('wp_footer','bdetector_insert_useragent');

    thanks

    Thread Starter mrapi

    (@mrapi)

    Thread Starter mrapi

    (@mrapi)

    thanks,great,that works:

    $wpdb->insert($table_name,array('user_agent'=>$_SERVER['REMOTE_ADDR'],
    	                                'hit_date'=>current_time( 'mysql' )
    	                                ),
     	                          array('%s','%s')
    	             );

    but duplicate values are back with 1 second between,even I set cookie ??

    Thread Starter mrapi

    (@mrapi)

    Hi,it is not working ??

    my current time is 13:42 and in database it puts 06:34
    also I found now 2 duplicated records ?? , very strange, the difference is about 1 second between them,how can a cookie expire so fast,I set it to expire when browser closes (expire time not set)
    https://img163.imageshack.us/img163/8044/ii9g.jpg
    thanks!

    Thread Starter mrapi

    (@mrapi)

    Hi Jesin
    I can’t edit php.ini because hosting is a private server,I only can access cpanel and my domain folders/files
    in public_html folder I added this line in htaccess:
    php_value date.timezone Europe/Bucharest
    but then my page show this:

    The server encountered an internal error or misconfiguration and was unable to complete your request.
    
    Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
    
    More information about this error may be available in the server error log.
    
    Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
    
    Apache Server at ....com Port 80

    thanks!

    Thread Starter mrapi

    (@mrapi)

    ok,no problem it is ok
    the only problem left: CURRENT_TIMESTAMP set time with -6 hours delay as my current timezone,how to set correct time/timezone?
    thanks!

    Thread Starter mrapi

    (@mrapi)

    Hi Jesin,thanks for your answer.

    echo message is put just one time,after some google search I used a cookie,now seems ok,I’m testing it.

    code:

    function bdetector_insert_useragent()
    { if (!isset($_COOKIE['visited']))
     {
        setcookie('visited',1);
    	global $wpdb;
    
    	$table_name = $wpdb->prefix . 'bdetector';
    
    	$wpdb->insert($table_name,array('user_agent'=>$_SERVER['REMOTE_ADDR']),array('%s'));
    
     }
    }

    Thread Starter mrapi

    (@mrapi)

    Hi,thanks for your answer,I’ll study also plugins development.
    That is great: you get joy from helping others,all the best for you !!!

    Thread Starter mrapi

    (@mrapi)

    Hi bcworkz,thanks again for your help,seems to me that I solved the problem.

    I used e.preventDefault(),in this case I used window.location to start the download

    My first intention was to put window.location just after ajax call,and I’ve seen that canceled the call,so I decided to put it into
    success:function() and that worked,I can’t explain why …
    For this moment that seems to work fine.
    Just one question:would be hard to create a plugin for this,maybe I will change the theme and plugin will be a good solution.

    Just a curiosity:are you from wordpress team?
    Thanks for your time and help!!!

    this is the final js code:

    var $j = jQuery.noConflict();
    
    $j(function()
       {
           $j('a[href$=".exe"]').on('click',
                 function(e)
                   {
                       var aryFd = $j(this).attr('href').split("/");
    		   var link = $j(this).attr('href');
    
                        e.preventDefault();
    
                       $j.ajax({
                           type:"POST",
                           url: "https://www.softexpertcta.info/wordpress/wp-admin/admin-ajax.php",
                           data: {
                                  action: 'fn_download_AddtoCount',
                                  dw_file_name: aryFd[aryFd.length - 1]
                                 },
                            success:function(response)
                             {
    
                               window.location=link;
                             }
    
                               });
    
                     }
    
                          );
       });

    Thread Starter mrapi

    (@mrapi)

    Hi bcworkz,thanks again for your answer,my code look now like this:

    functions.php

    <?php
    
    function fn_my_script_enqueuer() {
       wp_enqueue_script('dwcounter',get_stylesheet_directory_uri()."/js/dwcounter.js", array('jquery'), '1.0', true);
    }
    
    add_action('wp_enqueue_scripts', 'fn_my_script_enqueuer');
    
    function fn_download_AddtoCount()
     {
    
         global $wpdb;
    
         $filename=$_POST['dw_file_name'];
    
       $wpdb->insert( $wpdb->prefix.'es_download_counter',
                  array( 'download_name' => $filename, 'time' => current_time('mysql')),
                  array( '%s',  '%s' )
                          );
    
        //echo('inserted');
       // die();
    
     }
    
    add_action('wp_ajax_fn_download_AddtoCount', 'fn_download_AddtoCount');
    add_action('wp_ajax_nopriv_fn_download_AddtoCount', 'fn_download_AddtoCount');

    js:

    var $j = jQuery.noConflict();
    
    $j(function()
       {
           $j('a[href$=".exe"]').on('click',
                 function(e)
                   {
                       var aryFd = $j(this).attr('href').split("/");
    
                       $j.ajax({
                           type:"POST",
                           url: "https://www.softexpertcta.info/wordpress/wp-admin/admin-ajax.php",
                           data: {
                                  action: 'fn_download_AddtoCount',
                                  dw_file_name: aryFd[aryFd.length - 1]
                                 },
                            success:function(response)
                             {
                               alert('Got this from the server: '+ response);
                             }
    
                               });
    
                     }
    
                          );
       });

    I make tests for 2 days,but no look
    I suspected php procedure when insering data so I replace that with writing something into a txt file,and just the same behavoiur,
    js file is always executed,I debug that with alert() so 99% problem,as you said is ajax call
    I put there the complete url as in the code above,nothing fixed
    I also tested on a localhost checking php log file:no error

    A strange thing also: if I uncomment these lines:
    //echo(‘inserted’);
    // die();
    alert from js success: is not reached

    in console on load page I have this warning:
    event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

    also on every click I can see this warning :

    Resource interpreted as Document but transferred with MIME type application/x-msdownload: “https://www.softexpertcta.info/dmdocuments/installAllnetSFXP.exe&#8221;

    my site is this
    download link is on red button on right corner above “Descarca acum”

    thanks!

    Thread Starter mrapi

    (@mrapi)

    Thanks bcworkz for your answer.I have lots of thinks to learn.. ??

    I’ve removed script block from header.php and how you suggested I’ve
    found how to specify jquery as a dependency
    https://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/

    so in my functions.php
    I removed the line:
    wp_enqueue_script('jquery');

    and I added:

    function my_script_init()
    {
    
    		wp_deregister_script('jquery');
    		wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js', false, '1.3.2', true);
    		wp_enqueue_script('jquery');
    	wp_enqueue_script('dwcounter',get_stylesheet_directory_uri()."/js/dwcounter.js", array('jquery'), '1.0', true);
    
    }
    
    add_action('init', 'my_script_init');

    script is executed as I can see in console,also no error in console but things are just the same : no record added ??

    thanks!

    Thread Starter mrapi

    (@mrapi)

    I’ve done some study and I’m near to solve this.
    When a user click on exe setup link,I want to insert some data into a table (date+time and file name downloaded)
    I also have a child theme, in functions.php I put:

    <?php
    wp_enqueue_script('jquery');
    
    function fn_download_AddtoCount()
     {
    
         global $wpdb;
    
         $filename=$_POST['dw_file_name'];
    
       $wpdb->insert( $wpdb->prefix.'es_download_counter',
                  array( 'download_name' => $filename, 'time' => current_time('mysql')),
                  array( '%s',  '%s' )
                          );
     }
    add_action('wp_ajax_fn_download_AddtoCount', 'fn_download_AddtoCount');
    add_action('wp_ajax_nopriv_fn_download_AddtoCount', 'fn_download_AddtoCount');

    in header.php,at the bottom :

    .....
     <script type="text/javascript"
                        src="<?php echo get_stylesheet_directory_uri("template_url"); ?>/js/dwcounter.js">
    
                </script>

    and dwcounter.js:

    var $j = jQuery.noConflict();
    
    $j(function()
       {
           $j('a[href$=".exe"]').on('click',
                 function(e)
                   {
                       var aryFd = $j(this).attr('href').split("/");
    
                      console.log('is here');
    
                       $j.ajax({
                           type:"POST",
                           url: "/wordpress/wp-admin/admin-ajax.php",
                           data: {
                                  action: 'fn_download_AddtoCount',
                                  dw_file_name: aryFd[aryFd.length - 1]
                                 }
    
                               });
    
                     }
    
                          );
       });

    table structure:
    CREATE TABLE IF NOT EXISTSwp_es_download_counter` (
    id mediumint(9) NOT NULL AUTO_INCREMENT,
    time datetime NOT NULL DEFAULT ‘0000-00-00 00:00:00’,
    download_name text NOT NULL,
    UNIQUE KEY id (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;`

    The problem is: that only works now and then: I have to click 3 times, with pause between, to see a new record added into table,sometime after 3-4 clicks,no record ??

    console.log(‘is here’) it is always executed,there must be something wrong in ajax call or my php function
    any help?
    thanks!

    Hi,I use normal links,the code above it is in your source code esdc.js
    Link is put on a normal menu
    Thanks

    Hi,I put a console log before $(selector).click as this:

    console.log(selector);
        $(selector).click( function( e ) {
            e.preventDefault();
     .........

    on first domain there I got exe link but on the second domain I got:

    XMLHttpRequest cannot load https://www.domain1.info/wordpress/wp-admin/admin-ajax.php?
    action=esdc_addtocount&filename=mysetup.exe&cnonce=36d26a19c2.
    Origin https://domain2.info is not allowed by Access-Control-Allow-Origin.

Viewing 15 replies - 16 through 30 (of 40 total)