我正在尝试用javascript设置一个cookie,然后用php在其他页面中读取它.我可以通过编写来编写cookie
document.cookie = cookieName+"="+cookieValue;
Run Code Online (Sandbox Code Playgroud)
我部分工作.- 写了cookie,我$_COOKIE[cookieName]
只能在同一个网页上阅读.
这真的不是很有用.我需要在另一页中阅读.我通常在asp.net和c#中开发,所以我对php很新.难道我做错了什么?
感谢您的时间!
EDIT1:两个页面都在同一个域中.例如.site.com/index.php - > site.com/index2.php
EDIT2:cookie通过以下方式设置在一页中:
function SetCookie(cookieName,cookieValue,nDays) {
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue)
+ ";expires="+expire.toGMTString();
}
Run Code Online (Sandbox Code Playgroud)
而在另一个页面中它无法访问,但在同一页面它可以...
EDIT3:我尝试设置域名并添加path=<?php echo $_SERVER['HTTP_HOST']; ?>
到javascript代码...仍然没有..
编辑4:到目前为止我有..
document.cookie = cookieName+"="+escape(cookieValue)+"; expires="+expire.toGMTString()+"; path=/"+"; domain=.<?php echo $_SERVER['HTTP_HOST']; ?>";
Run Code Online (Sandbox Code Playgroud)
而且我仍然可以从同一页面阅读cookie.
EDIT5:哦......我的......上帝...这一直都是一个错字...只需要删除"path =/"+" ; dom ......"我现在对自己感到羞耻...在此期间我也重置了我的饼干,所以Jared现在我不幸地接受你的帖子作为anwser ...我给我的名字带来了耻辱!!! ....
我有以下link_to路径:
HTTP://本地主机:3000 /字母/ showpdf/3
我的字母控制器中有以下自定义操作:
def showpdf
@letter = Letter.find(params[:id])
@redcloth_letter = " <style type='text/css'> </style>"
@redcloth_letter = @redcloth_letter << RedCloth.new(@letter.body).to_html
pdf = PDFKit.new(@redcloth_letter)
pdf.stylesheets << "#{RAILS_ROOT}/public/stylesheets/compiled/pdf.css"
send_data(pdf.to_pdf, :filename => "pdf.pdf")
end
Run Code Online (Sandbox Code Playgroud)
我目前没有回到浏览器.
编辑:这是我在红宝石日志中看到的:
Processing LettersController#showpdf (for 127.0.0.1 at 2011-02-18 15:10:31) [GET]
Parameters: {"action"=>"showpdf", "id"=>"3", "controller"=>"letters"}
Letter Load (1.5ms) SELECT * FROM "letters" WHERE ("letters"."id" = 3)
Sending data pdf.pdf
Completed in 1917ms (View: 6, DB: 2) | 200 OK [http://localhost/letters/showpdf/3]
Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中使用Rails引擎作为gem.引擎有PostsController
很多方法,我想在我的主应用程序中扩展控制器逻辑,例如添加一些方法.如果我只是PostsController
在主应用程序中创建,则不会加载引擎的控制器.
有一个解决方案提出了Rails引擎基于改变扩展功能ActiveSupport::Dependencies#require_or_load
这是唯一/正确的方法吗?如果是的话,我在哪里放这段代码?
EDIT1:
module ActiveSupport::Dependencies
alias_method :require_or_load_without_multiple, :require_or_load
def require_or_load(file_name, const_path = nil)
if file_name.starts_with?(RAILS_ROOT + '/app')
relative_name = file_name.gsub(RAILS_ROOT, '')
@engine_paths ||= Rails::Initializer.new(Rails.configuration).plugin_loader.engines.collect {|plugin| plugin.directory }
@engine_paths.each do |path|
engine_file = File.join(path, relative_name)
require_or_load_without_multiple(engine_file, const_path) if File.file?(engine_file)
end
end
require_or_load_without_multiple(file_name, const_path)
end
end
Run Code Online (Sandbox Code Playgroud) 我很难找到如何将SQL结果保存到String或结果返回的任何类型.
我的SQL查询是
SELECT SUM(Length) FROM tbl_test WHERE TITLE LIKE 't%'
Run Code Online (Sandbox Code Playgroud)
这里我需要一个函数来总结所有数据行的长度,其中标题以字母"T"开头,当在MS-SQL中执行查询时它返回"188.99"(sql类型为十进制)
我的问题是,如何将该值保存到C#变量中?查询始终返回具有特定值的一行,我想将其保存到变量中.我有一个C#函数来执行查询,我只需要将该行的值188.99保存到变量中.任何建议都很酷,无论我将结果保存为十进制变量还是字符串.
我想在数组中的所有项目中进行字符串替换.我有的是:
$row['c1'] = str_replace("&", "&", $row['c1']);
$row['c2'] = str_replace("&", "&", $row['c2']);
$row['c3'] = str_replace("&", "&", $row['c3']);
$row['c4'] = str_replace("&", "&", $row['c4']);
$row['c5'] = str_replace("&", "&", $row['c5']);
$row['c6'] = str_replace("&", "&", $row['c6']);
$row['c7'] = str_replace("&", "&", $row['c7']);
$row['c8'] = str_replace("&", "&", $row['c8']);
$row['c9'] = str_replace("&", "&", $row['c9']);
$row['c10'] = str_replace("&", "&", $row['c10']);
Run Code Online (Sandbox Code Playgroud)
如何用更少的代码实现这一目标?我认为foreach声明可行,例如:
$columns = array($row['c1'], $row['c2'], $row['c3'], $row['c4'], $row['c5'], $row['c6'], $row['c7'], $row['c8'], $row['c9'], $row['c10']);
foreach ( $columns as $value){
$value = str_replace("&", "&", $value);
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
我不确定convertToWorldSpace的工作原理.
我有spriteA,它是父母.
我将它设置为40,40位置并将其添加到场景中.
我有第二个spriteB,我设置在80,80位置.
我将spriteB添加到spriteA.
我打印出spriteB的位置:80,80.
然后我打印[self convertToWorldSpace:spriteB.position].而且,我仍然得到80,80.spriteB的位置应该不同吗?
如何在MySQL查询中使用COUNT CASE和WHEN语句,在一个MySQL查询中计算数据是否为NULL以及何时不为NULL?
基本上我有玩家名单,我想把它们配对,这样每个玩家都会玩一次.找到这些数据的最快方法是什么?
虽然我愿意解析字符串中包含的指令,但我基本上是试图从它的空格和制表符字符中清除字符串,以便在其中查找指令.不幸的是,我的循环进入一个无限循环,我无法找到为什么因为我在每次擦除char时刷新迭代器...
请帮忙吗?
void myClass::parseInstructions(std::string& line)
{
std::string::iterator it;
for (it = line.begin(); it != line.end(); ++it)
if (((*it) == ' ') || ((*it) == '\t'))
it = line.erase(it);
}
Run Code Online (Sandbox Code Playgroud) 我试图通过JSON API阅读Tumblr帖子.
使用他们的API,数据传回如下:
var tumblr_api_read= {
"posts":[
"id":"1234",
"regular-title":"This is the title of the post",
"regular-body":"This is the body of the post"
]
}
Run Code Online (Sandbox Code Playgroud)
我很难回归"常规冠军"和"常规身体".
我的JS代码如下所示:
var tumblr= tumblr_api_read['posts'];
for (eachPost in tumblr)
{
var id=posts[eachPost].id; //Works fine
var regularTitle=posts[eachPost].regular-title; //Returns NaN
}
Run Code Online (Sandbox Code Playgroud)
我假设它是因为帖子[eachPost] .regular-title中有短划线但是我无法找到任何关于如何使其在这种情况下工作的文档!
谢谢.