如何加载基于用户的代码变体? [英] How to load variations of a code based on user?

查看:61
本文介绍了如何加载基于用户的代码变体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够根据用户来存储代码的不同变体.因此,如果A用户登录,我希望他们看到与他们的偏好有关的代码/页面.

I want to be able to server different variations of a code based on the user. So if USer A signs in i want them to see code/pages pertaining to their preferences.

我知道我们可以做一个php/mysql来保存路径.但是我如何在同一页面上提供代码.所有用户都具有相同的页面index.php,home.php,profile.php,但是我希望能够通过简单地显示针对他们的代码来使用同一页面来满足那些请求.

I know we can do a php/mysql to save paths. But how do i serve the code on the same page. All users have the same page index.php, home.php, profile.php but i want to be able to use the same page to serve those requests by simply show the code that is specifc to them..

推荐答案

不完全确定这是否是您要追求的目标,但也许可以帮助您走上正确的路...

Not entirely sure if this is what you're after, but maybe it'll help get you on the right path...

<?php
    // sample preferences, read from database
    $userPrefs = array(
        'block1' => true,
        'block2' => false,
        'block3' => true
    );

    $block1 = '<div id="block1">This is Block #1!</div>' . PHP_EOL;
    $block2 = '<div id="block2">This is Block #2!</div>' . PHP_EOL;
    $block3 = '<div id="block3">This is Block #3!</div>' . PHP_EOL;

    if ($userPrefs['block1'] == true) { echo $block1; }
    if ($userPrefs['block2'] == true) { echo $block2; }
    if ($userPrefs['block3'] == true) { echo $block3; }
?>

输出:

<div id="block1">This is Block #1!</div>
<div id="block3">This is Block #3!</div>

这篇关于如何加载基于用户的代码变体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