PHP undefined variable when url identifier is present - php

I apologize for this being a bit lengthy but I wanted to show the code and not leave anything out.
The Goal: The user submits a registration form that submits the form to a database which adds the info plus a unique string to the database. Once the user submits an email is sent to the user that contains a link to a php page that has that unique string as a URL identifier at the end like so:
xyz.com/activate.php?uid=292ca78b727593baad9a
When the user clicks that link they are taken that page where they will fill out another form and when they click submit it will activate their account.
The Problem: When the user goes to the link provided they receive an error from my validation page like so:
Undefined index: variable in process.php
BUT when the user deletes the URL identifier so the URL shows as:
xyz.com/activate.php
The user does not receive an error and the validation page (process.php) works properly. I have attempted to use the identifier with a $_GET['uid'] and checking if it exists before running the code but the result was the same. I cannot find an answer when attempting to google this issue so I apologize if this has been asked before.
The Question: Why does this work without the URL identifier but not with it? I do realize the URL identifier basically does a $_REQUEST when the page first loads which is what runs the process.php. Is there a way to prevent that?
So that you guys know the code I am working with I have posted it below.
activate.php:
<?php
// validate the form.
require_once('process.php');
$validation_rules = array(
'company_name' => array(
'required' => true,
'min-length' => 2
)
);
$db_error = '';
$validate = new validator();
$validate->validate($validation_rules);
if ($validate->validate_result()) {
// the validation passed!
}
?>
<div class="bg v-100 cm-hero-activate">
<div class="v-100">
<div class="v-set v-mid">
<form class="v-mid v-bg-white <?php if(!$validate->validate_result() && $_POST || !empty($error)) { echo "shake"; } ?>" name="activation" action="" method="post">
<fieldset>
<div class="form-content">
<div id="content">
<div class="form-inner in" data-id="1" data-name="activate">
<h1>ACTIVATE YOUR ACCOUNT</h1>
<div class="form-section">
<h2>Personal Info</h2>
<?php if (!empty($db_error)) {
echo $db_error;
} ?>
<div class="field-group">
<input type="text" id="company_name" class="field required" name="company_name" value="<?php $validate->form_value('company_name'); ?>">
<label for="company_name" class="placeholder">Company Name</label>
<?php $validate->error(array('field' => 'company_name', 'display_error' => 'single')); ?>
</div>
</div>
<div class="field-bottom">
<button name="submit" data-name="activate" class="bttn btn-dark btn-hover-gloss">ACTIVATE MY ACCOUNT</button>
</div>
</div>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
process.php:
<?php
class validator {
private $validation_rules;
private $errors = array();
private $validate_result = array();
public function validate($rules) {
$this->validation_rules = $rules;
if($this->validation_rules && $_REQUEST) {
foreach($this->validation_rules as $field => $rules) {
$result = $this->process_validation($field, $rules);
if($result == false) {
$this->validate_result[] = 0;
} elseif($result == true) {
$this->validate_result[] = 1;
}
}
}
}
public function form_value($field_name = '') {
if($this->validation_rules) {
if($_REQUEST && $_REQUEST[$field_name]) {
if(!$this->validate_result()) {
echo $_REQUEST[$field_name];
}
}
}
}
public function validate_result() {
if($this->validation_rules) {
if($_REQUEST) {
$final_result = true;
$length = count($this->validate_result);
for($i=0;$i < $length; $i++) {
if($this->validate_result[$i] == 0) {
$final_result = false;
}
}
return $final_result;
}
}
}
private function process_validation($field, $rules) {
$result = true;
$error = array();
foreach($rules as $rule => $value) {
if($rule == 'required' && $value == true) {
if(!$this->required($field, $value)) {
$error[] = "$field - required";
$result = false;
}
} elseif($rule == 'min-length') {
if(!$this->minlength($field, $value)) {
$error[] = "$field - minimun length is $value";
$result = false;
}
}
}
$this->errors[] = array($field => $error);
return $result;
}
public function error($data = '') {
if($this->validation_rules) {
if($_REQUEST) {
foreach($this->errors as $err) {
if(isset($data['field'])) {
foreach($err as $field => $field_error) {
if($data['field'] == $field) {
foreach($field_error as $error_data) {
if(isset($data['display_error']) == 'single') {
echo '<p class="error">' . $error_data . '</p>';
goto next;
} else {
echo '<p class="error">' . $error_data . '</p>';
}
}
next:
}
}
} else {
foreach($err as $field => $field_error) {
foreach($field_error as $error_data) {
if(isset($data['display_error']) == 'single') {
echo '<p class="error">' . $error_data . '</p>';
goto next1;
} else {
echo '<p class="error">' . $error_data . '</p>';
}
}
next1:
}
}
}
}
}
}
private function required($field, $value) {
if(empty($_REQUEST[$field])) {
return false;
} else {
return true;
}
}
private function minlength($field, $value) {
if(strlen($_REQUEST[$field]) < $value) {
return false;
} else {
return true;
}
}
?>
EDIT: it seems that the error is happening on the if statement in the min-length function: if(strlen($_REQUEST[$field]) < $value)
EDIT 2: This may also be of some use. The textbox is being filled with this: <br /><font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'><tr><th align='left' bgcolor='#f57900' colspan=
and underneath that I receive this error: Notice: Undefined index: company_name in C:\...\process.php on line 25 Call Stack #TimeMemoryFunctionLocation 10.0005369632{main}( )...\activate.php:0 20.0029403928validator->form_value( )...\activate.php:80 ">

Your $field_name doesn't exist in the $_REQUEST array which is why you are getting your undefined index error.
You are not checking if the value is set - just accessing it via $_REQUEST[$field_name] in your if statement.
Change
public function form_value($field_name = '') {
if($this->validation_rules) {
if($_REQUEST && $_REQUEST[$field_name]) {
if(!$this->validate_result()) {
echo $_REQUEST[$field_name];
}
}
}
}
To
public function form_value($field_name = '') {
if($this->validation_rules) {
if($_REQUEST && isset($_REQUEST[$field_name])) {
if(!$this->validate_result()) {
echo $_REQUEST[$field_name];
}
}
}
}
Unrelated Tips.
Aim for cleaner - and more concise readable code.
$input = [
'name' => 'Matthew',
];
$rules = [
'name' => 'required|string',
];
$v = (new Validator())->validate($input, $rules);
if ($v->fails()) {
// Do something with $v->errors();
return;
}
// Do something with validated input
Try and avoid using else or elseif wherever possible. This can be achieved by looking for the negative first, and exiting early. Try not to have too many levels of nesting. It makes your code extremely difficult to read and increases cyclomatic complexity.
Also - take a look at an MVC framework which should help you to structure your code. A good start would be something like Laravel https://laravel.com/ there are good tutorials on https://laracasts.com/

You are getting this error because you have logic like
if($this->validation_rules && $_REQUEST) {
In PHP, an empty array is falsy and a non-empty one, truthy.
$_REQUEST is a combination of $_GET, $_POST and $_COOKIE.
When you add the uid query parameter, $_REQUEST will not be empty and therefore not falsy and your validator will attempt to run but without the expected POST data (such as company_name).
If you're only wanting to validate POST data, you should only be inspecting $_POST.
See Gravy's answer for safer ways to check for the existence of array keys.

Related

How to get the name of input field with PHP

I'm trying to create a function. which will check if the field is empty or not. If the input is empty it'll push an error for that input in the error array.
$errors = ["name" => "Name is required"];
like so
How can I do this?
function checkRequiredFields($fields = [], $errors = [])
{
foreach ($fields as $field) {
if (is_blank($field)) {
$errors[$field] = "$field is required";
}
}
}
btw here's how my is_blank function looks:
function is_blank($value)
{
return !isset($value) || trim($value) === '';
}
You can check that the field has been submitted and doesn't hold the empty string:
<?php
function check_required_fields($fields, &$errors) {
foreach($fields as $fieldname) {
if(isset($_POST[$fieldname]) && $_POST[$fieldname] === '') {
$errors[$fieldname][] = "'$fieldname' is required.";
}
}
}
check_required_fields(['email'], $errors);
?>
<form method='POST'>
<input type='text' name='name'>
<input type='email' name='email'>
<input type='submit'>
</form>
You can get the values of the input fields with
$field = $_GET["field"]; // or $_POST["field"]; depending of your form.
But you need to sanitize properly your input values for security reasons.
https://www.php.net/manual/fr/function.filter-input.php
The empty() function is also what you're looking for.
if (empty($field)) {
$errors[$field] = "$field is required";
}
Checkout the documentation : https://www.php.net/manual/fr/function.empty.php
Take a look at the isset() function also.

How do I let an error-message only appear after the $_POSTS are sent?

On a blog I'm coding the admin can edit existing posts.
I want to let an error-message appear when the $_POST['title'] for e.g is empty(There will be displayed:"Your post should have a title"). I also do it if the subheading, content or category are empty.
The errors work just fine if one or some of them is/are empty. As soon I load the page to edit a post every error is displayed from the beginning.
How do I make them only appear when one or some $_POST's are empty after the <input type="submit .../> is clicked (they shouldn't be there when the site has loaded)?
This is the function in the PostsAdminController.php that checks the $_POST's and renders the site:
public function edit()
{
$error = "";
$id = $_GET['id'];
$entry = $this->postsRepository->find($id);
$categoryFId = $this->categoryRepository->getOneCatFromId($entry->c_Id);
$savedSuccess = false;
$abort = false;
if ($this->loginService->check()) {
if (!empty($_POST['title'])) {
$entry->title = $_POST['title'];
} else {
$error .= "Your post should have a title.";
$abort = true;
}
if (!empty($_POST['subheading'])) {
$entry->subheading = $_POST['subheading'];
} else {
$error .= "A good subheading is nothing you should just leave out.";
$abort = true;
}
if (!empty($_POST['content'])) {
$entry->content = $_POST['content'];
} else {
$error .= "Your post should have content, you know, it wouldn't be a 'post' then.";
$abort = true;
}
if (!empty($_POST['category'])) {
$entry->c_Id = $_POST['category'];
}
if ($abort == false){
$this->postsRepository->update($entry);
$savedSuccess = true;
}
} else {
$error = "You have no permission to do this, how the hell did you get here?";
}
$this->render("post/admin/edit", [
'entry' => $entry,
'error' => $error,
'savedSuccess' => $savedSuccess,
'categoryFId' => $categoryFId
]);
}
I really hope someone can help me with this, I don't know what I could to to let them only disappear when the POSTS have already been send..
You have to check if there was a POST action use:
if ($_SERVER['REQUEST_METHOD'] == 'POST')
in your case
...
if ($this->loginService->check()) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!empty($_POST['title'])) {
...
}
}
}

