如何将SESSION变量传递给父目录中的页面?(How to pass SESSION variable to a page in the parent directory?)
在我的网站上,我想有几个子域名。 为给定子域创建上下文的文件存储在相应的子目录中。
有时我需要链接到不属于子域的文件。
例如,在我的“subdomain1.mysite.org”上,我有一个指向“www.mysite.org/login.php”的链接。 “login.php”存储在包含与子域对应的所有子目录的目录中。
如果我以这种方式链接到“www.mysite.org/login.php”:href
href='../login.php'
,它不起作用。 因为浏览器试图访问“subdomain1.mysite.org/../login.php”。 为了解决这个问题,我以这种方式建立链接:href='http://www.mysite.org/login.php'
但我认为通过这种方式我无法将会话变量传递给新页面(可以是案子?)。所以,我的问题是我找不到将会话变量传递到位于父目录(或位于另一个域的页面)的页面的方法。 有谁知道如何解决这个问题?
添加
按照建议,我厌倦了使用
session_set_cookie_params
来解决问题。 但我仍然无法达到预期的效果。 在更多细节中,我执行以下操作:我在
index.php
文件中为subdomain1.mysite.org
生成内容我使用以下代码:session_set_cookie_params(24*60*60,'/','.mysite.org'); session_start(); $_SESSION['page'] = $PHP_SELF;
比以后,在同一个文件中我链接到我的一个页面(我想问题可以在这里)。 我通过以下方式创建链接:
href='http://www.mysite.org/login.php'
在login.php文件中,我有以下代码:
session_set_cookie_params(24*60*60,'/','.mysite.org'); session_start(); print "a".$_SESSION['page']."b";
结果,“a”和“b”之间没有任何内容。 所以,我仍然无法将会话变量从一个页面传递到另一个页面。 有人知道我做错了什么吗?
添加2我必须说如果我添加以下行我的问题就解决了:
session_name("some_name");
之前
session_set_cookie_params
。On my web site I would like to have several sub-domains. Files that create context for a given sub-domain are stored in corresponding sub-directory.
Sometimes I need to link to the files that do not belong to the sub-domain.
For example, on my "subdomain1.mysite.org" I have a link to "www.mysite.org/login.php". The "login.php" is stored in the directory that contains all subdirectories corresponding to the sub-domains.
If I make the link to the "www.mysite.org/login.php" in this way:
href='../login.php'
, it does not work. Because browser tries to access "subdomain1.mysite.org/../login.php". To solve this problem I make the link in this way:href='http://www.mysite.org/login.php'
but I think that in this way I cannot pass my session variables to the new page (can it be the case?).So, my problem is that I cannot find a way to pass session variables to the page that is located in the parent directory (or to the page that is located on another domain). Does anybody know how this problem can be solved?
ADDED
As recommended, I tired to use
session_set_cookie_params
to solve the problem. But I still cannot manage to get the desired result. In more details I do the following:I have in the
index.php
file that generates content forsubdomain1.mysite.org
I use the following code:session_set_cookie_params(24*60*60,'/','.mysite.org'); session_start(); $_SESSION['page'] = $PHP_SELF;
Than later, in the same file I make a link to one of my pages (I think problem can be here). I create the link in the following way:
href='http://www.mysite.org/login.php'
In the login.php file I have the following code:
session_set_cookie_params(24*60*60,'/','.mysite.org'); session_start(); print "a".$_SESSION['page']."b";
As the result there is nothing between "a" and "b". So, I still cannot pass the session variables from one page to another one. Does anybody know what I am doing wrong?
ADDED 2 I have to say that my problem is solved if I add the following line:
session_name("some_name");
before the
session_set_cookie_params
.
原文:https://stackoverflow.com/questions/4948340
最满意答案
您需要获取额外的数据,如下所示:
autocomplete :customer, :lastname, :display_value => :display_autocomplete, :extra_data => [:firstname, :lastname]
You need to get the extra data, like so:
autocomplete :customer, :lastname, :display_value => :display_autocomplete, :extra_data => [:firstname, :lastname]
相关问答
更多-
当用户在使用rails3-jquery-autocomplete时从自动完成列表中选择一个下拉项目时执行重定向的最佳方法是通过“railsAutocomplete.select”事件,当用户选择其中一个选项时会触发该事件。 这里记录了如何做到这一点。 这种方法意味着您可以避免编辑rails3-jquery-autocomplete代码,并且只有当用户从下拉选项中选择时才会导致重定向,而不是表单字段的“onChange”,这实际上并不是什么你要。 The best way to perform re-dire ...
-
就像一个想法..: 在您的代码中,您看起来有多个自动填充字段: <%=f.autocomplete_field :skill_name, users_autocomplete_vocab_name_path %> 如果这些字段都具有相同的html'id'和'name'属性(最有可能发生),则js可能无法获得所需的字段。 所以,只是为了澄清:1。在您的服务器日志中,您是否看到该请求实际到达您的控制器? (users_autocomplete_vocab_name_path)2。如果您在视图中只留下一个自动填 ...
-
我的问题很愚蠢但事实证明它与类别表使用自定义外键这一事实无关。 我的第一个问题是使用表名的复数版本而不是单数。 一旦我将所有对用户的引用更改为用户,我注意到javascript控制台没有向我抛出任何异常,所以我想我已经破坏了所有内容并且调用没有进行或者它正在进行并且它没有呈现正常。 控制台中存在正确的MYSQL调用证实了我的怀疑。 就在那时,我看到列表在我的页面右侧呈现,可能是由于其他地方发生了奇怪的样式。 底线是拥有自定义外键根本不会改变宝石的使用。 应使用原始表名。 My problem was sil ...
-
使用rails3-jquery-autocomplete的多个输入字段(Use multiple input fields with rails3-jquery-autocomplete)[2022-03-27]
所以你需要发送额外的字段并考虑它们进行搜索。 您可以使用:fields选项发送额外字段: f.autocomplete_field :academic_title, fields: { country: "#country" } 然后你需要考虑这个额外的字段进行搜索。 class AcademicTitleController < ActiveRecord::Base def autocomplete_academic_title country = params[:country] ... -
您需要获取额外的数据,如下所示: autocomplete :customer, :lastname, :display_value => :display_autocomplete, :extra_data => [:firstname, :lastname] You need to get the extra data, like so: autocomplete :customer, :lastname, :display_value => :display_autocomplete, :extra ...
-
我会写出自己的答案,但我不确定我能否比RSpec更好地描述它,因此这是直接从这里获取的 : Rails 4.x ActiveRecord::Migration等待迁移检查 如果你不使用ActiveRecord你不需要担心这些设置。 Rails 4.x的用户现在可以利用改进的模式迁移和同步功能。 在RSpec 3之前,用户需要在开发和测试环境中手动运行迁移。 另外,根据规格是通过rake还是通过standalone rspec命令运行,行为会有所不同。 随着Rails 4的发布,新的API已经暴露在Activ ...
-
首先,总结一下我的方法。 在MachineCosting表单中,使用'rails3-jquery-autopopulate'gem按名称搜索Machines。 Hack MachineController还以json形式发送'Parts info'和匹配的机器。 当用户选择一台机器时,使用javascript为PartCostings添加nested_forms,并使用以json形式收到的数据部分填充它们。 现在我就是这样做的(代码部分)。 视图/ machine_costings / _form.html ...
-
在你的控制器中 def get_autocomplete_items(parameters) items = active_record_get_autocomplete_items(parameters) items = items.where(searchable: true) end 在上面的示例中,我们调用active_record_get_autocomplete_items而不是super ; 由于处理多个ORM的设计,因为这些方法是动态调用的,所以没有超级。 在上面的示例中假设了Ac ...
-
rails3-jquery-autocomplete:Javascript TypeError(rails3-jquery-autocomplete: Javascript TypeError)[2022-06-15]
是的,事实证明我有一个错误的javascript_include_tag,它加载了另一个jquery副本。 那就是问题所在 Yup, turns out I had an errant javascript_include_tag that loaded another copy of jquery. That was the issue -
我的一个项目的一个例子: routes.rb: get 'users/autocomplete_category_name' 视图: <%= form_tag 'users/index' do %> <%= autocomplete_field_tag 'name', '', users_autocomplete_category_name_path, :size => 75 %> <% end %> An example from one of my projects: routes.rb: ge ...