Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Created 02-2017 by Marcel Minke (marcel.minke@limesurvey.org)
- *
- * This script creates a dummy token to directly start a survey with an empty data set
- */
- /*
- * ------------ START SETTINGS --------------
- */
- //to be used dummy details for token first name, last name and email
- $firstname = "John";
- $lastname = "Doe";
- //use invalid email address to not accidentally send emails to a real account
- $email = "john.doe@gmail.comm";
- //to create unique tokens we just use the current timestamp including seconds
- $token = date("YmdHis");
- //set the URL of the current system
- /*
- * ------------ START CONFIG --------------
- */
- //error reporting
- ini_set('display_errors',1);
- error_reporting(E_ALL & ~E_NOTICE);
- //check if SURVEYID was passed
- if(isset($_GET['sid']) && $_GET['sid'] != "")
- {
- $sid = intval($_GET['sid']);
- //basepath needs to be defined in order to include config file (there is a check for this!)
- define("BASEPATH", dirname(dirname(__FILE__)));
- //push all config details (config.details returns them as array) into this array
- $config = require_once("application/config/config.php");
- // DB CONNECTION DETAILS
- $username = $config['components']['db']['username'];
- $password = $config['components']['db']['password'];
- $dbprefix = $config['components']['db']['tablePrefix'];
- //the DB connection string looks like this:
- //'mysql:host=localhost;port=3306;dbname=etcvps88_devm;'
- //so we need to check for the last "=", add 1 and get the string without the ending ";" character:
- $database = substr($config['components']['db']['connectionString'],strrpos($config['components']['db']['connectionString'],"=")+1,-1);
- //connect to DB
- $connect = mysqli_connect("localhost",$username,$password,$database) or die( "Unable connect to database '$database'");
- //set charset to deal with special characters
- mysqli_set_charset($connect,'utf8');
- $tokentable = $dbprefix."tokens_$sid";
- //set the survey language to default (usually "en")
- $lang = "en";
- /*
- * ------------ START WORKFLOW --------------
- */
- $insertquery = "INSERT INTO $tokentable (firstname, lastname, email, token, language)
- VALUES('$firstname', '$lastname', '$email', '$token', '$lang')";
- //for debugging only
- /*
- echo "$insertquery<br /><pre>";
- print_r($_SERVER);
- echo "</pre>";
- */
- //execute INSERT statement
- mysqli_query($connect, $insertquery);
- //URL of current script
- $url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
- //remove "start.php"
- $url = str_replace("start.php", "", $url);
- //add URL details to load survey
- $url .= "index.php/survey/index/sid/$sid/token/$token/lang/$lang/newtest/Y";
- //redirect
- header("Location: $url");
- exit;
- }
- //no IDs passed
- else
- {
- echo "No survey ID was passed.";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement