Why is my function changing boolean value to 'on'?

前端 未结 1 1354
轮回少年
轮回少年 2021-01-29 06:07

So I\'m new to php/the programming world and I\'m studying online and other forms and such but I couldn\'t find anything to help answer my question which is why I\'m here. Any h

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 06:45

    Change related line to following: The problem is when activateBox is not empty it assings itself to $activeMain naturally.

    $activeMain = isset($_POST['activateBox']);
    

    Updated : Check this one.

    function activeCheck() {
        return isset($_POST['activateBox']);
    }
    
    activeCheck();
    

    Updated Answer Due To Updated Question : I removed session_destory if you execute that and if you have another session variable ex: user isLoggedIn it would be destroyed too. unset is OK for the purpose. Please check XSS, Sql injection attacks around the internet implement logic according to best practises, and validate/sanitize your data before process parameters into DB or etc.

    
    
    
        
            PHP FORM
        
    
    
        
    Name:

    Activate:
    $val) { // sanitize your inputs. @see XSS, SQL injection etc. // validate parameters according to your needs. $safeParameters[$key] = $val; } $_POST = []; checkIsActivated($safeParameters); // implement other logic, // save form to database etc. } function checkIsActivated($parameters) { return !empty($parameters['activateBox']); } ?>

    0 讨论(0)
提交回复
热议问题