Header Redirect after form Validation in PHP

I am trying this code as part of form processing:
<?php
if(isset($_POST['senderEmail']))
{
try
{
require '_php/_security/validation.php'; //SEE BELOW
$rules = array(
'senderEmail' => 'validEmail',
'emailTextbox' => 'validTextbox',
);
$validation = new Validation();
if ($validation->validate($_POST, $rules) == TRUE) {
require("_php/database/dbProcessing.php"); //Form Proccessing for database inclusion
}
else {
foreach($validation->emailErrors as $error){
$emailErrors[] = $error;
$_SESSION['$emailErrors'] = $emailErrors;
header('Location:indexmobile.php#emailErrors');
die('ABORT!');
}
}
}
catch (PDOException $e)
{
$error = 'Error adding elements to database: ' . $e->getMessage();
echo "Error: " . $error;
exit();
}
exit();
}
?>
The validation.php where I do my validation has this:
<?php
class Validation {
public $errors = array();
public function validate($data, $rules) {
$valid = TRUE;
foreach ($rules as $fieldname => $rule) {
$callbacks = explode('|', $rule);
foreach ($callbacks as $callback) {
$value = isset($data[$fieldname]) ? $data[$fieldname] : NULL;
if ($this->$callback($value, $fieldname) == FALSE) $valid = FALSE;
}
}
return $valid;
}
public function validEmail($value, $fieldname) {
$valid = !empty($value);
if ($valid == FALSE) {
$this->emailErrors[] = "The $fieldname is required";
return $valid;
} else {
$valid = filter_var($value, FILTER_VALIDATE_EMAIL);
if ($valid == FALSE) $this->emailErrors[] = "The $fieldname needs to be a valid email";
return $valid;
}
}
public function validTextbox($value, $fieldname) {
$valid = !empty($value);
if ($valid == FALSE) {
$this->emailErrors[] = "The $fieldname is required";
return $valid;
} else {
$whitelist = '/^[a-zA-Z0-9 ,\.\+\\n;:!_\-#]+$/';
$textarea = strip_tags($value);
$textarea = mysql_real_escape_string($textarea);
$valid = preg_match($whitelist, $textarea);
if ($valid == FALSE) $this->errors[] = "The $fieldname contains invalid characters";
return $valid;
}
}
}
Upon using this, Im have issues with the redirect (I think). It seems further that Im having errors in validation. My questions are thus:
Am I doing the header redirect correctly? I've read that " header() must be called before any actual output is sent,.." So is this the reason why this redirect is incorrect? how to make a redirect if i need to show/send something to the redirected page?
function validTextbox always ends up an error that the field is empty. Why so?
Is my entire process of form validation a good way of validating form fields (which i learned from watching an online tutorial)? What is a better way?
Is there something wrong with error reporting in this case?
Thank you for those who replies. I am new to PHP and trying my best to learn the language.
1 - There are several ways to pass on a message to the page you are redirecting to. One is through $_GET like this
$message="Some message for the next page.";
$message=urlencode($message);
header("Location:page.php?message=".$message);
then on page.php
if(!empty($_GET['message']))
{
$_GET['message'];
}
similarly you can also use the session (less secure)
$_SESSION['message']='some other message';
then on page.php
if (!empty($_SESSION['message']))
{
echo $_SESSION['message'];
unset($_SESSION['message']);
}
2 - I would have to see what you are passing to your validate function. You should do a var_dump of $_POST and add that to your question.
3 - It depends on your criteria. If you are just checking for emptiness its overkill. I don't know what text you need / consider valid, but a regex is a reasonable way of enforcing validation.
4 - See #2.

