...

View Full Version : Accept Terms of Agreement button



bucket
10-18-2009, 02:55 AM
Hello. I am wondering how to make a accept terms of agreement button.

Like there will be a paragraph with the terms and then a button that says 'I agree' or 'I do not agree'.

I want the Agree button to go to the next page, but the next page cannot be visited by itself unless you accept and read the terms from the first page. Can someone give me a script to do that?

I have looked around but most of them are like a pop up for when a check box is missing.

whizard
10-18-2009, 05:50 AM
Maybe along the lines of

if($_SESSION['agreement'])
{
//Show page
}
else
{
//Show form
}

?

Dan

Phil Jackson
10-18-2009, 08:14 AM
if(isset($_POST['checkBoxName']) && $_POST['checkBoxName']=="checked"))


i think

bucket
10-18-2009, 03:01 PM
Okay so I got this for now.


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="blah" NAME="blah" onSubmit="return validateData()">

and

<input type = "button" id = "but1" value = "I DO accept the terms and conditions" onclick = "redirect()">
<input type = "button" id = "but2" value = "I DO NOT accept the terms and conditions" onclick = "cancel()">

<script type = "text/javascript">

function redirect() {
window.location = "page2.html";
}
function cancel() {
window.location = "http://google.com";
}
</script>

So how would I integrate what you guys gave me to this?

I would like to put them together.

powerfear
10-18-2009, 04:37 PM
Here a simple example add your code and modify it like you want



<?php
if (isset($_POST['submit'])) {
//your page if agreed
} else {
?>
//page to read and agree or decline
<title>Therm of use</title>
<center><h1>Therm of use</h1>
<br>Therm of use go here.....</center><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="submit" value="I agree">
<input type="submit" name="submit2" value="I disagree">
</center>
</form>
<?php
}
if (isset($_POST['submit2'])) {
//code for if don't agree
}
?>

oracleguy
10-18-2009, 05:25 PM
Okay so I got this for now.


<form action="<?php echo $_SERVER['PHP_SELF']; ?>" id="blah" NAME="blah" onSubmit="return validateData()">

and

<input type = "button" id = "but1" value = "I DO accept the terms and conditions" onclick = "redirect()">
<input type = "button" id = "but2" value = "I DO NOT accept the terms and conditions" onclick = "cancel()">

<script type = "text/javascript">

function redirect() {
window.location = "page2.html";
}
function cancel() {
window.location = "http://google.com";
}
</script>

So how would I integrate what you guys gave me to this?

I would like to put them together.

Don't use JavaScript for the buttons, use a form and have it submit and process the user's choice on the server side.

bucket
10-18-2009, 05:56 PM
Here a simple example add your code and modify it like you want



<?php
if (isset($_POST['submit'])) {
//your page if agreed
} else {
?>
//page to read and agree or decline
<title>Therm of use</title>
<center><h1>Therm of use</h1>
<br>Therm of use go here.....</center><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="submit" name="submit" value="I agree">
<input type="submit" name="submit2" value="I disagree">
</center>
</form>
<?php
}
if (isset($_POST['submit2'])) {
//code for if don't agree
}
?>


Its not working at all, nothing shows up when I click I agree.

Okay so thats the whole thing?

Phil Jackson
10-18-2009, 06:35 PM
<?php
if (isset($_POST['submit2'])) {
echo "i dont agree";
}
elseif (isset($_POST['submit'])) {
echo "i do agree";
}
else
{
?>
//page to read and agree or decline
<title>Therm of use</title>
<center><h1>Therm of use</h1>
<br>Therm of use go here.....</center><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="submit" name="submit" value="I agree">
<input type="submit" name="submit2" value="I disagree">
</center>
</form>
<?php
}

?>

bucket
10-18-2009, 10:16 PM
I would like to also add it so you cannot bypass the first page/visit like page2.php without like a session or something.

Like it redirects back.

Phil Jackson
10-18-2009, 10:19 PM
what is the URL of this page and what is the URL of page2?

bucket
10-18-2009, 10:21 PM
first page index.php

and the second page is index2.php


Il edit them by myself. Just make it like page1 and page2.php.

Thank You phil.

bucket
10-18-2009, 10:40 PM
Any luck phil?

Phil Jackson
10-18-2009, 10:41 PM
untested.. wrote it quick, but should work. Also not bullet proof but added security



