Sometimes the built in result pages are just not good enough for your marketing plans.

With custom result pages, you can direct users to a page on your site based on the quiz result. In its simplest form, Riddle will redirect users to a page on your site. You can read more about custom result pages for quizzes on our blog.

But if you want to take it a step further you need to use the data from the quiz to display dynamic content on the landing page.

Learn how to do just that in this simple example:

  • Direct your quiz takers to a page on your site depending on their quiz results.
  • Then use a simple PHP script to display data from the quiz on that site to make it personal and dynamic.

Create a simple quiz and use our pre-build custom result page to inspect the data we send to your page when the user finishes a quiz.

Use this link for your test: https://examples.riddle.com/custom-result-page.php

and please also refer to this guide to get the more info on how to test a custom result page.

Create PHP Code to process the data

You will need a code editor to create the custom PHP Code from this lesson. I am using Dreamweaver from Adobe which has a built in FTP client so I can upload the file to my server.

If you want to use free tools and do not have an FTP client or no FTP access to your site, use these alternatives:

Free Code Editor: Brackets

Create directories and upload files to WordPress using the File Manager Plugin.
A Word of warning for this plugin. You can completely destroy your WordPress site with this plugin. Make sure to not delete or rename any files or folders.

Instructions to get your custom code onto your site:

With your FTP client or the File Manager Plugin create a new folder directly below the root folder of your wordpress site. Name the folder “riddle” for example. Make sure to pick a name that is not used by WordPress (do not name it uploads for example). Then upload the file you created following the steps from this lesson to this folder.

Lastly enter the full URL of this file as the custom result page into Riddle, replacing the test URL we used in Lesson one. The file path could be https://www.mysite.com/riddle/customphpfile.php

Note: the file needs to be in a subdirectory of the WordPress site where you want to host the custom result page and your site needs to be SSL secured, meaning your domain needs to start with https and not http.

The code

Read our instructions on how the code works here on our documentation on custom result pages.

If you already know what you are doing, you can also just copy the code from below. Make sure to alter the $redirectPage values to match your site (more on that in lesson 3).

<?php
session_start();
$riddle = json_decode($_REQUEST['data']);
$riddle_score = $riddle->resultData->scoreNumber;
$_SESSION['riddle_name'] = $riddle->lead2->Name->value;
switch ($riddle_score) {
    case '0':
    $redirectPage = 'amateur-cook';//just enter the page or post name here not the full URL and do not add .php or .html or anything like that
    break;
    case '1':
    $redirectPage = 'amateur-cook';//just enter the page or post name here not the full URL and do not add .php or .html or anything like that
    break;
    case '2':
    $redirectPage = 'pro-cook';//just enter the page or post name here not the full URL and do not add .php or .html or anything like that
    break;
    // Add as many cases as you you like. The result number equals the number of correctly answered questions. This allows you to do your own segmenting, without sticking to the strict segments that Riddle uses on the default quiz result pages.
};
?>
<script>
 window.parent.location.href = 'https://pastafun.com/<?php echo $redirectPage;?>';//change this to the URL of your blog.
</script>

Just one quick reminder. Make sure to name the pages exactly as you did in the previous lesson’s PHP code. The file name needs to match your redirect variable values.

Add PHP Code to WordPress and put it all together

To create the PHP code that you need on your WordPress site use a PHP plugin like Insert PHP Code Snippet from xyzscripts.com

There are lots of other plugins like this on the market, but this one seemed to work perfectly fine, albeit you trade the “free” for many aggressive ads in admin backend.

The code you will add to the PHP snippet is below:

<?php
session_start();
$riddle_name = $_SESSION['riddle_name'];
echo "<p>Hi there, $riddle_name.</p>";
?>

Resources – custom result pages

Thank you for following along.

You can test our version of this setup on our sample site Pastafun.com

There are a few places on our blog and documentation that you might want to visit to read up more on our custom result page feature:

If things go wrong, here is where to look:

Did you use our test page to look up the exact way to find the values you want to use? Find out if your variables actually have the values you expect them to have. Remove the redirection JavaScript from the custom PHP code and add this PHP code prior to the closing ?> var_dump($riddle); var_dump($_SESSION);

Do a var_dump for any other variable you are using and check if they have the value you expect. If they don’t, you are not picking up the correct value.

If you are doing everything as we said and you are still not getting any data, check with your hosting company and ask them if they have security measures in place that prevent you from processing $_REQUEST data.

If that is not the case either, maybe the file you uploaded to your server is not working. Do something very simple. Remove the redirect script again and type echo (“hello world”); before the closing ?>. Now when you open the URL of your custom PHP file in a browser it should at least say “Hello World” on the screen. If it does not or if that produces an error, your hosting company may not allow for you adding files outside of WordPress. Ask them about it.

If you run into further problems, use the chat tool on riddle.com and we will try to help. Please understand though, that this is fairly advanced stuff and we may not be able to answer as fast as we usually do as not everyone in our support chat will know how to debug and fix issues with these things.