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 9 of 9
  1. #1
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts

    File_Get_Contents Question

    Hey All,

    I am in the process of trying to make an updater/license validator for a web script I've made and was trying to use file_get_contents and it was working perfectly fine until I went to try and access the mysql db on my site that stores the licenses and stuff (we'll call it the update site).... it seems that the code to select the licenses from the database isn't parsed before it is retrieved and it then gives me errors because it can't find the license tables locally (thats because they are on the update site - remote).

    So my question is how would you suggest I go about a license checker/updater so that it will perform the mysql queries on the remote database (update site's database) before retrieving the rest of the file :S Here's what I've got so far...

    check.php (stored locally - this is what contacts my sites server to check)
    PHP Code:
    if($_SESSION['rp4_rank'] == "Administrator"){
        echo 
    "<b>» $update_stats</b>
    <table><tr>"
    ;
        
    $get mysql_query("SELECT * FROM rp4_settings");
        
    $i mysql_fetch_array($get);
        
    $a "rdjp";
        
    $v $i['panelversion'];
        
    $l $i['license'];
        if(
    $content = @file_get_contents("http://update.quickscriptz.ca/?a=$a&v=$v&l=$l&k=$k")){
            echo 
    $content;
        }else{
            echo 
    "<td><img src='images/update_error.gif' /></td>
    <td>$update_error</td>"
    ;
        }
    echo 
    '</tr></table></div>';

    index.php (stored on my/update site)
    PHP Code:
    <?php
    include('connect.php');
    function 
    updatecheck(){
        if(
    $_GET['a'] == "rdjp"&&$_GET['l'] != ""&&$_GET['v'] != ""){
    ###########################
    # General
    ###########################
            
    $lv "4.0.0";
            
    $l $_GET['l'];
            
    $v $_GET['v'];
            
    $getinfo mysql_query("SELECT * FROM rp4_licenses");
            
    $row mysql_fetch_array($getinfo);
            
    $count mysql_query("SELECT COUNT(id) FROM rp4_licenses WHERE license='$l'");
            
    $total mysql_fetch_array($count);
            if(
    $total(COUNT(id)) == "1"){

    ###########################
    # Version Check
    ###########################
                
    if($v == "$lv"){
                    echo 
    "<td><img src='images/update_no.gif' /></td><td>$update_uptodate</td></tr>";
                }
                if(
    $v != "$lv"){
                    echo 
    "<td><img src='images/update_yes.gif' /></td><td>$update_yes</td>";
                    echo 
    "<tr><td><img src='images/update_license.gif' /></td><td>License Valid</td>";
                    echo 
    "<tr><td><img src='images/update_download.gif' /></td><td>Download</td>";
                }
            }
        }
    }
    ?>
    Any help is greatly appreciated and will be repped! Thanks!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Are you using your own hosted mysql server or are you just using localhost? Also what errors are you getting? It would help if you posted those.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Well... the errors are irrelevant... You see the problem is that I need to basically have the file on my update server run itself before it is retrieved by the check file....

    And the files on the update server are all being run through localhost mysql (and my host wont allow remote mysql connections).
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #4
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Do you need to run a certain function from the file or file has some other scripts than PHP?

    If that's the case maybe you could run a function before displaying content

    PHP Code:
    if($content = @file_get_contents("http://update.quickscriptz.ca/?a=$a&v=$v&l=$l&k=$k")){
            include 
    "http://update.quickscriptz.ca/?a=$a&v=$v&l=$l&k=$";
            
    run_function_from included file();
            echo 
    $content

  • #5
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Well... you see the problem again is that I need some sql queries run on the update server before it is retrieved by the check file... so like this would be ideal:

    Have a piece of code that parses the file on the update.quickscriptz.ca server and then it only echos the result that the file gives...

    Any ideas? Thanks for suggestions... +Rep
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #6
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Store Latest information from update(localhost) server in file---(sha1(latest$id))
    Store Latest information from toupdate(web) server in file---(sha1(latest$id))

    Compare those two values with file_Get_contents
    ---if !==
    connect to your localhost database, and retrive information
    show content
    ---else
    show content

  • #7
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    Alright... I've figured out how I'm going to do it... but a couple of problems have arisen....

    PHP Code:
    if($_SESSION['rp4_rank'] == "Administrator"){
        echo 
    "<b>» $update_stats</b>
    <table><tr>"
    ;
        
    $get mysql_query("SELECT * FROM rp4_settings");
        
    $i mysql_fetch_array($get);
        
    $a "rdjp";
        
    $v $i['panelversion'];
        
    $l $i['license'];
        if(
    $content = @file_get_contents("http://update.quickscriptz.ca/?a=$a&v=$v&l=$l")){
            echo 
    $response;
        }else{
            echo 
    "<td><img src='images/update_error.gif' /></td>
    <td>$update_error</td>"
    ;
        }
    echo 
    '</tr></table></div>';

    Now my only problem is how to pass the variable "$response" from update.quickscriptz.ca to the local server using the file_get_contents.... so in other words how can i use the var $reponse by simply using file_get_contents on my update server?

    Thanks!

    Edit: If its any help I was trying to work out something with the explode() function where the beginning is "//Start Response//" and the end is "//End Response//" but I am unfamiliar with the function (yes i checked php.net)
    Last edited by Troy297; 08-04-2007 at 03:14 AM.
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #8
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    [bump] I've tried using the explode() function but it doesn't work due to the fact that the code must be parsed in order for it to get a response to echo out... so ya...

    Any help is great!
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!

  • #9
    Regular Coder Troy297's Avatar
    Join Date
    Oct 2006
    Location
    Earth
    Posts
    314
    Thanks
    10
    Thanked 0 Times in 0 Posts
    [bump] Anyone have any ideas?
    Everyone hears what you say, friends listen to what you say, best friends listen to what you don't say.
    Radio DJ Panel v3 - It's Here!


  •  

    Posting Permissions

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