dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

Server-side validation

hello
code is
<?php

define('LICENSE_VALID', '601');
define('LICENSE_INVALID', '602');

if(isset($_POST['licenseid']) && trim($_POST['licenseid']) != '')
{
// variables posted by AI serial validation tool
$licenseid = trim($_POST['licenseid']);
$languageid = (int) $_POST['languageid']; // you can use this parameter to display a localized error message taken from your database

if($id =='555-555') // TODO: user custom database-linked code to check the license ID
{
echo LICENSE_VALID . "\n" . "Serial ID = " . $licenseid . ' is OK.';
die();
}
else
{
echo LICENSE_INVALID . "\n" . "Serial ID = " . $licenseid . ' is invalid !';
die();
}
}
else
{
echo LICENSE_INVALID . "\n" . "Missing Serial ID !";
die();
}

?>
Serial Number dont is 555-555
Have to use the code?
dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

Hi:) i didn't quite understand what to write in the script, if it has to be chmoded on the server.. Could you give a full example please?
dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

Trouble you to help me write a complete and accurate code, thank you
dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

plase help me!!! very thank you!
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,
Could you give a full example please?
I noticed that you are using the example on the forum (which is a working PHP script). Please note that you need to adapt this code for your case.
if it has to be chmoded on the server.
Note that the PHP script used for the server-side validation must not be chmoded in order to work.

What exactly is the problem you are encountering?

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

sorry.i am chinaese i Understand A little English
I just want a complete code, the project web site will be able to type in the code so that .
Can I have a simple and easy code
Server-side validation......
dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

Tell me or the use of methods and code, or Guide
very thank you!!!very thank you!!!
dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

I was not used this php code Input in the project, the address of the server The installation will be able to smoothly
dbcode
Posts: 8
Joined: Tue Jan 15, 2008 10:01 am

Some help?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

Here is a full example for the PHP script:

Code: Select all

<?php

// server response codes
define('LICENSE_VALID',   '601');
define('LICENSE_INVALID', '602');

// database connection parameters
$db_host = 'localhost:3306';
$db_user = 'root';
$db_pass = 'root123';
$db_name = 'test_db';

// client information table
$clients_tbl_name = 'clients';
$sn_tbl_col       = 'serial_no';

/**
 * Server HTTP response to the query issued by Advanced Installer serial validation tool.
 */
function ServerResponse($is_valid, $posted_serial = '', $lang_id = 1033)
{
  $msg_sep = "\n";
  
  // load error messages from your database, using "$lang_id" for localization (optional)
  
  if($posted_serial == '')
    return LICENSE_INVALID . $msg_sep . "Missing Serial Number !";
  
  if($is_valid == true)
    return LICENSE_VALID;
  else
    return LICENSE_INVALID . $msg_sep . "Serial Number: " . $posted_serial . ' is invalid !';  
}

// Variables POSTed by Advanced Installer serial validation tool to this web page: "sn", "languageid".
if(isset($_POST['sn']) && trim($_POST['sn']) != '')
{
  // get the serial number entered by the installing user in the "UserRegistrationDlg" dialog 
  $sn = trim($_POST['sn']);
  
  // get the system language ID of the user's machine
  // (you can use this parameter to display a localized error message taken from your database)
  $languageid = (int) $_POST['languageid'];
  
  // connect to database
  $db_conn = @mysql_connect($host, $db_user, $db_pass);
  if(!$db_conn)
  {
    // issue error response
    echo ServerResponse(false, $sn, $languageid);
    die();
  }
  
  // select target database
  $db_selected = @mysql_select_db($db_name, $db_conn);
  if(!$db_selected)
  {
    // issue error response
    echo ServerResponse(false, $sn, $languageid);
    die();
  }
  
  // prepare SQL statement
  $sn_query = "SELECT `". $sn_tbl_col ."` FROM `". $clients_tbl_name ."` WHERE `". $sn_tbl_col ."` = '" . mysql_escape_string($sn) . "'";
  
  // execute query
  $result = @mysql_query($sn_query, $db_conn);
  
  // get result set size
  if(@mysql_num_rows($result) == 0)
  {
    // serial number NOT found in database => issue error response
    echo ServerResponse(false, $sn, $languageid);
    die();
  }
  else
  {
    // serial number was found in database => issue SUCCESS response
    echo ServerResponse(true, $sn, $languageid);
    die();
  }
}
else
{
  // issue error response
  echo ServerResponse(false);
  die();
}

?>
This script connects to the MySQL database which contains the serial numbers, verifies the serial entered by the user and returns a response.

Note that you need to configure the database information used in the script to allow the script to connect to your database. This is done in the // database connection parameters and // client information table sections of the script.

Also, in the "Serial Validation" page of the Advanced Installer project you select the "Server side validation" option and set the URL to point to the PHP script file on your server.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”