How To Show User A Random Video In ClipBucket

95 views October 18, 2016 Saqib Razzaq 1

It is good to have a button on website which users can click to watch a random video. It comes in handy when users are bored and don’t know what to watch. With help of this button you can decrease bounce rate and make user stay for longer on website.

Step 1:

Go to your main directory where Clipbucket is installed (public_html in most cases) and create a new file named randomvid.php. You can name it anything you want but this is what we will be using for this tutorial.

Step 2:

Now paste the below code in your newly created file.

 /*
***************************************************************
| Copyright (c) 2007-2009 Clip-Bucket.com. All rights reserved.
| @ Author : ArslanHassan
| @ Software : ClipBucket , © PHPBucket.com
***************************************************************
*/
define("THIS_PAGE",'random');
require 'includes/config.inc.php';
$urls = array (
'Your page URL',
'Your page URL',
'Your page URL',
'Your page URL',
);
$random = rand(1, count($urls));
$link = $urls[$random];
Header("Location:" . $link);
subtitle(lang('videos'));
//Displaying The Template
template_files('stumble.html');
display_it();
?>

What is this code doing?
$url:

This variable stores list of URLs out of which some URL you’d like your users to see upon clicking button.

$random:
rand() is a PHP function that shows random things from an array. It takes $url array and counts all urls and then picks one of them.

$link
This variable stores the currently picked URL

Header
Currently picked URL in $link variable is shown.

Step 3:

Navigate to Styles / yourtheme / layout and create a new file called randomvid.html
Leave this file empty and hit save button.

Step 4:

Now open header.html and add below code where you want the link to appear.

Note: Add the same code anywhere on your website and this feature will work just fine.

Was this helpful?