Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts

    Run php code after page loads

    I wanna load a snippet that tells the person if their online or not but it takes to long when loading the page, so I wanna make it run when the page is already rendered. How would I do this?

    Heres the code

    PHP Code:
    $url "http://www.blockstatus.com/aim/status-checker/index.php";
                    
    $ch curl_init();
                    
    curl_setopt($chCURLOPT_URL,$url);
                    
    curl_setopt($chCURLOPT_POST1);
                    
    curl_setopt($chCURLOPT_POSTFIELDS,"aimac={$row['aim']}");
                    
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
                    
    curl_setopt($chCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']); 
                    
    $result2 curl_exec ($ch);
                    
    curl_close ($ch);
                    
    $data $result2;
                    
    $pattern '/Status:<\/b>(.*?)<br.*?><\/td>/i';
                    
    preg_match($pattern$data$status);
                    
    $output str_replace("Status: """$status[1]);
                    
    $aimstatus trim($output); 

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by The_Return View Post
    I wanna load a snippet that tells the person if their online or not but it takes to long when loading the page, so I wanna make it run when the page is already rendered. How would I do this?

    Heres the code

    PHP Code:
    $url "http://www.blockstatus.com/aim/status-checker/index.php";
                    
    $ch curl_init();
                    
    curl_setopt($chCURLOPT_URL,$url);
                    
    curl_setopt($chCURLOPT_POST1);
                    
    curl_setopt($chCURLOPT_POSTFIELDS,"aimac={$row['aim']}");
                    
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
                    
    curl_setopt($chCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']); 
                    
    $result2 curl_exec ($ch);
                    
    curl_close ($ch);
                    
    $data $result2;
                    
    $pattern '/Status:<\/b>(.*?)<br.*?><\/td>/i';
                    
    preg_match($pattern$data$status);
                    
    $output str_replace("Status: """$status[1]);
                    
    $aimstatus trim($output); 
    you can't do this only with php because is server side and that means that when the page is loaded all php activity is finished. The only way to do this is to use ajax and after the page is loaded to do a ajax request to the server for what you want do.

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •