Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

show something only when user comes from specific page at remote host?

$_SERVER['HTTP_REFERER'] gets all the info you need, not just the domain – so you just need to drill deeper into the data you are already getting.

I’d suggest only setting one variable to make sure you don’t paste something wrong into the second – you can check for the www version by appending ‘www.’.

Your current code would display the page to anyone who accesses the page directly with no referrer (i.e. by bookmark or search engine result) and it sounded like you only want people who successfully completed the quiz to be able to view the page, so I also removed the part where you set the domain to the right one if the referer was empty.

You may need to tweak this a bit, but it should point you in the right direction:

<?php
// set the non-www allowed domain, path, and title
$allowedDomain = 'thequizhost.com';
$allowedPath="/the-quizzes/quizzing.php"
$allowedQuery = 'our-specific-quiz-we-need-to-echek-for'
// grab the HTTP referer using WP's built-in function
$referer = wp_get_referer();
// if referer is not empty
if (!empty($referer)) {
    // split url to check its pieces
    $refererData = parse_url($referer);
    // check domain, both non-www and www
    if($refererData['host'] == $allowedUrl || $refererData['host'] == 'www.'.$allowedUrl) {
        // check the path
        if($refererData['path'] == $allowedPath) {
            // parse the query string
            parse_str($refererData['query'], $queryString);
            // check just the "title" variable
            if($queryString['title'] == $allowedQuery) {
                // now we know they really completed the quiz
                $showForm = true;
            }
        }
    }
}
// if $showForm is true, they've been verified and can see the form
if($showForm == true) {
    do_shortcode("[signup_form id='2']");
// they didn't come from the right place, so don't show the form
} else {
    // redirect to homepage, or wherever you like
    wp_safe_redirect(home_url()); exit;
}
?>

If you think there’s a good chance visitors will try to hit the page without taking the quiz, instead of redirecting, you could display alternate content – something to the effect of “Thanks for your interest. Please take the quiz (link here) to enable signup.”

Related Posts:

  1. Create a global variable for use in all templates
  2. Integrating WordPress to my website, while keeping my own authentication system
  3. Display user’s total comment count outside The Loop
  4. Changing user_nicename
  5. How to auto login user again after change user_login
  6. Can i check if user is doing any ajax request?
  7. How do I create a WP user outside of WordPress and auto login?
  8. Showing user ID on user main page from screen options
  9. Getting the Current User
  10. How do I hide specific user profile fields?
  11. Authenticating to WordPress, using my own authentication two-factor system
  12. How to track a users progress through pages by inserting data into WordPress Database?
  13. automated tests as a user?
  14. How can I default to all WordPress roles when parameter is not included in shortcode?
  15. there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
  16. Delete option value from array using update_option()
  17. get_users(…) only returns one user
  18. List User order by ID in Descending order (Backend)
  19. Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
  20. Get all user meta by meta key instead of ID
  21. How to get a list of all possible values of a specific user meta key?
  22. User’s total comment count excluding comments on their own posts
  23. User management system similar to wordpress one?
  24. Show all posts by author
  25. Custom user login page by creating a plugin
  26. Programmatic Login from 3rd Party site
  27. Add New User, extra fields which are required?
  28. Modify user profile data through scripting?
  29. Get users that likes the post
  30. custom user role wordpress – grant guest access to edit.php without insert/update/delete
  31. Do not execute If User is login as Administrator or any Specific Role
  32. Best practice for show data to one specific user?
  33. Call to undefined function get_userdata() in plugin
  34. get_users meta_query: REGEXP not working for matching new lines
  35. Change CSS based on is_user_logged_in
  36. How to show a users bio on a page
  37. “operation successful” message
  38. php if username is role
  39. Is it possible to create new user from external form using REST API?
  40. Foreach loop inside an array_merge
  41. Show current user posts only
  42. Change page password every day (predictable password ;) )
  43. Get the users that my following users are following
  44. create front-end users post list by specific category
  45. Show site content based on user role
  46. php return username of currently viewed author profile
  47. How to list users like an archive page 10 users on page and have navigations
  48. Redirect to current user page upon link click
  49. Use of antispambot with $curauth->email
  50. Uses for function: wp_update_user
  51. Generate a QR code when creating a new WordPress user
  52. Change wordpress’ database data using ajax – how to get current user id?
  53. Sort column in Users admin Tab
  54. Integrate otp in my custom singup form
  55. Allow a user or role to view drafts and previews, but not other admin privileges?
  56. Woocommerce display orders with products from specific categories to specific admins
  57. Storing huge number of users in wordpress
  58. Admin Panel 404 Error after login
  59. How to block specific user id in custom login form?
  60. Get current user id in function php
  61. how can I call a function when time expire
  62. Call WP Rest-Api to GET /users/me returned NOTHING in console
  63. Uploading/integrating custom user registration page
  64. If user has clicked link add class and store using PHP/WordPress
  65. Store data from JavaScript object to custom table in user account
  66. Page template not working when logged out
  67. How to change the value of a variable using input field?
  68. Display current user metadata on WordPress page
  69. How do I track which user clicked my button?
  70. Use WP user status (logged_in) to manage access to independent application
  71. Add another role to a user when they click a button?
  72. Query to show average # of months all accounts with specific role have been active
  73. wordpress more than one ajax request at the same time issue
  74. Can’t get_users info by using json_encode
  75. Editable Student file associated with basic User ID
  76. Adding users to another blog
  77. Changing WordPress author name in database
  78. Private messaging – Getting and displaying the avatar/url of a message recipient
  79. Updating custom user meta
  80. Loop 1 user randomly
  81. Update only some custom user fields
  82. How to set max users to 17.000
  83. main menu page redirects to user ID
  84. How to ‘remember’ a site member’s last visited page?
  85. How to connect database table to each registered wordpress user.
  86. Get author meta of all writers
  87. Let users register weight each day and save it in DB
  88. Display a list of users with avatar filterable with alphabets
  89. Parse error: syntax error, unexpected ‘}’ in C:\wamp64\www\Proiect\aplicatie\user_check.php on line 18 [closed]
  90. Forbid certain users to access a specific page
  91. Check if username doesn’t exists
  92. WP query with variables gives no result for specific user
  93. Import users and custom user meta from csv
  94. How to lock users account until approvation
  95. rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
  96. Getting invalid user ID error when creating a new user with wp_insert_user
  97. How to create a User Role and give permission to only use Web Stories plugin?
  98. How to create custom user role without plugin?
  99. How to add custom user role into wordpress
  100. Redirect WordPress page to the latest created post by the logged in author/user
Categories PHP Tags php, signup, users
Javascript not loading after the document ready
The Capability to choose post/page template

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress