Julian day from DateTime

Is there a better way of converting a DateTime object to a Julian day number than something like this: $jd = GregorianToJD( $dt->format('n'), $dt->format('j'), $dt->format('Y') ); I'm a bit surprised there isn't either a function to do it directly or a format specifier to print it. Am I missing something obvious? Edit: Many of the (somewhat sarcastic) replies below seem to b

来自DateTime的Julian日

有没有更好的方法来将DateTime对象转换为Julian天数,而不是像这样: $jd = GregorianToJD( $dt->format('n'), $dt->format('j'), $dt->format('Y') ); 我有点惊讶,没有一个函数可以直接执行,也没有格式说明符来打印它。 我错过了明显的东西吗? 编辑:下面的许多(有点讽刺)回复似乎假设朱利安日的数字与长期过时的朱利安日历有某种关系。 事实并非如此。 Julian日数是从相当任意的时代开始计算天数的最常用

date() is malfunctioning

i have a php methode that checks if a passed in parameter is a date. Here's it: public function is_Date($str){ if (is_numeric($str) || preg_match('^[0-9]^', $str)){ $stamp = strtotime($str); $month = date( 'm', $stamp ); $day = date( 'd', $stamp ); $year = date( 'Y', $stamp ); return checkdate($month, $day, $year)

日期()发生故障

