通过onclick in link按钮设置C​​ookie,然后通过PHP变量进行测试 [英] set a Cookie by onclick in link button and then test by PHP variable

查看:58
本文介绍了通过onclick in link按钮设置C​​ookie,然后通过PHP变量进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MVC框架中。



当我按下链接按钮时,我有一个设置cookie值的JavaScript。这是我的JavaScript代码:

In MVC Framework.

I have a JavaScript that set the cookie value when I press a link button click. here is the code of my JavaScript:

 <script type="text/javascript" >
    (function() {
        document.getElementById("mylink").onclick = function() { 
            var the_cookie = "video=video;" ; 
            document.cookie = the_cookie;
            //location = 'http://localhost/nproject/index.php?c=files&a=index&active_project=2&1369320566'; 
            //var video = document.getElementById("mylink").value;
            alert(document.cookie.value);
            
        };
    })();
</script>





我在本地电脑的链接是:

HTTP://localhost/nproject/index.php C =文件&安培; A =&索引放大器; active_project = 1& 1369323644 [ ^ ]



我对这个链接一无所知,因为我是MVC框架的新成员。我刚刚在list_files.php中编写了这个JavaScript。我的链接按钮在index.php上。在index.php中,我只需添加如下链接:



And my link in local pc is :
http://localhost/nproject/index.php?c=files&a=index&active_project=1&1369323644[^]

And I don''t understand anything about this link as I am a new comer in MVC framework. I have just write this JavaScript in list_files.php. And my link button is on index.php. In index.php I have just add the link as like this:

echo '<div><a id = "mylink" value ="video"'; 
echo 'href="';
get_url('files');
echo '" >Video</a> </div>';



因为,index.php的结尾是:


Because, the end of the index.php is :

<?php $this->includeTemplate(get_template_path('list_files', 'files')) ?>



因为它正在加载我的list_files.php。

当我点击链接时,它提醒我未定。我还在list_files.php中编写了我的PHP代码,用于获取php变量中的cookie值以进行另一次检查。

由Cookie设置的PHP变量:


As it is loading my list_files.php.
And when I am clicking on the link its alerting me "undefned". And I have also write my PHP code in list_files.php for getting cookies value in php variable for my another checking.
PHP variable set by Cookie:

<?php if(isset($_COOKIE["video"]))
         { $value = $_COOKIE["video"];
           echo $value;
         }
         ?>



因为我得到的结果未定义所以,我变得混淆做以后的工作。请帮帮我。


As I am getting the result undefined so, I become confuse to do later jobs. Please help me.

推荐答案

this-> includeTemplate(get_template_path(' list_files'' files'))?>
this->includeTemplate(get_template_path('list_files', 'files')) ?>



因为它正在加载我的list_files.php。

当我点击链接时,它提醒我未定。我还在list_files.php中编写了我的PHP代码,用于获取php变量中的cookie值以进行另一次检查。

由Cookie设置的PHP变量:


As it is loading my list_files.php.
And when I am clicking on the link its alerting me "undefned". And I have also write my PHP code in list_files.php for getting cookies value in php variable for my another checking.
PHP variable set by Cookie:

<?php if(isset(


_COOKIE [ video]))
{
_COOKIE["video"])) {


value =
value =


这篇关于通过onclick in link按钮设置C​​ookie,然后通过PHP变量进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