Drupal redirection - redirect

I am working on a project and there is a custom module in that which have the drupal redirection code in it here is the code :
if (empty($_GET['destination'])
&& isset($_COOKIE["abc"])
&& $_COOKIE["abc"]<>''
&& ($_POST['form_id'] != 'user_pass_reset'))
{
$_GET['destination'] = "xyz" ;
}
}
Can anyone please explain the 3rd line of code or maybe all of it. Thanks

I have added comments to the source. <> is the same as !=. See PHP Comparison Opperators.
if (empty($_GET['destination']) //Check if $_GET['destination'] is empty.
&& isset($_COOKIE["abc"]) //Check if $_COOKIE["abc"] is not NULL.
&& $_COOKIE["abc"]<>'' //Check if $_COOKIE["abc"] does not equal an empty string.
&& ($_POST['form_id'] != 'user_pass_reset')) //Check if $_POST['form_id'] is not 'user_pass_reset'
{
$_GET['destination'] = "xyz" ; //Set $_GET['destination'] to "xyz"
}
}

should be modify a little bit in second line
if (empty($_GET['destination']) //Check if $_GET['destination'] is empty.
&& isset($_COOKIE["abc"]) //Check if $_COOKIE["abc"] is EXISTS.
&& $_COOKIE["abc"]<>'' //Check if $_COOKIE["abc"] does not equal an empty string.
&& ($_POST['form_id'] != 'user_pass_reset')) //Check if $_POST['form_id'] is not 'user_pass_reset'
{
$_GET['destination'] = "xyz" ; //Set $_GET['destination'] to "xyz"
}
}

Related

Firestore Security Rules: request.time "undefined on object"

I'm trying to create a Security Rule based upon request.time as given in an example on AngularFirebase website.
My function is
function isThrottled() {
return request.time < resource.data.lastUpdate + duration.value(1, 'm')
}
Where I'm trying to allow update: if isThrottled() == false
However, when I try to update a document with this rule, it fails due to time being not defined on the object.
Error: simulator.rules line [169], column [12]. Property time is
undefined on object.
Shouldn't every request have a time or TimeStamp attached to it? Is this something to do with how I'm initializing my Cloud Functions or client app?
Screenshots below:
EDIT
A snippet for the rest of the update security rules are:
service cloud.firestore {
match /databases/{db}/documents {
match /users/{userId} {
match /username/{id} {
allow update: if isSelf(userId)
&& usernameAvailable(incomingData().username)
&& incomingData().username is string
&& incomingData().username.size() <= 25
&& incomingFields().size() == 1
&& isThrottled() == false;
}
}
function incomingData() {
return request.resource.data
}
function isThrottled() {
return request.time < resource.data.lastUpdate + duration.value(1, 'm')
}
function incomingFields() {
return incomingData().keys()
}
function isSelf(userId) {
return userId == currentUser().uid;
}
function usernameAvailable(username) {
return !exists(/databases/$(db)/documents/usernames/$(username));
}
}
}
The username collection is a subcollection under each user document (in the users root collection. Each username document only has 1 field called username that users can update).
This might not be useful for your case in particular, but I had the same error when checking a custom claim on the token object.
Before accessing the field you can use in to check whether the property exists on the object. This code generates the error if agent is not defined:
allow write: if request.auth != null && request.auth.token.agent == true;
This code works fine if agent is not defined:
allow write: if request.auth != null && "agent" in request.auth.token && request.auth.token.agent == true;

Why doesn't this form code work? It seems logical

I'm trying to program a simple form that asks for the following inputs:
mood, age, and gender
It does not matter what I put in the mood prompt. It always comes out positive. For the age, I would like the tab to close if they are under 18 years old. For gender, it goes the same with the mood prompt. Any help would be appreciated.
var userMood = prompt("Hey! How's it going?");
if (userMood = "good" || "Good") {
alert("Awesome! We just need you to fill out a form for security reasons.");
} else if (userMood != "good" || "Good") {
alert("Oh, I'm sorry to hear that... We just need you to fill out a form for security reasons.");
}
var userAge = prompt("What is your current age?");
if (userAge >= "18" ) {
alert("Great! You are the sufficient age to enter this webpage!");
userAge = true;
} else if ( userAge <= "17"){
alert("Sorry, you are too young to view this content...");
window.close();
}
var userGender = prompt ("What is your gender?");
if (userGender = "male" || "Male" || "female" || "Female"){
alert("Great! You're human!");
userGender = true;
} else {
alert("The webpage has perdicted non-human cyber activity, you can no longer continue.");
window.close();
}
i'm going to make my answer verbose to help you learn. for starters, you are using = when you mean to use == or even ===. this is why the mood is always registering as good, because userMood = "good" sets userMood to 'good' and so the expression evaluates to "good", which validates the if statement because FALSE for strings is "" and true is every other string. also userMood = "good" || "Good" doesn't do what you think it does. you need to check both strings like so (userMood === "good" || userMood === "Good").
I tried varying some lines in your code into something below.
var userMood = prompt("Hey! How's it going?");
if (userMood == "good" || userMood == "Good")
alert("Awesome! We just need you to fill out a form for security reasons.");
else
alert("Oh, I'm sorry to hear that... We just need you to fill out a form for security reasons.");
var userAge = prompt("What is your current age?");
if (userAge >= 18 )
{
alert("Great! You are the sufficient age to enter this webpage!");
userAge = true;
}
else if ( userAge < 18 && userAge > 0)
{
alert("Sorry, you are too young to view this content...");
window.close();
}
else if ( userAge < 0 )
{
alert(" ***** prompt message for inputting negative number ****");
window.close();
}
var userGender = prompt ("What is your gender?");
if (userGender == "male" || userGender == "Male" || userGender == "female" || userGender == "Female")
{
alert("Great! You're human!");
userGender = true;
}
else
{
alert("The webpage has perdicted non-human cyber activity, you can no longer continue.");
window.close();
}

