<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>session &#8211; LPC影子技术分享</title>
	<atom:link href="https://www.mudbest.com/tag/session/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.mudbest.com</link>
	<description>行影不离,忘之却步.</description>
	<lastBuildDate>Wed, 12 Dec 2012 12:12:21 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>
	<item>
		<title>解决PHP获取上一页的URL地址时丢失session</title>
		<link>https://www.mudbest.com/%e8%a7%a3%e5%86%b3php%e8%8e%b7%e5%8f%96%e4%b8%8a%e4%b8%80%e9%a1%b5%e7%9a%84url%e5%9c%b0%e5%9d%80%e6%97%b6%e4%b8%a2%e5%a4%b1session/</link>
					<comments>https://www.mudbest.com/%e8%a7%a3%e5%86%b3php%e8%8e%b7%e5%8f%96%e4%b8%8a%e4%b8%80%e9%a1%b5%e7%9a%84url%e5%9c%b0%e5%9d%80%e6%97%b6%e4%b8%a2%e5%a4%b1session/#comments</comments>
		
		<dc:creator><![CDATA[hkshadow]]></dc:creator>
		<pubDate>Wed, 12 Dec 2012 12:12:21 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[分享]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[跳转]]></category>
		<guid isPermaLink="false">http://www.mudbest.com/?p=1730</guid>

					<description><![CDATA[很多系统中都应用了session保存客户的信息,在操作每个页面的时候都对客户的状态进行判断,如果不存在sess ... <a title="解决PHP获取上一页的URL地址时丢失session" class="read-more" href="https://www.mudbest.com/%e8%a7%a3%e5%86%b3php%e8%8e%b7%e5%8f%96%e4%b8%8a%e4%b8%80%e9%a1%b5%e7%9a%84url%e5%9c%b0%e5%9d%80%e6%97%b6%e4%b8%a2%e5%a4%b1session/" aria-label="阅读 解决PHP获取上一页的URL地址时丢失session">阅读更多</a>]]></description>
										<content:encoded><![CDATA[<p>很多系统中都应用了session保存客户的信息,在操作每个页面的时候都对客户的状态进行判断,如果不存在session的值,就跳转到登入页面.</p>
<p>问题出现了:如果客户重新登入后能跳转到上一个正在编辑的页面那就最好了.</p>
<p>上网搜集了一些资料发现一般都是在URL后面带上上一页面的地址,然后在跳转回去.</p>
<p>思路是一样的,在当前页面获取上一页的url然后保存在session中,如果从session中能取到赋值,就跳转到上一页,如果没有就跳转到登入后的后页.<span id="more-1730"></span></p>
<p>具体代码如下: 在处理session跳转的页面加入如下代码,一般都是包含的头部文件.如果不存在的话就跳转到login.php页面</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php   
if(!isset($_SESSION&#x5B;'admin_loginname'])){   
//获得上一个页面的URL   
$_SESSION&#x5B;'prev_url'] = $_SERVER&#x5B;'HTTP_REFERER'];   
//echo $_SESSION&#x5B;'prev_url'];   
include(&quot;login.php&quot;); 
include(&quot;backend-footer.php&quot;);   
exit(0);   
}  
?&gt;
</pre>
<p>在login.php登录成功后的页面加入</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php   
//增加了跳转到前一个页面的   
if($_SESSION&#x5B;'prev_url']){   
    $prev_url = $_SESSION&#x5B;'prev_url'];   
    unset($_SESSION&#x5B;'prev_url']);   //清空session中的值,原理跟get方式获取上一页面一样
    header(&quot;Location: &quot;.$prev_url);    
}else{   
    header(&quot;Location: index.php&quot;);         
}
?&gt;
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.mudbest.com/%e8%a7%a3%e5%86%b3php%e8%8e%b7%e5%8f%96%e4%b8%8a%e4%b8%80%e9%a1%b5%e7%9a%84url%e5%9c%b0%e5%9d%80%e6%97%b6%e4%b8%a2%e5%a4%b1session/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
