Php terms and conditions

Different pages > terms & conditions > different pages

This is going to be tricky to explain, but i’m having trouble with a ‘terms & conditions’ page. I need to make ONE terms & conditions, but different pages get the user to this terms, and depending the page he came from, after agreeing, he gets redirected to the correspondent page. kind of A1.php > terms & conditions.php > A2.php B1.php > terms & conditions.php > B2.php This terms & conditions page is the same for everyone, but how can i make her redirect depending on where the user came from? Is that possible? Thank you.

Lucas, how are you getting the link for the next page? I mean, the page that must open after Terms and Conditions are accepted, the link to that page, how do you get it or where do you get it from?

2 Answers 2

What most people to, and what works the most reliable, is to add some kind of url variable. Instead of redirecting to terms_and_conditions.php , you instead redirect like this:

B1.php > terms_and_conditions.php?redirect=A2.php > A2.php B1.php > terms_and_conditions.php?redirect=B2.php > B2.php 

This way, some people who knows this may see the url, and just type «A2.php» on the browser and skip the Terms and conditions, right ?

Yes. But if you rely on the URL being ‘secret’ for security, you don’t have much security at all. If you want to track if a person really saw (and accepted) the terms and conditions, you need to store that information somehow.

Next is a real example of how to do it. Lucas, you will have to create 5 text files, name them with the next given names, copy-paste the codes to the corresponding files, and, finally, open your browser and type : «localhost/a1.php» and «localhost/b1.php».

  This is A1. To enter A2 you have to accept Terms and Conditions. 

  This is B1. To enter B2 you have to accept Terms and Conditions. 

terms_and_conditions.php

  Terms and Conditions 

Bla bla bla bla bla .

  This is A2. Thanks for accepting Terms and Conditions.  
  This is B2. Thanks for accepting Terms and Conditions.  

The tricky part is in terms_and_conditions.php. Pay attention to the action, which value comes from PHP. This is how only one Terms and Conditions can be used by many pages.

The page to open next is in a1.php and b1.php. Take a look at the input text named «next_page» (display:none). The «value» will have to change for every page.

Hello Jose, thank you for your reply. I get it! It’s kind of sending a hidden input with a setted value. The problem goes deeper when i tell you that I can’t change the pages A1/B1 source code. The only thing that i can do is tell what link goes to the Terms and Conditions. Is there a way out?

If many pages must jump to other pages through Terms and Conditions, the first pages MUST KNOW what are their corresponding next pages, so Terms and Conditions will be able to get this data and use it to open the next pages. Lucas said The only thing that i can do is tell what link goes to the Terms and Conditions, well, that link is what Terms and Conditions requires, the problem is, HOW TO PASS THE LINK to Terms and Conditions. In my answer we are using a HTML form, but there is another way : to store the link in PHP session. All depends on how Lucas is getting the link (by form or session).

Источник

Conditional Statements in PHP code Between HTML Code

I’m having a bit of an issue by using Conditional Statements in PHP separated by HTML code. This is the type of code I’m trying to write. This is a profile page and it should only be seen by the user whose profile it is (i’m using session variables for checking that) :

But this doesn’t work. I also tried using the shorthand notation by putting a : at the end of the if and using the endif statement, but it didn’t work. ( On an earlier project , the : method worked for foreach and endforeach so I thought I would try it out ) Any Ideas ?

7 Answers 7

You probably forgot the endif of the alternative control structure syntax:

Omitting the braces as you wrote is not possible. It is only possible if it is followed by a regular statement.

Notice an annoying bug that i’ve just had — you have to use

PHP has two styles of notation for if() blocks (and blocks in general).

Firstly, you have the wordy notation, which involves explicitly stating endif; at the end of the if() block. It looks like this:

if(whatever): do something else: do something else endif; 

The colons at the end of the if and else lines are important, because otherwise PHP thinks you’re using the other notation (below).

Secondly, you have the curly-braces notation, which looks similar to C or Perl style code, and looks like this:

With this style notation, you are allowed to leave the pairs of curly-braces off if your block is only going to be one line long. (I personally think it’s bad practice to leave them off like this, but plenty of people swear by it, and it is perfectly valid syntax. But I’ve seen PHP get confused over single-line blocks when you’re switching between PHP code and HTML; this is why I always prefer to use braces even if I’m only writing one line).

The problem in your case is that you’ve mixed the two notations. You’s trying to us the wordy notation, but don’t have the colons on the lines, so PHP thinks you mean the braces notation. But because the braces notation allows for the braces to be missed out, PHP is seeing your code as valid syntax, even if it isn’t going to work quite as you planned.

Your solution is to tidy it up so that you are definitely using one syntax or the other. Either add braces ( < and >>) to the start and end of each block as shown in my example, or add colons and an endif; line.

So your code should look like one of these two examples:

Источник

Add a terms and conditions checkbox in Woocommerce registration form

