Jump to content

n1concepts

Members
  • Posts

    195
  • Joined

  • Last visited

Posts posted by n1concepts

  1. I agree with gizmola comments & to add one note:

    * If you or client doesn't want the hassle of trying to figure out alot of the configurations that's required with WP (itself) and WooCommerce, then Shopify a good option (pretty easy to setup & manage).

    However, there comes the difference w/the two - you'll pay (Shopify) for that ease-of-use vs getting WP & WooCommerce (pretty much) setup at little to no cost.

  2. Hi,

    I need to modify some code found on Github to redirect if the user is not already logged in as the set 'wp user' from the script or 'admin'.

    Github link: https://gist.github.com/cliffordp/e8d1d9f732328ba360ad

    <?php
    
    function auto_login() {
    	// @TODO: change these 2 items
    	$loginpageid   = '1234'; //Page ID of your login page
    	$loginusername = 'wpusername'; //username of the WordPress user account to impersonate
    
    	// get this username's ID
    	$user = get_user_by( 'login', $loginusername );
    
    	// only attempt to auto-login if at www.site.com/auto-login/ (i.e. www.site.com/?p=1234 ) and a user by that username was found
    	if (!is_page( $loginpageid ) || ! $user instanceof WP_User ) {
    		return;
    	} else {
    
    	$user_id = $user->ID;
    
    	// login as this user
    	wp_set_current_user( $user_id, $loginusername );
    	wp_set_auth_cookie( $user_id );
    	do_action( 'wp_login', $loginusername, $user );
    
    	// redirect to home page after logging in (i.e. don't show content of www.site.com/?p=1234 )
    	wp_redirect( home_url() );
            exit;
        }
    }
    
    add_action( 'wp', 'auto_login', 1 );
    
    ?>

    Basically, I want to define in the function php file the logic to redirect viewer to the login page if the following conditions not met:

    1. is_page NOT '1234'  and/or wpusername not found

    2. No user currently logged in (either wpusername or any wp admin)

    Again, if either of those conditions not met, then the script should redirect to 'wp_login'

    -----

    Can anyone advise what edits can be made to this code to accomplish that goal - thx

     

  3. Disregard, using the code generated by the tool (RFG) that is setting the favicon.

    The issue I'm seeing is when I minimize the brower (itself) - THEN - that browser's favicon / title name shows which is correct being it's the parent containing the (multiple tabs, inside).

    Thanks for those that reviewed post - topic closed.

  4. Hi,

    I used Real Favicon Generator to create the required files to show the favicon on web pages which works.

    However, if/when I minimize the browsers (Chrome, Firefox, etc...) in this case Chrome - the website's favicon & title changes to the browser's favicon & title.

    Note: I see from other websites where their 'coded' favicon remains even when the browser is minimized.

    Q: How can I accomplish this - keep the site's favicon & title showing in brower tab, even when minimized?

    Thx!

  5. Thx for response requinix && maxxd - both your comments (I agree & on point).

    I would prefer to handle this on the backend with php, however, not my call - lead devs prefer JS so reason I was inquiring (thx)

    For the code (copying from WWW) - yeah, use to boiler plate customization (certainly not using 'as is' - thx again for respnose).

    We got it working but not how I would have preferred - but always multiple ways to accomplish similar results.

  6. Hi,

    I'm working with an example set of code to create a Stripe (Token) and that script works Great!

    Example code found at https://jsfiddle.net/ywain/5yz4z2yn/

    However, I need to capture the 'token' which is found at line 38 within the Javascript code.

    My issue: how can I pass that var (result.token.id) to an external PHP file?

    If you want to see the simulation - just fill out the form (use 4242 4242 4242 4242 for the test card & current of future 'two-digit' year) other values are random.

    In the HTML code (simulated form) you'll see that the 'token' class display the token when (result.token) JS condition is met / TRUE

    <div class="success">
            Success! Your Stripe token is <span class="token"></span>
          </div>

    I'll suppress the token from showing the var once I am able to grab the value & pass into the, external, PHP (Stripe api's for processing).

    Again, here's the code snippet in question from the 'Javascript file found at https://jsfiddle.net/ywain/5yz4z2yn/

    if (result.token) {
        // Use the token to create a charge or a customer
        // https://stripe.com/docs/charges
        successElement.querySelector('.token').textContent = result.token.id;
        successElement.classList.add('visible');

    Again, I need to (somehow) grab 'result.token.id' and (securely) pass that value to an external PHP file.
    Note: I do not want to use cookies b/c that not a stable solution for all browsers nor safe.

    Appreciate any suggestions - thx!

  7. Hi,

     

    I'm working on implementing the Payflow api into a php-based website and having issues with the payments processing at PayPal.

    Note: the PayPal api is using the Payflow class - that class can be found via this link: https://github.com/rcastera/Paypal-PayFlow-API-Wrapper-Class/blob/master/Class.PayFlow.php

     

    Paypal is now asking for me to produce the actual API call - from the cURL prior to that cURL process firing so I need to - some how - echo out that prepared URL statement from the 'public' function to which I can then save to a file or in a MySQL database table.

     

    I need some guidance to help me get that URL echo'ed or assigned to a local var from the OOP class named 'payFlow and method named, 'processTransaction' - see excerpt of that class below: lines 609 thru 641 from the provided link: https://github.com/rcastera/Paypal-PayFlow-API-Wrapper-Class/blob/master/Class.PayFlow.php

    
      public function processTransaction() {
        // Uses the CURL library for php to establish a connection,
        // submit the post, and record the response.
        if(function_exists('curl_init') && extension_loaded('curl')) {
          $request = curl_init($this->getEnvironment()); // Initiate curl object
          curl_setopt($request, CURLOPT_HTTPHEADER, $this->getHeaders($this->NVP));
          curl_setopt($request, CURLOPT_HEADER, 1); // Set to 0 to eliminate header info from response
          curl_setopt($request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1)
          curl_setopt($request, CURLOPT_TIMEOUT, 45); // times out after 45 secs      
          curl_setopt($request, CURLOPT_FORBID_REUSE, TRUE); //forces closure of connection when done 
          curl_setopt($request, CURLOPT_SSL_VERIFYPEER, FALSE); // Uncomment this line if you get no gateway response.
          curl_setopt($request, CURLOPT_POST, 1); //data sent as POST
          curl_setopt($request, CURLOPT_POSTFIELDS, $this->getNVP()); // Use HTTP POST to send the data
          $postResponse = curl_exec($request); // Execute curl post and store results in $post_response
      
          // Additional options may be required depending upon your server configuration
          // you can find documentation on curl options at http://www.php.net/curl_setopt
          curl_close($request); // close curl object
          
          // Get the response.
          $this->response = $postResponse;
          
          $this->response = $this->parseResults($this->response);
        
          if(isset($this->response['RESULT']) && $this->response['RESULT'] == 0) {
            return TRUE;
          } 
          else {
            return FALSE;     
          }
        }
        else {
          return FALSE;
        }
      }
    
    
    

    Again, what i need is the ability to (some how) capture $request and echo that out (return that value) outside the function so I can assign to a local variable to then save to MySQL database or echo at a later date.

     

    Any help accomplishing this task - which is prior to line 628 - appreciated (thx)

     

    brgds,

    Craig

  8. Hi,

     

    I need some insight on how to go about fixing some broken code due to host upgrading PHP from 5.3 to 5.4 - see error below:

    Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in...
    

    Yes, I aware, the two parameters that are required which would be as follow - with $db being the connection string:

    mysqli_real_escape_string($db, $value);
    

    Right now, the $db arguement is NOT in the 'mysqli_real_escape_string() function - read below to know why (that's what i need help to fix):

     

    My problem is this function - itself - is being called within a function which (with PHP 5.3 used MYSQL extensions but PHP5.4 deprecated those functions and MYSQLi requiring 2 parameters as stated.... See that entire piece of code to see the issue which involves the 'quote_smart' function which executes the mysqli_real_escape_string() function inside 'quote_smart' function:

     

    Here's the defined function, currently:

    function quote_smart($value){
    
    		   // Stripslashes if magic quotes is on
    
    		   if(get_magic_quotes_gpc()) {
    
    			   $value = stripslashes($value);
    
    		   }
    
    		   // Quote if not a number or a numeric string
    
    		   if (!is_numeric($value)) {
    
    			   $value = mysqli_real_escape_string($value);
    
    		   }
    
    		   return $value;
    
    		}
    

    and it's being called as such:

    ${$key} = quote_smart($value);
    

    Thus, my problem - I'm not sure how to pass the mysqli link (arguement) into the function - correctly - or if i should just make the $db var 'global' within the quote_smart function itself - now that PHP is 5.4.

     

    FYI: Yes, the objective is to rewrite all this code with PDO and prepared statements but need to get this up, quickly, with temp fix due to sudden issues due to host upgrade.

     

    Would really appreciate some guidance on this one - thx!

  9. Hi,

     

    Thanks to both of you for your quick responses - appreciated.

    1st response: that's what i'm trying to do (hopefully i did it right) in setting conditional logic on process() - see it?

    That will determined if the pop up should show policy or not - if submit button not clicked.

     

    which lead to 2nd response: thanks (I will try the popup but the presentation / structure wasn't well liked by mgt but you right - most browsers/clients block popups so the redirect won't show anyway... :) To that, just adhering to mgt - they want the redirect.

     

    So again, how can I adjust the code i have to update 'var jscheck' if 'checkfire()' triggered by the submit button.

    That's my issue - that (global) variable remains as 'fire' regardless.

  10. Hi,

     

    I have the 'onbeforeunload' event set on the 'body' tag to set a JS function to trigger ONLY if a conditionis set - two var's equaling one another. Note: that all works just fine - no issues with the default setup.

     

    However, This function should NOT trigger the event if the 'submit' button is click (therefore suppressing the 'process()' function set on 'body' tag. Reason: that means staff completed the transaction and data actually saved to the database. The 'cancel.html' required to inform them their action canceled the process and no record created as a result.

    ----

     

    Here's what i have thus far - appreciate some insight to get this final piece to work ('process' function should NOT fire when 'submit' button click which triggers 'checkfire' function). That's my problem - not able to pass local var out of 'checkfire' function to update global var which then read by 'process' function. (Brain dead!)

    =====

     

    Here's the code for review:

    * This is the snippet that sets the default var values and the 'checkfire' function that will be called from the 'submit' button

    <script type="text/javascript">
    var viewer = "fire";
    var jscheck = viewer;
    
    // if function called, then update var jscheck
    function checkFire() {
        jscheck = "nofire";
        alert("jscheck value is now: " + jscheck);
        return jscheck;
    }
    </script>
    

    * Here's the part that fires the 'cancel.html' page if staff member clicks away from the page without submitting the form data.

    This is where we need to display the cancelation policy advising they did not complete the process by submitting info.

    <script type="text/javascript">
    // Process to advise member by leaving page without clicking "Submit Record" button, canceled the entire process / update
    
    if (viewer == jscheck) {
    function process() {
        window.open('http://www.domain/canceled.html', '_blank'); self.blur();
        }
    } 
    </script>
    

    and finally, the Body tag showing 'process()' function and the 'submit' button showing onclick event calling 'checkfire()' func.

    <body onbeforeunload="process()">
    
    <input name="sumbit" value="Submit Record" onclick="checkFire();" />
    
    

    Again, If the 'submit' button is clicked, then the 'process()' should NOT trigger at that point.

     

    ISSUE: this is what's happening - process() function firing even when the form submitted (it should ONLY fire if staff leaves the page prior to submitting the form which is requirement to close out work order).

    ----

     

    I'm not sure how to dynamically 'remove' the onbeforeunload event off the 'body' tag or pass the 'checkfire()' value of 'jscheck' out of that function to global jscheck var to cause the conditional logic in 'process()' to fail - resulting in no action.

     

    Any help with this appreciated - thx!

  11. Hi,

     

    This works great and exactly what i need to get the data I want - specifically.

    However, I'm having trouble assigning those var_dumps to local variables - see example below which yields nothing:

    $var1 = var_dump($paypal_response['TRXRESULT']);
    echo $var1;    // doesn't produce any value for $var1
    

    I need to assign the results to variables so i can work with them to insert / update MySQL database.

    I tried var_export and other methods but unable to get the results/value(s) assigned as with this example.

     

    Thx for help - really appreciated!

  12. Hi,I

     

    I'm trying to setup Paypal Pro on a website - have everything working - but need to grab the 4th & 6th key values from the results given from the Paypal response and having difficulty with the task.

     

    See the code that prints the response and the response sent from Paypal below - I need to grab the values for  [TRXRESULT] and [TRXRESPMSG]

    echo('<pre>');
    print_r($PayFlow->getResponse());
    echo('</pre>');
    

    and here's the response I get from Paypal on script execution - this is an example of a failed transaction:

     

    Paypal Response

    Array
    (
        [RESULT] => 36
        [RPREF] => RPC5B24581A2
        [RESPMSG] => Transaction failed: Fail to obtain approval for the online transaction
        [TRXRESULT] => 23
        [TRXPNREF] => EUJPC36F2092
        [TRXRESPMSG] => Invalid account number: Unsupported Credit Card type
    )
    

    Again, I want to grab the values from [TRXRESULT] and [TRXRESPMSG] and assign them to local variables so i can work with them within the local php script.

     

    Example: $trxresult  and $trxrespmsg

     

    Here's part of the class (file name is Class.Payflow.php find on Github) that pertains to this snippet of code in question:

     

    Class.Payflow.php

    /**
       * @uses      Gets the response from Paypal.
       * @access    Public
       * @param     None.
       * @return    Array/String - Returns an array of Paypal's response or empty string if not return.
       * @example   $PayFlow->getResponse();
       */
      public function getResponse() {
        if($this->response) {
          return $this->response;
        }
        else {
          return '';
        }
      }
      
    

    Thanks in advance for help w/this one!

     

  13. Hi,

     

    You best me to updating this post with similar findings - I found most recent code for this objective use the 'onbeforeunload' event so i updated:

     

    <body onbeforeunload="process()">

     

    Also, I found - at least for me - why some of the browsers were not allowing the function to execute.

    Issue: within preferences, (per browser) I found "Block Pop-up" was checked; soon as I unchecked that option, the JS worked without issue.

     

    Thanks - I think I figured this one out (was interested!)

    Super? You "Da Master" in my book (appreciate support!)

  14. Hi,

    I am testing the below JS code in various browsers and it works just fine on my Windows laptop running Firefox but INOP on IE (same laptop) and also from my Mack which runs Firefox and Safari. I'm on the latest versions of all browsers - can someone advise what would prevent the JS function from opening the new page in those browsers mentioned?

     

    Note: I am not blocking JS nor popups - this just a test to see how the function works but now I'm curious as to what's really happening... thx!

    Here's the code:

    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    
    <!DOCTYPE html>
    <html>
    <head>
    
    <script type="text/javascript">
    function process() {
        window.open('http://www.w3schools.com/js/', '_blank'); self.blur();
        }
    </script>
      	
    </head>
      
    
    <body onUnload="process();">
    <p> </p>
    <p>Close the browser or enter another URL in window and press enter.</p>
    <p>In doing either of those actions, you should be redirected to http://www.w3schools.com/js</p>
    </body>
    </html>
    </head>
    
    <body>
    </body>
    </html>
    
  15. Hi,

     

    I was reviewing a php web scraping write up which is found at http://imbuzu.wordpress.com/tag/web-scraping and discovered there is a syntax error in the author's code:

     

    THE ERROR IS ON THIS LINE (FULL SET OF CODE CAN BE FOUND AT AUTHOR'S SITE - link above)

    for ($i = 0; $i getElementsByTagName('td');

     

    (I'm posting below): Note - i can't understand the logic of the 'for' loop, getElementsByTagName function to fix the problem so asking for help to make this work as the author suggested.

    <?php    
         
    error_reporting(E_ERROR);
    
    $url = "http://www.imdb.com/chart/";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $document = curl_exec($curl);
    
    //echo $document;
    
    $dom_rep = new DOMDocument;
    $dom_rep->loadHTML($document);
    
    $all_trs = $dom_rep->getElementsByTagName('tr');
    $trs_we_want = array();
    foreach ($all_trs as $tr) {
      $class_name = $tr->getAttribute('class');
      if (preg_match("/chart_(even|odd)_row/", $class_name)) {
        $trs_we_want[] = $tr;
      }
    }
    
    for ($i = 0; $i getElementsByTagName('td');
      $the_tds_arr = array();
    
      foreach ($the_tds as $td) {
        $the_tds_arr[] = $td;
      }
    
      $movie_title = $the_tds_arr[2]->nodeValue;
      $rank = $the_tds_arr[0]->nodeValue;
      $weekend = $the_tds_arr[3]->nodeValue;
      $gross = $the_tds_arr[4]->nodeValue;
      $weeks = $the_tds_arr[5]->nodeValue;
      echo "<div>";
      echo "<h2>$movie_title</h2>";
      echo "Rank: $rank<br />";
      echo "Weekend: $weekend<br />";
      echo "Gross: $gross<br />";
      echo "Weeks: $weeks<br />";
      echo "</div>";
    }    
        
        
    ?>
    
    
  16. I have working code, see below, to which I'm trying to create a two-by-two (two rows and two columns) table instead of the one cell which currently displays when link/btn is clicked. Can someone enlighten me on how to modify this code to produce two rows and two cells on same, initial, click? Again, the code works - below - but only generating one row & cell, currently.

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    table,td
    {
    border:1px solid black;
    }
    </style>
    </head>
    <body>
    
    <p>Click the button to create a TABLE, a TR and a TD element.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <script>
    function myFunction()
    {
    var x = document.createElement("TABLE");
    x.setAttribute("id", "myTable");
    document.body.appendChild(x);
    
    var y = document.createElement("TR");
    y.setAttribute("id", "myTr");
    document.getElementById("myTable").appendChild(y);
    
    var z = document.createElement("TD");
    var t = document.createTextNode("cell");
    z.appendChild(t);
    document.getElementById("myTr").appendChild(z);
    }
    </script>
    
    </body>
    </html>
    
    
  17. Hi,

    I'm trying to define a query that will only pull results for rows where only a specific action is defined for said column (Process) where the 'Action' is 'idle'. Note: if any process as other actions logged, other than 'idle' for any rows of data, then that process should NOT be included in the results at all - only those that do NOT have additional rows logged as 'started' or 'complete'.

    For example: I need to define the MySQL query that will ONLY parse results that include id 5, 8, 12 being those only show 'Action' of 'idle'.
    Being all the rest have multple 'Actions' of 'started' or 'complete' - ids: 1,2,3,4,6,7,9,10,11 - then they should be excluded in the 'SELECT' results.

    ==============================
    Id              Process                   Action

    1                Filter                         idle

    2                Drain                         idle

    3                Swell                         idle

    4                Filter                       started

    5                Stretch                      idle

    6                Filter                     complete

    7                Drain                       started

    8                Spread                      idle

    9                Swell                       started

    10              Swell                     complete

    11              Drain                     complete

    12              Plant                         idle

    ==============================

     

    I played around with the 'SELECT' statement (defining where 'action != started', etc...) but it pulls the row matching 'idle' - even for those having other actions logged.

     

    Again: that's my problem - not sure how to define the logic to exclude those (I even tried subquery to pull all matching 'started' or 'complete' then insert in later query to 'NOT' match on those results but it takes forever to finish the query so know that's not correct. Note: each of the logs have a timestamp - I excluded that column but is apart of each record (just fyi...)

    I would appreciate some guidance on figuring this out as I'm not sure if 'Case' the correct way to define this logic nor how to defined the query using such... - ensuring any 'process' linked to any other 'Action' other then 'idle' is excluded in the results. Thanks in advance!

  18. I need to match only the files whose names start with a or z and end with a or z?

    I'm struggling with the reg to do this.... This what i have thus far but doesn't block to just the 1st letter 'a' or 'z' at beginning of a word or the last letter (same) 'a' or 'z'.

     

    Example:

     

    Regular Exp in 'ls' statement:     ls [az]*[az$]

     

    Results: afkfz akfkea az za zdea zdkdkz

    However, the problem is [az$] also allowing:  'a', a 'z', or a '$'.

     

    Question: what am I doing wrong w/this regular expression?    [az]*[az$]

    Should the $ sign be outside the bracket? That didn't work for me - any suggestions appreciated.

     

    Thx!

  19. Requirements & Objectives:

     

    Ensure $x is populated (not empty) and fires $x variable if TRUE back to http://domain2.com/log.php?x=$_REQUEST['a'] on page (success.php) load.

     

    http://domain2.com/log.php        // This is the page that needs to receive appended variable from http://domain1.com/success.php via JS

    -------

     

    START OF PROCESS:
    http://domain1.com/index.php?id=test123    

    // this is the receiving domain with appended variable 'id' sent to www.domain1.com/index.php


    http://domain1.com/success.php?a=$_REQUEST['id']            
    // variable 'id' is then captured & passed, from inbound.php to success.php to which I, then, need that page (success.php) to fire the captured var $a back to domain2.com/log.php as var 'x' via JS.

    =============

     

    Again, the objective is to get 'success.php' to assign $x to link and fire as: http://domain2.com/log.php?x=$_REQUEST['a'] on page (success.php) load via JS. I have the variable capture process, via PHP worked out - just need help with the JS part on success.php to fire the url back to www.domain2.com with captured var $x if populated.

     

    ---

     

    Any help appreciated - thx!

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.