I'm quite new to php and I tested this code on my local server and it was working fine but when I uploaded it to webserver I started getting the following errors.
This is the Code :
"if($stmt=$mysqli->prepare("SELECT members.id, permissions.name FROM members,permissions WHERE username=? AND password=? AND members.type=permissions.id" )){
$username=$input["user"];
$password=$input["pass"];
$configsalt=$config["salt"];
$stmt->bind_param("ss",$username,md5($password.$configsalt));
$stmt->execute();
$stmt->bind_result($id,$type);
$stmt->fetch();"
The line 39 is "$stmt->bind_param("ss",$username,md5($password.$configsalt));"
Strict Standards: Only variables should be passed by reference in
/home/hotel132/public_html/bulbmg/index.php on line 39
Fatal error: Cannot redeclare is_admin() (previously declared in /home/hotel132/public_html/bulbmg/includes/config.php:22) in /home/hotel132/public_html/bulbmg/includes/config.php on line 28
I don't know why the second error is occuring!!!
'
.......
//Functions
function is_admin(){
if($_SESSION['type']=="admin"){
return true;
}
else{
return false;
}
} //line 28
?>'
Kidly help me out with this.
You should not use literals, try using variables.
The error:
Are you including or requiring file(s) more than one time? Try include_once/require_once
Otherwise check function_exists
EDIT:
Have you tried this?
if (!function_exists('is_admin')) {
function is_admin(){
if($_SESSION['type']=="admin")
return true;
else
return false;
}
}
Related
I am puzzled by this. I get a PHP error for redeclaring a function although the function is only declared once. The code looks as follows:
function array_search_partial($arr, $keyword) {
foreach($arr as $index => $string) {
if (strpos($string, $keyword) !== FALSE)
return $index;
}
}
$has_cv = array_search_partial($fnames,'cv:');
In my log files this produces the following error (the page does not complete loading):
[31-Jan-2020 10:48:32 Europe/Berlin] PHP Fatal error: Cannot redeclare array_search_partial() (previously declared in /XXX/XXX/XXX.php:332) in /XXX/XXX/XXX.php on line 332
So the error occurs on line 332 because the function has already been declared on line 332?!? Just to make sure I renamed the function to something arbitrary and I get the same error. Does anyone know what could be going on here?
I have this function called checkCentre1() and I'm unable to open my web application due to below error appearing:
Fatal error: Cannot redeclare checkCentre1() (previously declared in C:\xampp\htdocs\scms2\protected\views\layouts\main.php:39) in C:\xampp\htdocs\scms2\protected\views\layouts\main.php on line 50
I did not declare checkCentre1() somewhere else. I have tried few solutions below but none is working:
if (!function_exists('checkCentre1')) { //function code }
include_once
My code is as below:
function checkCentre1($value){ //line 39
$modelUser = AuthUsers::model()->findByPk($value);
if($modelUser){
if($modelUser->ref_user_type_idref_user_type == 1 || $modelUser->ref_user_type_idref_user_type == 2){
return true;
}else{
return false;
}
} else
return false;
} //line 50
Does anybody has any other solution for this?
I am trying to update one of the sites I maintain to the latest PHP and during this, I have come across the following error:
Fatal error: Call to undefined function tep_session_name() in ... /includes/application_top.php on line 83
The code it is referring to is:
// set the session name and save path
tep_session_name('osCAdminID');
tep_session_save_path(SESSION_WRITE_DIRECTORY);
But I have looked at the sessions.php file are the function is defined in the below code:
function tep_session_name($name = '') {
if ($name != '') {
return session_name($name);
} else {
return session_name();
}
}
Any help in identifying the cause would be greatly appreciated.
Thanks, E.
I'm absolutely sure, that you call this function before you include file with function declaration
I am troubleshooting an error in PHP and I don't know how to resolve it. I don't have any PHP knowledge.
Here is the code:
function _act($sql) {
if (!$this->_link) {
Fatal::internalError('Tried to make database query before connection.');
}
$r = mysql_query($sql, $this->_link);
if ($r === false) {
Fatal::dbError($sql, "Database query failed", mysql_error());
}
return $r;
}
In the error log I get the following:
[24-Jan-2013 13:25:38 America/Denver] PHP Strict Standards: Non-static method Fatal::dbError() should not be called statically, assuming $this from incompatible context in /home1/flcclear/public_html/Library/classes/Query.php on line 91
I have tried to make it an object call with $r->mysql_error(); but this caused a different error. I am not trying to rewrite this code, just trying to correct the errors for an elementary/middle school which equals no money, volunteer time.
Thanks in advance.
make Fatal::internalError,Fata::dbError (also other methods you are using like "Fatal::methodName") static
example :
class Fatal
{
public static dbError($sql,$message){
//method body
}
}
but the error message is referring to the Fatal::dbError and not to mysql_error.
Fatal::dbError is a class designed for you? Try this:
Class Fatal{
...
static public dbError(...){...}
...
}
I'd like to use stdClass to store options for some methods, instead of passing huge lists of variables (inspired by javascript-style coding)
However, I'd like to make sure I'm always getting an instance of stdClass as an argument. I know I can add a hint in the argument (gb::search below) but when I deliberately try to break it, I'm not sure how to handle the error.
Any tips?
class gb extends CI_Model {
protected $searchtypes = array('full','partial');
protected $endpoint = "https://local.endpoint";
function __construct() {
parent::__construct();
// sample search
$options = new stdClass();
$options->term = 'sample search';
$options->type = 'full';
$this->search($options);
}
function clean_term($term){
$term = trim($term);
return $term;
}
function search(stdClass $options){
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}
The error it throws is something like:
A PHP Error was encountered
Severity: 4096
Message: Argument 1 passed to gb::search() must be an instance of stdClass, null given, called in /application/models/gb.php on line 20 and defined
Filename: models/gb.php
Line Number: 29
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 31
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/gb.php
Line Number: 32
Any ideas how to approach this from a CodeIgniter point of view?
if I remember - mistyped argument should raise E_RECOVERABLE_ERROR, so, it triggers error handler but execution continues. So, you have two options basically.
One is to throw exception in error handler when E_RECOVERABLE_ERROR is encountered. To halt execution.
Another - check type with instanceof stdClass and do what you suppose - raise exception or return something.
UPDATE In your case your framework (CI is for CodeIgniter?) sets error handler (somewhere using set_error_handler). So, after logging or printing error message execution continues. (If there was not handler you would get fatal error). Just test type of argument manually:
function search(stdClass $options){
// test type for sure, because of recoverable error
if (!($options instanceof stdClass)) {
return false; // or throw new InvalidArgumentException('Parameter should be instance of stdClass');
}
$term = $options->term;
$type = $options->type;
// make sure we're doing a valid search
if (!$term || !in_array($type, $this->searchtypes)) {
return false;
}
$term = $this->clean_term($term); // etc
}