CodeIgniter PHP Parsing Error unexpected '{', expecting '('

What's with this PHP Parsing Error Unexpected '{', expecting '('
No backtrace, no any other error message, just one line in the controller, that's it -_-
I kept looking for solutions and reading many links related to this.
What could be the reason for the error in my code below..
This was my controller code (which was working fine):
if (isset($filter) && !empty($search)) {
$data['users'] = $this->model_search->searchTutor($field, $search);
}
elseif (($filter == 'subjName') && !empty($search)) {
$data['users'] = $this->model_search->searchBySubj($field, $search);
}
else {
$data['users'] = $this->model_search->getlist($field);
}
//later i wanted to add a code that will show No Result Found
The view file of my page started giving this error when I added an elseif statement in my controller (Search.php):
if (isset($filter) && !empty($search)) {
$data['users'] = $this->model_search->searchTutor($field, $search);
}
elseif (($filter == 'subjName') && !empty($search)) {
$data['users'] = $this->model_search->searchBySubj($field, $search);
}
//so I added another elseif
elseif (isset($filter) && empty($search)) {
$data['users'] = $this->model_search->getlist($field);
}
//and put the No Result last
else {
$this->session->set_flashdata('nores','<div class="alert text-center">No result matched your search.</div>');
}
Is it because of the multiple elseif condition or am I really missing something here? Please help..
elseif {
Your new elseif has no condition. When do you expect it to run? You need to add a condition.

NGUI avoid line-break in UIInput

Is there any way to avoid users to input line-breaks in UIInputs?
Do not want the user to be able to write line-breaks in username inputs, for example.
I searched for multiline attribute but it seems it only exists in UILabel objects.
Tried "validation:Username" but this option does not allow to write characters like "-", which is a valid username character of my application.
Thanks!
You can similarly limit your input field to a single line by setting the Max Lines property to 1 on the UILabel.
http://www.tasharen.com/forum/index.php?topic=6752.0
Had to check the UIInput.cs file to know how to ignore newlines, and I found this:
case KeyCode.KeypadEnter:
{
ev.Use();
bool newLine = (onReturnKey == OnReturnKey.NewLine) ||
(onReturnKey == OnReturnKey.Default &&
label.multiLine && !ctrl &&
label.overflowMethod != UILabel.Overflow.ClampContent &&
validation == Validation.None);
if (newLine)
{
//Insert("\n");
}
else
{
UICamera.currentScheme = UICamera.ControlScheme.Controller;
UICamera.currentKey = ev.keyCode;
Submit();
UICamera.currentKey = KeyCode.None;
}
return true;
}
So in order to avoid newlines, you need to do:
UILabelObject.multiLine = false;
UIInputObject.onReturnKey = UIInput.OnReturnKey.Default;
Doing that, bool newLine becomes false and performs Submit();

Checking form submission against a word list

I have some code to check is a form is being spammed and if so then stop the email.
It includes a section like this:
if(strpos($messagefield, " cialis") !== false){
$noemail = true;
}
if(strpos($messagefield, " viagra") !== false){
$noemail = true;
}
etc for as many words as we have in the bad word list
This works fine, but is clumsy and difficult to easily add new words to check.
It would be easier if I could create an array and check any field against the array, but I am strugling to find an example to use (most examples still specify the text to search for which defeats the object in this case)
Can anyone help with code to check $messagefield against an array?
(I know there are better ways maybe but this works for us at the moment!)
$i = 0;
$wordlist = array(' cialis', ' viagra');
while ($i < count($wordlist) && $noemail == false) {
if (strpos($messagefield, $wordlist[$i]) !== false) {
$noemail = true;
}
$i++;
}
It is better to use stripos (case-insensitive version of strpos).
Try following code:
$a = array(' cialis', ' viagra');
for ($i = 0; $i < count($a); $i++)
if(stripos($messagefield, $a[$i]) !== false){
$noemail = true;
break;
}
}