...

View Full Version : File_Get_Contents Question



Troy297
08-03-2007, 07:02 PM
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)


if($_SESSION['rp4_rank'] == "Administrator"){
echo "<b>&#187; $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
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! :thumbsup:

_Aerospace_Eng_
08-03-2007, 07:06 PM
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.

Troy297
08-03-2007, 07:09 PM
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).

matak
08-03-2007, 08:53 PM
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


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;

Troy297
08-03-2007, 09:21 PM
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

matak
08-03-2007, 09:41 PM
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

Troy297
08-04-2007, 04:09 AM
Alright... I've figured out how I'm going to do it... but a couple of problems have arisen....


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)

Troy297
08-04-2007, 08:51 PM
[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!

Troy297
08-07-2007, 01:29 AM
[bump] Anyone have any ideas?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum