douhuang5331 2013-01-12 11:44
浏览 74
已采纳

在php中传递函数和文件之间的变量

I have a file called admin.php in which I have a button with the name send. What I want to do is when I click it, to make visible a link on the user's page, user.php. How can I do this?

I have a file with all my functions called functions.php in which I have a function called onSubmit($var); I initialize the variable $var is admin.php with the value $_POST['send'] but when I call the function in the file user.php I have no way of telling him who the variable $var is so I get 'undefined index'.

Is there another way to do this?

EDIT Added code This is admin.php

<input type="button" name="send" value="Submit" /><br/>      

require 'functions.php';  
$posted = $_POST['send'];  
onSubmit($posted);  

This is user.php

require 'functions.php';  
onSubmit($var);  //here it says undefined index var because it doesn't know who the variable is
if($isSent == 1) { 

<a style="visibility:visible;" href="test3.html" id="test3">Test3</a> <br/>  

}  

And this is functions.php

global $isSent;  
function onSubmit($var) {  
if(isset($var)) {  
$isSent = 1;  
}  
}
  • 写回答

3条回答 默认 最新

  • dongliu8542 2013-01-12 15:05
    关注

    Right I've done a bit of research on Caching and this is what I've come up with. It might not be 100% correct but it's a start as like I've said I've never tried it myself lol

    In your admin.php I'd put this function in:

    if(isset($_POST['send'])){
        if($enabled == true){
            $enabled == false;
        }
        else{
            $enabled == true;
        }
         apc_add('enabled',$enabled);
    }
    

    Now to 'get' our $enabled var:

    $enabled = apc_fetch('enabled');
    

    Then to check the the var within your client page:

    if($enabled == true){
        echo ' button';
    }
    

    Now the only things I haven't fully looked at is the security of the apc_ function and the client usage. I believe it works for all clients of the server but I'm not 100% certain. Here the php manual to give better examples.

    This is the method I was thinking of. But again I'm not sure on the security of it but I'm sure you can find something to keep it secure. The video is actually is tutorial for a Youtube API. But he does cover saving a variable to a cache text file which should be of use to you :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c