我有一个PHP方法,检查是否传入参数是一个日期。 这是它: public function is_Date($str){ if (is_numeric($str) || preg_match('^[0-9]^', $str)){ $stamp = strtotime($str); $month = date( 'm', $stamp ); $day = date( 'd', $stamp ); $year = date( 'Y', $stamp ); return checkdate($month, $day, $year); } return

Session Flag doesn't work in Javascript

I use session flag in javascript for IF function. If session flag is 1, the javascript will show a specifict div on click. I have tried it manually, but the code doesn't seem to work. This is my JS code: $(document).ready(function(){ check = <?= $_SESSION['flag'] ?>; $("#bag").click(function(){ if(check==0){ $("#login").show(); $("#notlogin").hide(); } else

会话标志在Javascript中不起作用

我在javascript中为IF函数使用会话标志。 如果会话标志为1,则JavaScript将显示点击时的特定div。 我已经手动尝试过,但代码似乎不起作用。 这是我的JS代码: $(document).ready(function(){ check = <?= $_SESSION['flag'] ?>; $("#bag").click(function(){ if(check==0){ $("#login").show(); $("#notlogin").hide(); } else { $("#login").hide(); $("#notlogin").show();

PHP secure session and cookies

I don't understand why we have to secure the cookies and session, I have a cookie that store userid, username encrypted password. I have a function that checks the cookies at any moment if is the information matches with DataBase information, if not, redirect to login page. however I don't understand the risk with that can view this information and what he can do with this information.

PHP安全会话和cookie

我不明白为什么我们必须保护cookie和会话,我有一个存储用户名,用户名加密密码的cookie。 我有一个函数,可以随时检查cookie是否与DataBase信息匹配,如果不是,则重定向到登录页面。 但我不明白风险,可以查看此信息以及他可以用这些信息做什么。 任何人都可以向我解释什么是风险? 确切地说,很难量化。 首先,请记住,cookie 在每个请求中都在客户端和服务器之间传输。 这对于有人拦截他们来说可能有很多机会。 假

Cookies instead of sessions?

What I've read and know about sessions is that they aren't really reliable with all that session id hijacking and stuff. So I decided I won't use sessions in my project, I'd rather just go with ordinary cookies and hope for the best. So basically what I have set up is kind of like a session but hopefully will be harder to crack. Unfortunately I seem to be unable to build it ha

Cookies而不是会话?

我已阅读和了解的会议是,他们不是真正可靠的会议id劫持和东西。 所以我决定我不会在我的项目中使用会话,我宁愿随意使用普通的cookies并希望获得最佳效果。 所以基本上我所设置的就像一个会议,但希望更难以破解。 不幸的是,我似乎无法让它难以破解。 所以基本上我认为这是更安全的问题,而不是cookies或会话之间的选择,但我似乎无法在任何直接文本中找到它。 我应该在会话cookie中散列什么,以及如何? 我读过哈希算

Authenticate system without sessions

I'm interested in your advice/opinion on this security problem. I was thinking on doing something like this: Get hash MAC (sha256) from string built from userId + expirationTime and as secret key string built from some secret string and $_SERVER['HTTP_USER_AGENT']. Get hash MAC (sha256) from userId + expirationTime and as secret key previously made hash (from step 1). Build st

验证没有会话的系统

我对你对这个安全问题的建议/意见很感兴趣。 我正在考虑做这样的事情: 从userId + expirationTime构建的字符串获取哈希MAC(sha256),并将其作为从某个秘密字符串和$ _SERVER ['HTTP_USER_AGENT']构建的密钥字符串。 从userId + expirationTime获取哈希MAC(sha256),并将其作为以前制作哈希的密钥(来自步骤1)。 从userId | expiration |构建字符串 和以前做的散列(从步骤2)。 用'rijndael-256

Switching between HTTP and HTTPS pages with secure session

Update: Note that every website switching between unsecure HTTP and encrypted HTTPS pages, is inevitable prone to SSL-strip. Please think about using HTTPS for the whole site, although this neither can prevent SSL-strip, at least this gives the user the possibility to call the site safely, if he cares. For sites that need to switch, this method is probably still the best option. It's a co

使用安全会话在HTTP和HTTPS页面之间切换

更新:请注意,每个网站在不安全的HTTP和加密的HTTPS页面之间切换,都不可避免地容易出现SSL-strip。 请考虑在整个网站上使用HTTPS,但这既不能防止SSL-strip,至少这让用户可以安全地呼叫该网站,如果他在意的话。 对于需要切换的网站,此方法可能仍然是最佳选择。 这是一种常见的情况,一个网站的页面含有敏感数据,应该只能使用HTTPS协议访问,而其他数据则使用非关键数据。 我发现了一个允许在安全和非安全页面之间切

Creating a secure login using sessions and cookies in PHP

I am making a login script that I would like to be as secure as possible. Problem is, security seems to be a never ending battle. So essentially, I am looking for suggestions and improvements to my ideas. What I have is a login based solely on sessions. Anytime the session information changes, session_regenerate_id() is called to avoid obvious hijacking attempts. When the session is not se

使用PHP中的会话和cookie创建安全登录

我正在制作一个登录脚本,我希望尽可能安全。 问题是,安全似乎是一场永无止境的战斗。 所以基本上,我正在寻找对我的想法的建议和改进。 我拥有的是仅基于会话的登录。 每次会话信息发生变化时,都会调用session_regenerate_id()以避免发生明显的劫持尝试。 当会话未设置时,我检查cookie是否有效登录,如果成功,我更新会话。 我试图通过添加散列值以及一段唯一用户信息(如用户名或ID)来保护cookie。 这个哈希包含

Convert PHP object to associative array

I'm integrating an API to my website which works with data stored in objects while my code is written using arrays. I'd like a quick and dirty function to convert an object to an array. Just typecast it $array = (array) $yourObject; From http://www.php.net/manual/en/language.types.array.php If an object is converted to an array, the result is an array whose elements are the objec

将PHP对象转换为关联数组

我正在将API集成到我的网站,该网站使用存储在对象中的数据处理数据,同时使用数组编写代码。 我想要一个快速和脏的函数来将对象转换为数组。 只是说明它 $array = (array) $yourObject; 从http://www.php.net/manual/en/language.types.array.php 如果一个对象转换为数组,则结果是一个数组,其元素是该对象的属性。 这些键是成员变量名称,但有一些值得注意的例外:整数属性不可访问; 私有变量的类名前加变量名;

How to convert an array to object in PHP?

我如何将这样的数组转换为对象? [128] => Array ( [status] => Figure A. Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution. ) [129] => Array ( [status] => The other day at work, I had some spare time ) ) In the simplest case, it's probably sufficient to "cast" the array as an object: $object

如何将数组转换为PHP中的对象?

我如何将这样的数组转换为对象? [128] => Array ( [status] => Figure A. Facebook's horizontal scrollbars showing up on a 1024x768 screen resolution. ) [129] => Array ( [status] => The other day at work, I had some spare time ) ) 在最简单的情况下,将阵列“转换”为对象可能就足够了: $object = (object) $array; 另一个选择是将一个标准