Adding new PHP session variable is destroying the session

I have encountered an odd issue that I was hoping someone could shed some light on.
I have a website that uses a PHP session to store login details. On this site is a game that also uses PHP session variables. Whenever I have not logged in to the site for a while, then try to play the game it logs me out. If I log back in straight away the session variables are remembered, I stay logged in and I can play the game as many times as I like. I can access any other page on the site with no issues.
I have session_start at the top of all pages. Any thoughts? Thank you.
This is my init.php file:
<?php
ob_start();
session_start();
//error_reporting(0); // don't display errors
require 'database/connect.php';
require 'functions/general.php';
require 'functions/users.php';
require 'functions/items.php';
require 'functions/creatures.php';
$current_file = explode('/', $_SERVER['SCRIPT_NAME']);
$current_file = end($current_file);
if (logged_in() === true){
$session_user_id = $_SESSION['user_id'];
$user_data = user_data($session_user_id, 'user_id', 'username', 'password', 'first_name', 'last_name', 'email', 'password_recover', 'type', 'allow_email', 'profile', 'coins');
$creature_data = creature_data($session_user_id, 'base_creature_id', 'level', 'strength', 'speed', 'intelligence', 'happiness', 'status', 'battle_level');
if(user_active($user_data['username']) === false) {
session_destroy();
header('Location: logout.php');
exit();
}
if($current_file !== 'changepassword.php' && $user_data['password_recover'] == 1){
header('Location: changepassword.php?force');
exit();
}
}
$errors = array();
?>
And here is the game file:
<?php
require_once('core.php');
Hangman::StartPage();
?>
<head>
<link rel="stylesheet" type="text/css" href="games/plank/styles.css" />
</head>
<?php Hangman::PrintGameState(); ?>
<div id="content">
<!--<div id="banner"><img src="games/plank/images/interface/banner.png" /></div>-->
<div id="innerContent">
<div id="wordArea">
<span class="alphabet">
<?php Hangman::PrintCurrentWord(); ?>
</span>
</div>
<span id="controls">
<?php if(isset($_GET['finished']) === true && empty($_GET['finished']) === true){ ?>
<img id="result" src="games/plank/images/interface/<?php echo Hangman::GameResult() ? 'win' : 'lose'; ?>.png" />
<a id="replay" href="http://www.mobbipets.com/site/walkthepalm.php?m=r"></a>
<?php }
else if (Hangman::IsGameFinished()) {
header('Location: walkthepalm.php?finished');
if (Hangman::GameResult() == 'win'){
update_coins($session_user_id, 50);
}
}
else { ?>
<span class="alphabet">
<?php Hangman::PrintKeyboard(); ?>
</span>
<?php } ?>
</span>
<span id="hangman"><img src="games/plank/images/hangman/<?php echo $_SESSION['gameState']; ?>.png" /></span>
</div>
</div>
<?php Hangman::EndPage(); ?>
And here is the core.php file the game uses.
<?php
require_once('db.php');
/*=================================================
this class handles game logic and php sessions.
==================================================*/
abstract class Hangman
{
private static $pageUrl = 'http://www.mobbipets.com/site/walkthepalm.php';
private static $gameStates = 8; //includes the game over state
private static $keyboardButtons = "abcdefghijklmnopqrstuvwxyz&'-";
private static $underscores = array(
'us_1',
'us_2',
'us_3',
);
private static $alphabetAliases = array(
'&' => 'amp',
'\'' => 'apos',
'-' => 'hyphen',
',' => 'comma',
'!' => 'exclaim',
'+' => 'plus',
'?' => 'question',
);
//just checks if we have a valid session
public static function IsLoggedIn()
{
if(isset($_SESSION['valid']) && $_SESSION['valid'])
return true;
return false;
}
private static function RegenerateSession()
{
//session_regenerate_id();
$_SESSION['valid'] = 1;
$_SESSION['lastActivity'] = time();
$_SESSION['word'] = Database::GetRandomWord();
$_SESSION['lettersLeft'] = strlen($_SESSION['word']);
$_SESSION['guessedLetters'] = '';
$_SESSION['gameState'] = 1;
// $session_user_id = $_SESSION['user_id'];
}
//session handling
public static function StartPage()
{
//session_start();
//terminate the session if we've been inactive for more than 10 minutes
if (self::IsLoggedIn())
{
if (isset($_SESSION['lastActivity']) && ((time() - $_SESSION['lastActivity']) > 600 ))
self::EndSession();
else
$_SESSION['lastActivity'] = time();
}
//if logged in after timeout check
if (self::IsLoggedIn())
{
$mode = trim(#$_GET['m']);
if ($mode != '')
$mode = strtolower($mode);
if ($mode != '') //we've passed a special input 'mode'
{
switch ($mode)
{
case 'g': //player making a guess
$guess = trim(#$_GET['g']);
if ($guess != '')
{
$guess = self::FromAlias(strtolower($guess));
if (strlen($guess) == 1 && stripos($_SESSION['guessedLetters'],$guess) === false) //valid
{
$_SESSION['guessedLetters'] .= $guess;
if (stripos($_SESSION['word'],$guess) === false) //wrong guess
$_SESSION['gameState']++;
else
$_SESSION['lettersLeft'] -= substr_count($_SESSION['word'] ,$guess);
}
}
break;
case 'r': //forced reset of session
self::EndSession();
break;
}
}
}
//we forced a reset
if (!self::IsLoggedIn())
{
self::RegenerateSession();
header ('Location: '.self::$pageUrl);
}
}
//is the game finished
public static function IsGameFinished()
{
return $_SESSION['gameState'] >= self::$gameStates || (isset($_SESSION['lettersLeft']) && $_SESSION['lettersLeft'] <= 0);
}
//check if we won (true == win)
public static function GameResult()
{
return $_SESSION['gameState'] < self::$gameStates && $_SESSION['lettersLeft'] == 0;
}
//add any page-close stuff here
public static function EndPage()
{
}
//terminates the session
private static function EndSession()
{
//$_SESSION = array(); //destroy all of the session variables
//session_destroy();
//session_unset();
self::RegenerateSession();
return true;
}
//convert a character to it's alias
private static function ToAlias($letter)
{
return array_key_exists($letter, self::$alphabetAliases) ? self::$alphabetAliases[$letter] : $letter;
}
//reduce an alias to it's corresponding character
private static function FromAlias($alias)
{
$key = array_search($alias, self::$alphabetAliases);
return $key === false ? $alias : $key;
}
//spit out the current word images based on game state
public static function PrintCurrentWord()
{
if (!self::IsLoggedIn())
return;
$finished = self::IsGameFinished();
for ($i = 0; $i < strlen($_SESSION['word']); $i++)
{
$letter = substr($_SESSION['word'],$i,1);
echo '<span class="';
if (!$finished && stripos($_SESSION['guessedLetters'], $letter) === false) //haven't guessed this yet
echo self::$underscores[rand(0,count(self::$underscores)-1)];
else //is a valid character that we've guessed already
echo self::ToAlias($letter);
echo '"></span>'."\n";
}
}
public static function PrintGameState() //debugging
{
echo "\n<!--\n";
echo "Word: ".$_SESSION['word']."\n";
echo "Letters guessed: ".$_SESSION['guessedLetters']."\n";
echo "Letters left: ".$_SESSION['lettersLeft']."\n";
echo "Game State: ".$_SESSION['gameState']."\n";
echo "-->\n";
}
//print out the keyboard buttons
public static function PrintKeyboard()
{
if (!self::IsLoggedIn())
return;
for ($i = 0; $i < strlen(self::$keyboardButtons); $i++)
{
$key = substr(self::$keyboardButtons,$i,1);
$keyAlias = self::ToAlias($key);
if (stripos($_SESSION['guessedLetters'], $key) === false) //haven't guessed this yet
echo '<a class="'.$keyAlias.'" href="?m=g&g='.$keyAlias.'"></a>';
else //we've guessed already
echo '<span class="'.$keyAlias.'"><img src="games/plank/images/alphabet/'.(stripos($_SESSION['word'], $key) === false?'wrong':'right').'.png" /></span>';
echo "\n";
}
}
}
?>
A common mistake is an assignment like this:
$_SESSION = $data;
this will overwrite any previously stored information.
Better practice is to make $_SESSION an array with named indexes:
$_SESSION['somedata'] = $data;
Now you will only overwrite data stored in the 'somedata' field.

PHP Syntax Error?

I have coded a nice script but i am constantly getting
Error on line 29: Parse error, unexpected T_IF(if)
I have tried debugging code, wasted plenty of time. But nothing, came out.
Here is my code.
<?php
include("geoip.inc");
$ip=$_SERVER['REMOTE_ADDR'];
$gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, "$ip");
$referrer=$_SERVER['HTTP_REFERER'];
// Country name is not used so commented
// Get Country Name based on source IP
//$country = geoip_country_name_by_addr($gi, "$ip");
$real=0;
geoip_close($gi);
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) {
$real = 1;
}
else {
if ($_COOKIE['iwashere'] != "yes") {
setcookie("iwashere", "yes", time()+315360000);
if ($country_code="IN") {
if(preg_match('/google/i', $referrer)) {
$key = "g17x9erm28n7cgifddssfqhgorjf3e"; // Account API Key
$ip = $_SERVER['REMOTE_ADDR']; // IP to Lookup
$result = file_get_contents('http://www.ipqualityscore.com/api/ip_lookup.php?KEY='.$key.'&IP='.$ip);
$real=$result
//$result will be equal to 1 for detected proxies & vpns or equal to 0 for clean IP's
{if($real==0)
{setcookie("testcookie", "testvalue");
if( isset( $_COOKIE['testcookie'] ) ) {
if (isset($_POST['jstest'])) {
$nojs = FALSE;
} else {
// create a hidden form and submit it with javascript
echo '<form name="jsform" id="jsform" method="post" style="display:none">';
echo '<input name="jstest" type="text" value="true" />';
echo '<script language="javascript">';
echo 'document.jsform.submit();';
echo '</script>';
echo '</form>';
// the variable below would be set only if the form wasn't submitted, hence JS is disabled
$nojs = TRUE;
}
if ($nojs){
$real=1;
}
}
else
$real=1;
}
else
$real=1;
} else
$real = 1;
}
else {
$real = 1;
}
} }
if ($real==1) {
include_once('Biggenius1.htm');
}
?>
It is if inside. Please give me advice, on how can i avoid these error. And also is there any alternative to code such complex script with multiple nested if statements?
Please post entire code:
try this
$real = 0;
geoip_close($gi);
if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) {
$real = 1;
} else {
if ($_COOKIE['iwashere'] != "yes") {
setcookie("iwashere", "yes", time() + 315360000);
if ($country_code = "IN") {
if (preg_match('/google/i', $referrer)) {
$key = "g17x9erm28n7cgifddssfqhgorjf3e"; // Account API Key
$ip = $_SERVER['REMOTE_ADDR']; // IP to Lookup
$result = file_get_contents('http://www.ipqualityscore.com/api/ip_lookup.php?KEY=' . $key . '&IP=' . $ip);
$real = $result;
//$result will be equal to 1 for detected proxies & vpns or equal to 0 for clean IP's {
if ($real == 0) {
setcookie("testcookie", "testvalue");
if (isset($_COOKIE['testcookie'])) {
if (isset($_POST['jstest'])) {
$nojs = FALSE;
} else {
}
// create a hidden form and submit it with javascript
echo '<form name="jsform" id="jsform" method="post" style="display:none">';
echo '<input name="jstest" type="text" value="true" />';
echo '<script language="javascript">';
echo 'document.jsform.submit();';
echo '</script>';
echo '</form>';
// the variable below would be set only if the form wasn't submitted, hence JS is disabled
$nojs = TRUE;
}
if ($nojs) {
$real = 1;
}
}
else
$real = 1;
}
else
$real = 1;
} else
$real = 1;
}
else {
$real = 1;
}
}
if ($real == 1) {
include_once('Biggenius1.htm');
}
On line 29, $real=$result should end in a semi-colon and on the following line {if($real==0) should be if($real==0){.
The error message is your friend, it suggested you look to line 29.
You placed a curely braces before the if condition
//$result will be equal to 1 for detected proxies & vpns or equal to 0 for clean IP's
{if($real==0)
remove it then your error wil be removed
From reading over your code, it seems like the only errors I can find are these:
{if($real==0)
And:
$real=$result
Which should be changed into:
if($real==0){
And:
$real=$result;
Here are the few errors I found:
if ($country_code="IN") : This is an assignment not comparision, will always return true
$real=$result : Missing Termination ; on the end

Categories