In woocommerce registration form, there’s no «terms and conditions» before sign up button. Is there a way to make it appears in the form? Here is the link of my theme layout.

1 Answer 1

Updated on july 2018 — Added compatibility for Woocommerce version 3.4+

If not done yet, first you need enable terms and conditions on checkout page:

enter image description here

  1. To create a new page in WordPress for your terms and conditions
  2. To enable that page in Woocommerce > Settings > Checkout > Checkout pages (section):
  3. Then save… you are done.

The code to get the term and conditions check box on registration form:

// Add term and conditions check box on registration form add_action( 'woocommerce_register_form', 'add_terms_and_conditions_to_registration', 20 ); function add_terms_and_conditions_to_registration() < if ( wc_get_page_id( 'terms' ) >0 && is_account_page() ) < ?> 

> // Validate required term and conditions check box add_action( 'woocommerce_register_post', 'terms_and_conditions_validation', 20, 3 ); function terms_and_conditions_validation( $username, $email, $validation_errors ) < if ( ! isset( $_POST['terms'] ) ) $validation_errors->add( 'terms_error', __( 'Terms and condition are not checked!', 'woocommerce' ) ); return $validation_errors; >

Code goes in function.php file of your active child theme (or active theme). Tested and works.

enter image description here

When checkbox is not ticked, an error message is displayed.

enter image description here

This checkbox is only a validation step (It is not saved in database, as we don’t use that information anywhere).

Addition:

To allow terms and conditions only in Registration page use one of the following:

add_filter( 'woocommerce_checkout_show_terms', '__return_false' ); 
add_filter( 'woocommerce_get_terms_and_conditions_checkbox_text', '__return_false' ); 

Code goes in function.php file of your active child theme (or active theme). Tested on WC 3.5+ and works.

Источник

Using AND/OR in if else PHP statement

How this will work?? $items_list = array(2,177); $rules_list = array( ‘[(13 OR 3 OR 2 )]’, ‘[(54 OR 77 ) AND 17 AND 59 AND 36 ] OR [(2 AND 36 )]’, ‘[(2 OR 3 OR 13 ) AND 30 ]’, ‘[(2 )] OR [(13 OR 4 ) AND (17 )]’, ‘[(2 )] OR [(13 OR 3 ) AND 17 ]’, ‘[(2 AND 30 ) OR (3 AND 30 )]’, ); //Calculate the bool result of each rule using the provided items array`

10 Answers 10

  • Many programmers prefer && and || instead of and and or , but they work the same (safe for precedence).
  • $status = ‘clear’ should probably be $status == ‘clear’ . = is assignment, == is comparison.

There’s some joking, and misleading comments, even partially incorrect information in the answers here. I’d like to try to improve on them:

First, as some have pointed out, you have a bug in your code that relates to the question:

if ($status = 'clear' AND $pRent == 0) 

should be (note the == instead of = in the first part):

if ($status == 'clear' AND $pRent == 0) 

which in this case is functionally equivalent to

if ($status == 'clear' && $pRent == 0) 

Second, note that these operators ( and or && || ) are short-circuit operators. That means if the answer can be determined with certainty from the first expression, the second one is never evaluated. Again this doesn’t matter for your debugged line above, but it is extremely important when you are combining these operators with assignments, because

Third, the real difference between and or and && || is their operator precedence. Specifically the importance is that && || have higher precedence than the assignment operators ( = += -= *= **= /= .= %= &= |= ^= >= ) while and or have lower precendence than the assignment operators. Thus in a statement that combines the use of assignment and logical evaluation it matters which one you choose.

will evaluate to true and assign that value to $e , because || has higher operator precedence than = , and therefore it essentially evaluates like this:

will assign false to $e (and then perform the or operation and evaluate true ) because = has higher operator precedence than or , essentially evaluating like this:

The fact that this ambiguity even exists makes a lot of programmers just always use && || and then everything works clearly as one would expect in a language like C, ie. logical operations first, then assignment.

Some languages like Perl use this kind of construct frequently in a format similar to this:

$connection = database_connect($parameters) or die("Unable to connect to DB."); 

This would theoretically assign the database connection to $connection , or if that failed (and we’re assuming here the function would return something that evalues to false in that case), it will end the script with an error message. Because of short-circuiting, if the database connection succeeds, the die() is never evaluated.

Some languages that allow for this construct straight out forbid assignments in conditional/logical statements (like Python) to remove the amiguity the other way round.

PHP went with allowing both, so you just have to learn about your two options once and then code how you’d like, but hopefully you’ll be consistent one way or another.

Whenever in doubt, just throw in an extra set of parenthesis, which removes all ambiguity. These will always be the same:

$e = (false || true); $e = (false or true); 

Armed with all that knowledge, I prefer using and or because I feel that it makes the code more readable. I just have a rule not to combine assignments with logical evaluations. But at that point it’s just a preference, and consistency matters a lot more here than which side you choose.

Источник

Читайте также:  Получить id чата telegram python
Оцените статью