<?php

function throughRefererOnly($pageRedirect, $fullPageDir, $referer, $errorMsg)
{
$PQwebsite = preg_quote($fullPageDir, "#");
if(!preg_match("#^".$PQwebsite."$#is", $referer))
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
}

$pageRedirect = "http://www.yourwebsite.co.uk/index.php";
$fullPageDir = "http://www.yourwebsite.co.uk/index2.php";
$errorMsg = "You do not have permission to access those files.";

// here you should put something like if(!isset($_POST['submitButton'])) { header("location: ".$pageRedirect."?error=".$errorMsg); exit; }
throughRefererOnly($pageRedirect, $fullPageDir, $_SERVER['HTTP_REFERER'], $errorMsg);

//recall error on index.php through if(isset($_GET['error'])) { echo $_GET['error']; }
?>


add to the top of index2.php and fill in the required variables

bucket
10-18-2009, 10:48 PM
kk thanks

bucket
10-18-2009, 10:50 PM
Doesn't seem to work.

Try it yourself.

Phil Jackson
10-18-2009, 10:55 PM
for your instance:



<?php

function throughRefererOnly($pageRedirect, $fullPageDir, $referer, $errorMsg)
{
$PQwebsite = preg_quote($fullPageDir, "#");
if(!preg_match("#^".$PQwebsite."$#is", $referer))
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
}

$pageRedirect = "http://www.yourwebsite.co.uk/index.php"; // redirected to if invalid
$fullPageDir = "http://www.yourwebsite.co.uk/index.php"; // allowed from
$errorMsg = "You do not have permission to access those files.";

// here you should put something like if(!isset($_POST['submitButton'])) { header("location: ".$pageRedirect."?error=".$errorMsg); exit; }
throughRefererOnly($pageRedirect, $fullPageDir, $_SERVER['HTTP_REFERER'], $errorMsg);

//recall error on index.php through if(isset($_GET['error'])) { echo $_GET['error']; }
?>

Phil Jackson
10-18-2009, 10:59 PM
are you trying on wamp server of somerthing like that?

Phil Jackson
10-18-2009, 11:08 PM
ah... http_referer may be turned of by your host.

Phil Jackson
10-18-2009, 11:36 PM
i put some more thought into it:



<?php

$pageRedirect = "http://www.yoursite.co.uk/2.php";
$errorMsg = "You do not have permission to access those files.";

function throughRefererOnly($pageRedirect, $serverAdd, $method, $errorMsg, $hash)
{
if($method!=="POST")
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
$time = time();
if(md5($serverAdd.floor($time/(3*60)))!==$hash)
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
}

if(isset($_POST['submit']))
{
throughRefererOnly($pageRedirect, $_SERVER['SERVER_ADDR'], $_SERVER['REQUEST_METHOD'], $errorMsg, $_POST['hash']);
}
?>



<form method="POST" action="2.php">
<input type="hidden" name="hash" value="<?php $time = time(); echo md5($_SERVER['SERVER_ADDR'].floor($time/(3*60))); ?>" />
<input type="submit" name="submit" value="submit" />
</form>


This example is all on the same page, called 2.php.

It will only return true if;

a) a post method was submited (will only work if on separate pages)
b) was from your server
c) submit was submitted within 3 minutes of page being loaded

bucket
10-19-2009, 10:51 PM
Phil, if u can post what should be on page.php and page2.php


Right now i got this for page2.php


<?php

$pageRedirect = "page2.php";
$errorMsg = "You do not have permission to access those files.";

function throughRefererOnly($pageRedirect, $serverAdd, $method, $errorMsg, $hash)
{
if($method!=="POST")
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
$time = time();
if(md5($serverAdd.floor($time/(3*60)))!==$hash)
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
}

if(isset($_POST['submit']))
{
throughRefererOnly($pageRedirect, $_SERVER['SERVER_ADDR'], $_SERVER['REQUEST_METHOD'], $errorMsg, $_POST['hash']);
}
?>



<form method="POST" action="2.php">
<input type="hidden" name="hash" value="<?php $time = time(); echo md5($_SERVER['SERVER_ADDR'].floor($time/(3*60))); ?>" />
<input type="submit" name="submit" value="submit" />
</form>

What should be on page.php

bucket
10-19-2009, 10:56 PM
This is also for a php installation script I have for my whole script.

Its basicly I want the users to accept the terms when they install the script.

Its like index.php will be the agreement and install.php will be the form, and I only want people to access install.php after they have accepted the terms on index.php page.

godofreality
10-20-2009, 06:39 AM
will you be using a login or anything for your website if so u can prevent unauthorized page viewing using a session if not u can just add this to your page u have with the terms agreement


<?php
if (isset($_POST['submit2'])) {
echo "i dont agree";
}
elseif (isset($_POST['submit'])) {
//my addition below
session_start();
$_SESSION['confirmed'] = true;

echo "i do agree";
}
else
{
?>
//page to read and agree or decline
<title>Therm of use</title>
<center><h1>Therm of use</h1>
<br>Therm of use go here.....</center><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="submit" name="submit" value="I agree">
<input type="submit" name="submit2" value="I disagree">
</center>
</form>
<?php
}

?>



then at the top of every page u don't want them to view add this


<?php
session_start();
if(isset($_SESSION['confirmed']) && $_SESSION['confirmed'] == true)
{
//add the page you would like them to see
}
else
{
//the redirect
?>
<body onload="window.open('index.php', '_self')">
</body>
<?php } ?>

Phil Jackson
10-20-2009, 06:55 AM
<body onload="window.open('index.php', '_self')">

header("location: index.php");
exit;

godofreality
10-20-2009, 07:43 AM
header("location: index.php");
exit;

both will work but as far as i am aware using a header to redirect causes your session data to get destroyed and using the onload event does not but i could be wrong on that never really tried it i always just used the javascript method

Phil Jackson
10-20-2009, 09:04 AM
as far as i am aware. they dont BOTH work. Only one is guaranteed to work every time.

bucket
10-20-2009, 01:14 PM
I have no idea whats going on.

Your saying I am unable to visit page2.php unless I go to it starting from page1.php correct

So page1.php is:


<?php
if (isset($_POST['submit2'])) {
echo "i dont agree";
}
elseif (isset($_POST['submit'])) {
//my addition below
session_start();
$_SESSION['confirmed'] = true;
header("location: page2.php");
}
else
{
?>
//page to read and agree or decline
<title>Therm of use</title>
<center><h1>Therm of use</h1>
<br>Therm of use go here.....</center><br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="submit" name="submit" value="I agree">
<input type="submit" name="submit2" value="I disagree">
</center>
</form>
<?php
}

?>

and page2.php is


<?php
session_start();
if(isset($_SESSION['confirmed']) && $_SESSION['confirmed'] == true)
{
//add the page you would like them to see
}
else
{
header("location: page1.php");
exit;
?>

<?php
} ?>

Correct? I fixed what Phil Jackson told me to fix. And I made it redirect when I agree instead of just saying I agree.

--EDIT---

THAT WORKS EXACTLY HOW I WANTED TO! :)

It redirects back to page1.php is theres no session.

Thank You!
How would I kill the session after it goes to page2.php?

Phil Jackson
10-20-2009, 02:12 PM
index.php :



<form method="POST" action="2.php">
<input type="hidden" name="hash" value="<?php $time = time(); echo md5($_SERVER['SERVER_ADDR'].floor($time/(3*60))); ?>" />
<input type="submit" name="submit" value="submit" />
</form>


index2.php :


<?php

$pageRedirect = "index.php";
$errorMsg = "You do not have permission to access those files.";

function throughRefererOnly($pageRedirect, $serverAdd, $method, $errorMsg, $hash)
{
if($method!=="POST")
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
$time = time();
if(md5($serverAdd.floor($time/(3*60)))!==$hash)
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
}

if(isset($_POST['submit']))
{
throughRefererOnly($pageRedirect, $_SERVER['SERVER_ADDR'], $_SERVER['REQUEST_METHOD'], $errorMsg, $_POST['hash']);
?>

all your code for page index2.php here


<?php
}
else
{
header("location: ".$pageRedirect."?error=".$errorMsg);
exit;
}
?>

Phil Jackson
10-20-2009, 02:25 PM
<?php
session_start();
if(isset($_SESSION['confirmed']) && $_SESSION['confirmed'] == true)
{
//add the page you would like them to see
}
else
{
session_destroy(); //to kill all sessions
unset($_SESSION['sessionname']); //to kill individual
header("location: page1.php");
exit;
?>

<?php
} ?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum