• Resolved ksonia90

    (@ksonia90)


    Hi i just installed a new version of this plugin.

    The problem im facing now is the header php redirection no longer working. It works well on plugin previous version.

    [insert_php]
    
    $dbhost = '';
    $dbuser = '';
    $dbpassword = '';
    $dbname = '';
    $con = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbname);
    
    // Check connection
    if (mysqli_connect_errno())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    $unique_id = $_GET['unique_id'];
    $sql="SELECT * FROM user WHERE unique_id = '$unique_id'";
    $result=mysqli_query($con,$sql);
    
    // Associative array
    $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
    
    //if not active redirect to home page
    if($row['active']!=1){
    header('Location: https://www.google.com/');
    }else{
    $clientID = $row['guest_id'];
    $name = $row['name'];
    }
    
    // Free result set
    mysqli_free_result($result);
    
    mysqli_close($con);
    
    [/insert_php]

    PLease help

    • This topic was modified 7 years, 7 months ago by ksonia90.
Viewing 1 replies (of 1 total)
  • Plugin Author webcraftic

    (@webcraftic)

    Hi,

    I’m sorry, I needed to update other plugins. Now I’m back to you and can help you.

    Do you need to create this redirect only if the user is on the pages or posts?

    Create a snippet that should be “run everywhere”:

    // remove a template redirect from within a custom plugin.
    add_action( 'template_redirect', 'wbcr_php_snippets_redirect_action');
    
    function wbcr_php_snippets_redirect_action() {
      	if(!is_singular()) {
          return;
        }
          
        $dbhost = '';
        $dbuser = '';
        $dbpassword = '';
        $dbname = '';
        $con = mysqli_connect($dbhost,$dbuser,$dbpassword,$dbname);
    
        // Check connection
        if (mysqli_connect_errno())
        {
        	wp_die("Failed to connect to MySQL: " . mysqli_connect_error());
        }
        $unique_id = $_GET['unique_id'];
        $sql = "SELECT * FROM user WHERE unique_id = '$unique_id'";
        $result = mysqli_query($con,$sql);
    
        // Associative array
        $row = mysqli_fetch_array($result,MYSQLI_ASSOC);
    
        //if not active redirect to home page
        if( $row['active']!=1 ) {
        	header('Location: https://www.google.com/');
        } else {
        	$clientID = $row['guest_id'];
        	$name = $row['name'];
        }
    
        // Free result set
        mysqli_free_result($result);
        mysqli_close($con);
    
    }

    This code will be executed on all pages and for all posts.

    Best regards, Alex

Viewing 1 replies (of 1 total)

The topic ‘Header redirection no longer working’ is closed to new replies.