启动会话失败_在不牺牲页面排名的情况下启动PHP会话

启动会话失败

This post was authored by Mark Sanborn. To learn more about Mark, click here.

这篇文章是由马克·桑伯恩 ( Mark Sanborn )撰写的。 要了解有关Mark的更多信息, 请单击此处

A while back I had been working on a website project that required an authentication login system. In order for the login system to properly operate every page of my site needed to check to see if there was a session created and the user was logged in. Some of you may know that in PHP you cannot view session variables without in fact initiating a session. So, for example if you wanted to provide a simple, "you are logged in as Mark click here to logout." on each and every page you would have to actually start a session to display this message properly.

前一段时间,我一直在从事一个需要身份验证登录系统的网站项目。 为了使登录系统正常运行,我的网站的每个页面都需要检查以查看是否创建了会话并已登录用户。你们中的某些人可能知道,在PHP中,您实际上无法启动会话变量就无法查看会话变量。会议。 因此,例如,如果您想提供一个简单的信息,“您以Mark身份登录,请单击此处以注销。” 在每个页面上,您都必须实际启动一个会话才能正确显示此消息。

At first this task may seem trivial. The code to start a session is one line:

起初,这项任务看似微不足道。 启动会话的代码为一行:

session_start();

After changing an existing website that was already indexed in Google quite well to include sessions I was shocked to find out what effect this might have in the Google index. A few weeks after making the change most if not all of my pages were no longer indexed by Google and for awhile I had no idea what was causing it.

在更改了一个已经很好地在Google中建立索引的现有网站以包含会话之后,我很震惊地发现这可能会对Google索引产生什么影响。 进行更改后的几周,大部分(如果不是全部)页面都不再被Google编入索引,有一段时间我不知道是什么原因造成的。

After awhile I would notice that sometimes my URLs were taking on an additional string of numbers. They would look like this:

过了一会儿,我会发现有时我的URL带有附加的数字字符串。 他们看起来像这样:

http://www.yourdomain.com/?PHPSESSID=61ca9c60b10cc8f481ac9c1eacbee797

When I saw this I immediately knew this was the reason Google was dropping my pages. This string of numbers inherently does two drastic SEO mistakes. For one this number changes every time you go to the site. What this means is that Google thinks it is a different URL with the same content as the last URL it indexed. Many know that Google penalizes pages for duplicate content. This extra string of numbers essentially makes your entire website a bunch of duplicates.

看到此消息后,我立即知道这就是Google删除我的页面的原因。 这串数字固有地会造成两个严重的SEO错误。 例如,每次您访问该站点时,此数字都会更改。 这意味着Google认为这是一个不同的URL,其内容与其上次索引的URL相同。 许多人知道Google会对网页中的重复内容进行处罚。 这些额外的数字串实际上使您的整个网站变成一堆重复项。

If that isn't enough already it also makes another SEO mistake. Google doesn't weigh pages that appear to be static the same as they do a page that appears to be a one time randomly generated page. To Google the above URL appears to be a page only meant to be seen by one person. Google gives less indexing weight to it.

如果这还不够,那么还会导致另一个SEO错误。 Google不会像看起来是一次随机生成的页面那样权衡看起来是静态的页面。 对于Google来说,上述URL似乎是一个只能被一个人看到的页面。 Google减少了索引的权重。

So what did I do to fix this issue?

那么,我该怎么做才能解决此问题?

Well after a little bit of searching I found that this is actually a common problem and there is a simple solution to fix it. I sure wish I knew about this before I sacrificed my page rank and indexing. To save you the trouble in the future please learn from my mistake and use the following code before starting any session variable.

经过一番搜索,我发现这实际上是一个普遍的问题,有一个简单的解决方案可以解决。 我当然希望在牺牲页面排名和索引之前了解这一点。 为了将来避免麻烦,请从我的错误中吸取教训,并在启动任何会话变量之前使用以下代码。

//These commands must be set BEFORE the session is started
ini_set('session.use_trans_sid', false);
ini_set('session.use_only_cookies', true);
ini_set('url_rewriter.tags', '');
// start session
session_start();

Moral of the story?

故事的道德启示?

Be very careful what you do to your pages your Google indexes may count on it.

请务必小心,您对Google索引可能会对页面所做的操作。

关于马克·桑伯恩 (About Mark Sanborn)

Hi, I am Mark Sanborn. I am 22 and just graduated from the University of Montana. I have had an interest in computers for as long as I can remember. I still remember the DOS days and really started getting into computers when Windows 3.1 was around. I made my first webpage in the 7th grade. My passion for web design and computers has only progressed from there.

嗨,我是Mark Sanborn。 我今年22岁,刚从蒙大拿大学毕业。 只要我记得,我就对计算机感兴趣。 我仍然记得DOS时代,当Windows 3.1出现时,它才真正开始进入计算机。 我在7年级建立了第一个网页。 从那时起,我对网页设计和计算机的热情才有所发展。

How did I learn to program? In college I was approached by a group that wanted a realty website created for the University business plan competition. I gladly took the job and forced myself to learn PHP/mysql while working on the project. By the time the project was complete I was fairly fluent in PHP and was confident I could build pretty much anything I set my mind to. I later used these skills to create a corporate website with a custom ecommerce shopping cart for a client.

我如何学习编程? 在大学里,我遇到了一个想要为大学商业计划竞赛创建房地产网站的小组。 我很高兴接受这份工作,并强迫自己在项目上学习PHP / mysql。 到项目完成时,我已经相当熟练地使用PHP,并且确信我可以建立自己想做的几乎所有事情。 后来,我使用这些技能来为客户创建带有自定义电子商务购物车的公司网站。

Computer Related Education I just received my B.S. in Business Administration Information Systems. I scored nearly a perfect score on the MCP test allowing my to achieve the Microsoft Certifed Professional status. While attending college I worked for the University as tech support for dorm students and faculty. I have a lot of experience working with computers but there is still a lot I can learn from others. I also believe that you learn the most by teaching it to others. This is why I created my own blog.

计算机相关教育我刚刚获得了工商管理信息系统学士学位。 我在MCP测试中得分近乎完美,这使我获得了Microsoft认证专家资格。 上大学时,我在大学工作,为宿舍学生和教职员工提供技术支持。 我有很多使用计算机的经验,但是我仍然可以从别人那里学到很多东西。 我还相信,您可以通过向其他人教书来学习最多。 这就是为什么我创建自己的博客的原因。

What Languages Do You Use? HTML, CSS, MySQL, PHP, Java, XML, Bash. For some reason I want to learn python yet I don't know what I would use it for. Some experience in: ASP, Visual Basic, ColdFusion.

您使用什么语言? HTML,CSS,MySQL,PHP,Java,XML,Bash。 由于某种原因,我想学习python,但我不知道该怎么用。 一些经验:ASP,Visual Basic,ColdFusion。

What Do You Do In Your Spare Time? I spend a lot of time in front of the computer but I am not your typical programmer that loves Star Trek and converses with their friends about what to do in the event of zombie attacks. All stereotypes aside, I love to play guitar I am interested in all types of music, mostly blues and classic rock. I am an avid weight lifter and practice Judo. I don't consider myself a fan of team based sports; however, I love individual sports. Last summer I learned to paraglide and for the past two winters I have been enjoying the fabulous sport of kiteboarding on snow.

您在业余时间做什么? 我在计算机前花费了大量时间,但我不是您喜欢Star Trek并与他们的朋友交谈以防万一发生僵尸攻击时该怎么做的典型程序员。 除了所有的刻板印象,我喜欢弹吉他。我对所有类型的音乐都感兴趣,主要是布鲁斯和古典摇滚。 我是一名狂热的举重运动员并练习柔道。 我不认为自己是团队运动的忠实拥护者。 但是,我喜欢个人运动。 去年夏天,我学会了滑翔伞运动,在过去的两个冬天里,我一直在享受着神话般的风筝冲浪运动。

翻译自: https://davidwalsh.name/initiating-php-sessions-without-sacrificing-page-rank

启动会话失败

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值