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地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?