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 手机连接电脑热点显示无ip分配
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大