Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Limit Page Access

Featured Replies

It seems that I managed to stump everyone with my last question.

 

I have a new problem...

 

I've been requested to create a page that has access to several different forms.

 

In order to access the form, the user will need to go through an "I Accept" page with the policy spelled out for them

Click on "I Accept"

Then be directed to the form

 

 

QUESTION:

Is there a way to make the form page so they cannot just type in the URL to get there, but make it so the are FORCED to only have access to the form page by going through the "I Accept" page?

 

 

 

I've been searching and am not even sure what to look for to find the answer to this question.

 

Please help if you can!

 

Thanks so much.

 

~JJ

Hey newby. This is fairly straightforward - I'll assume you're using PHP, but it's going to be possible in any server-side language. You could even do it in Javascript, but that wouldn't be secure.

 

Say for example that your policy page has the following:

 

<form method="post" action="form.php">
<input type="submit" name="accept" value="I accept" />
</form>

 

Clicking the submit button will take them to form.php. To check that they didn't just type the URL in, you'd have the following at the top of form.php:

 

<?php

if (!isset($_POST["accept"])) {
// Do what you want here - display an error message, etc.
// I'm going to send them back to the policy page
header("Location: policy.php");
die;
}

?>

  • Author

Awesome Nathan,

 

Thanks so much for your help!! I'll give it a try this week.

Just would like to confirm that Nathan's solution is spot on.

I use this on many occassions to redirect users that have not gone through the 'correct' route to a page.

My twist on the code is:

 

<?
// redirect to ....php if POST is NULL
if ($_POST['accept'] == NULL)
{
header("Location: policy.php");
exit;
}
?>

 

But might start using Nathan's version of the code block as it looks more professional. And might be more efficient.

Changing my code to use 'isset' from now on.

 

Am I also correct in reading that the redirect code block must be at the top of the page before any other characters, whitespace?

 

I usually put some notes in a php code block for 'my eyes only' above the redirect code block and seems to be OK. So that must be characters, whitespace not in a php block that is not allowed, if you see what I mean.

Yep, that's right. The <? has to be the first thing in the page.

Changing my code to use 'isset' from now on.

 

Am I also correct in reading that the redirect code block must be at the top of the page before any other characters, whitespace?

 

I usually put some notes in a php code block for 'my eyes only' above the redirect code block and seems to be OK. So that must be characters, whitespace not in a php block that is not allowed, if you see what I mean.

 

Yes, all headers must be sent before anything is outputted to the browser. (any HTML, echo or print statement. (note that PHP errors outputted counts as well).

 

You can use output buffering to catch any data that might be sent before the headers and ensure you send all your headers first. Have a look at http://no.php.net/manual/en/ref.outcontrol.php

Yep, that's right. The <? has to be the first thing in the page.

 

No, the PHP opening tag doesn't have to be the first thing. It can appear anywhere.

 

Might you be refering to the XML decleration?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.