I'm trying to implement an as simple as possible licensing system in a installable web-app that I'm building (user downloads and uploads to their server). After learning that sessions can't be set cross-domain (which was my first choice), I've now thought about including an external file on my server, containing a function called validate() which validates whether or not the license exists in my database.
Flow of events: User inputs license key on his site -> License key posted to the file /validate.php which includes a file from my server -> Server checks to see if license key is included in database -> If yes, sets a session on users domain and redirects to admin section -> If no, redirects back to login page, with an error message.
Here's my code (theoretical - may have issues):
validate.php
include("http://www.example.com/function.php");
validate($_POST['license']);
function.php
include("db_conn.php");
function validate($license)(
$conn = mysql_connect($db_host, $db_user, $db_pass); mysql_select_db($db_name);
$license = mysql_real_escape_string($license);
$query = "SELECT FROM licenses WHERE license = '$license'";
$result = mysql_query($query);
if(mysql_num_rows($result) == 1) {
mysql_close($conn);
session_set_cookie_params(60*60*24*30,"/","." . $_SERVER['SERVER_NAME']);
session_start();
$_SESSION['license_valid'] == "YES";
header("Location:" . $_SERVER['SERVER_NAME'] . "/admin");
} else {
mysql_close($conn);
header("Location" . $_SERVER['SERVER_NAME'] . "/login/?error=1");
}
);
The problem is, I'm not sure how the server will handle the function validate() for example, will the session be set on my server, or the user's server? Will it use my $_SERVER['SERVER_NAME'] or the user's? Will it look to include db_conn.php from my server, or the user's?