I have a site with basically 3 home pages depending on the type of customer. Depending on what home page they come in on, I want them to be linked back to that same home page when they clicked on “home” in the navigation or the logo.
I’m guessing I need to use a Global variable along with some PHP. Any recommendations or possible Plugin?
Thanks,
Dan
Welcome to Sitepoint Dan.
This sounds like a perfect application for the PHP session variable.
If you wish to ‘persist’ the choice (indicating which page the user “belongs to”) you could write it into a cookie.
Thanks for your quick response ParkinT.
I agree with the PHP session variable. Do you know if I can link to a specific webpage within the PHP code?
ex: If session_variable = “homepage1”
link to homepage1
Thanks
As PHP generates the HTML for the browser, you will make ‘decisions’ about which page; based on the user.
Either the user details are retrieved from a database or dynamically (during this session) you have made a decision about this user as to which page(s) they will see.
Build a global array of the “types” of users and related pages.
Then when you create the hyperlink - in PHP code - just add the “href” value based on the current “UserType” (which I would include as a session variable). Something like this:
<a href="<?php echo $usertype[$current_user_type][0]; ?>" target="parent">HOME</a>
This assumes you have the global array of user types (one element for each different user) and pages. For example:
<?php
$usertype["basic"][0] = "home1.php";
$usertype["basic"[1] = "links1.php";
$usertype["advanced"][0] = "home2.php";
$usertype["advanced"][1] = "links2.php";
$usertype["novice"][0] = "home3.php";
$usertype["novice"][1] = "links3.php";
?>
I think you get the idea. Your actual variable names and page names will, likely, be different.
=====================================================================
Another - simple - approach would be to encode the pagenames IN the session (group) value. Like this:
<a href="home<?php echo session['user_group']; ?>.php">Home</a>
You then create pages
- homebasic.php
- homeadvanced.php
- homenovice.php
Or some variation on this idea.
Thanks again… I think that would work well.
Since the “Home” link is a Wordpress Menu item, is it possible to add this code to it? (<a href=“home<?php echo session[‘user_group’]; ?>.php”>Home</a>)
Thanks for all your help.