is just an extra layer of security... it can be done also with isset($_POST), kanang REQUEST_METHOD is variable where the server sets if the passed user variables are either $_GET or $_POST, either way its an old practice or should i say habit that i always used...
id prefer to use isset() over empty() i have bad experienced on empty specially if the variable is not set... i only use to check if certain variable has string value or not for array i use is_array() but i use it with isset unless im sure the variable is already defined...
sa akong pag sabot sa empty() mu return siya ug false if dli cya empty or dli zero ang value, for isset() kay mu return sya ug true even if ang value niya 0 or empty string otherwise if null mu return cya ug false. sakto ba?
good to hear some ideas from an expert
thank you sir!![]()
Just for clarification...
"empty" is used to determine whether it is empty or not.
"isset" on the other hand determines whether the variable is declared or not.Code:$variable_arr = array(); if(empty($variable_arr)){ // returns true because we have an empty }
Code:$variable = ""; if(isset($variable)){ // returns true because we have the variable declared before the if statement }
ang empty pwede nmo magamit not just in array, u can also evaluate 1 or 0..
if u know the restrictions, better mogamit ug empty kaysa isset..ang problema sa isset kung imong gi evaluate way sulod (na declare but y sulod)...thats y better ang empty IF you know the restrictions.
mga sir thank you gyud kaayo sa mga help. however naa nsad another problem ni arise huhu. i hope mo tabang gihapon mo hehe.
mao ni ang situation, gusto nako ipa display si $data para maka hibaw ko if ni work ba or ma pasa ba jud ang query. kaso sa pag display pa lang d na man mo gawas. i dont know if asa dapita ang error if sa syntax ba sa sql or something wrong jud sa php code nako. anyway mga bros here it goes
mao ni ako init.php
and mao ni akong users.php. ang ako lang gi include diri is ang kato rang function nga feel nako naa ang error mahitaboCode:<?php session_start(); require 'database/connect.php'; require 'functions/general.php'; require 'functions/users.php'; if (logged_in() == true) { $session_user_id = $_SESSION['userid']; $user_data = user_data($session_user_id, 'userid', 'username', 'password', 'firstname', 'lastname', 'email'); } $errors = array(); ?>
hinaot maka tabang gihapon mo nakoCode:function user_data($userid) { $data = array(); $userid = (int)$userid; $func_num_args = func_num_args(); $func_get_args = func_get_args(); if($func_num_args > 0) { unset($func_get_args[0]); $fields = '`' . implode('', $func_get_args) . '`'; $data = mysql_fetch_assoc(mysql_query("SELECT '$fields' FROM users WHERE userid = '$userid'")); print_r($data); return $data; } }![]()
Bro, if u hav problem relating to DBs query etc...check ur query first, best way is imo e print imong query (kanang select nmo) din e ipa run dritsu saimo DB pra ka assur ka wlay prob imong query statement ayha ka mg test saimong mga variables.
i noticed something that is problem waiting to happen... i noticed that you typecast $userid, why not check it if its string or integer before doing the main code.... it can be solved simple ethier by $userid > 0 or !is_int($userid) or is_numeric($userid)...
salbahis 3 rule in anti-code injection
#1 Always know where the variable came from
#2 Always check its content and escape if necessary
#3 Never use globals
Similar Threads |
|