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. Add extra field to users
  3. Integrating WordPress to my website, while keeping my own authentication system
  4. Display user’s total comment count outside The Loop
  5. Changing user_nicename
  6. How to auto login user again after change user_login
  7. What is the most efficient way to search users by their display name?
  8. Can i check if user is doing any ajax request?
  9. How do I create a WP user outside of WordPress and auto login?
  10. Network installation giving errors when viewing or adding a user
  11. Showing user ID on user main page from screen options
  12. Getting the Current User
  13. How do I hide specific user profile fields?
  14. Authenticating to WordPress, using my own authentication two-factor system
  15. How to track a users progress through pages by inserting data into WordPress Database?
  16. automated tests as a user?
  17. How can I default to all WordPress roles when parameter is not included in shortcode?
  18. there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
  19. Delete option value from array using update_option()
  20. get_users(…) only returns one user
  21. List User order by ID in Descending order (Backend)
  22. Warning: Use of undefined constant HTTP_USER_AGENT – assumed ‘HTTP_USER_AGENT’ (this will throw an Error in a future version of PHP)
  23. Get all user meta by meta key instead of ID
  24. How to get a list of all possible values of a specific user meta key?
  25. User’s total comment count excluding comments on their own posts
  26. User management system similar to wordpress one?
  27. Show all posts by author
  28. Custom user login page by creating a plugin
  29. Programmatic Login from 3rd Party site
  30. Add New User, extra fields which are required?
  31. user_profile_update_errors hook not executing
  32. Modify user profile data through scripting?
  33. Get users that likes the post
  34. custom user role wordpress – grant guest access to edit.php without insert/update/delete
  35. add_cap not working
  36. Do not execute If User is login as Administrator or any Specific Role
  37. wordpress archive a user
  38. Best practice for show data to one specific user?
  39. Call to undefined function get_userdata() in plugin
  40. get_users meta_query: REGEXP not working for matching new lines
  41. Change CSS based on is_user_logged_in
  42. How to show a users bio on a page
  43. “operation successful” message
  44. php if username is role
  45. How do you create two separate Register pages?
  46. Is it possible to create new user from external form using REST API?
  47. Foreach loop inside an array_merge
  48. Show current user posts only
  49. Change page password every day (predictable password ;) )
  50. Get the users that my following users are following
  51. create front-end users post list by specific category
  52. Show site content based on user role
  53. ‘pre_user_query’ interfering with user export
  54. php return username of currently viewed author profile
  55. How to list users like an archive page 10 users on page and have navigations
  56. How can I call a specific file (via php) by referencing the logged-in username?
  57. Redirect to current user page upon link click
  58. Use of antispambot with $curauth->email
  59. Uses for function: wp_update_user
  60. Display additional user fields
  61. Generate a QR code when creating a new WordPress user
  62. Change wordpress’ database data using ajax – how to get current user id?
  63. Sort new column in Users wp-admin
  64. Sort column in Users admin Tab
  65. Integrate otp in my custom singup form
  66. Allow a user or role to view drafts and previews, but not other admin privileges?
  67. Woocommerce display orders with products from specific categories to specific admins
  68. Storing huge number of users in wordpress
  69. Private messaging – Getting and displaying the avatar/url of a message recipient
  70. Updating custom user meta
  71. Loop 1 user randomly
  72. Update only some custom user fields
  73. List users in a dropdown for login
  74. How to set max users to 17.000
  75. Trying to display user meta by “name” – not by “ID”
  76. main menu page redirects to user ID
  77. How to ‘remember’ a site member’s last visited page?
  78. How to connect database table to each registered wordpress user.
  79. Adapting a php array to WordPress
  80. Get author meta of all writers
  81. Let users register weight each day and save it in DB
  82. Display a list of users with avatar filterable with alphabets
  83. Cross origin ajax request always returns 0 when calling get_current_user_id();
  84. Parse error: syntax error, unexpected ‘}’ in C:\wamp64\www\Proiect\aplicatie\user_check.php on line 18 [closed]
  85. Forbid certain users to access a specific page
  86. Check if username doesn’t exists
  87. One folder to be accessible by one user
  88. WP query with variables gives no result for specific user
  89. Import users and custom user meta from csv
  90. How to lock users account until approvation
  91. rest_cannot_create_user – Sorry, you are not allowed to create new users. CURL WORDPRESS REST API
  92. Getting invalid user ID error when creating a new user with wp_insert_user
  93. How to create a User Role and give permission to only use Web Stories plugin?
  94. How to create custom user role without plugin?
  95. PHP Works only for logged in users: [closed]
  96. Custom Admin Menu Report for Specific User ID
  97. How to add custom user role into wordpress
  98. Redirect WordPress page to the latest created post by the logged in author/user
  99. Only registered users can see part of the contents of single.php
  100. change Dashboard default page on login
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
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 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