简体   繁体   English

Cookie集和重定向问题PHP和.Net应用程序

[英]Cookie set and redirection issue PHP and .Net application

I'm using cookie to communicate between .net and php application. 我正在使用cookie在.net和php应用程序之间进行通信。 I'm able to retrieve cookie value using php and the cookie is set using .net So in both files, i can view the cookie values. 我可以使用php检索cookie值,并且使用.net设置cookie,因此在两个文件中,我都可以查看cookie值。

What i want to do now is. 我现在想做的是。

If the user is logged in using aspx application, then he is allowed to view the php pages(using cookie). 如果用户使用aspx应用程序登录,则允许他查看php页面(使用cookie)。 If not logged in, they will be redirected to aspx page. 如果未登录,它们将被重定向到aspx页面。

Here is the code 这是代码

if (!isset($_COOKIE["AuthoerCode"])){
   header("Location:login.aspx");
}else{
  header("Location:dashboard.php");
}  

The above if conditions works perfect but the else part is not working and I'm getting this error. 上面的if条件工作完美,但是else部分不起作用,并且出现此错误。

The page isn't redirecting properly(Firefox)

In other words, i need to check in my dashboard.php page whether the cookie is set or not - If set, view the dashboard.php else view the login.aspx 换句话说,我需要在我的dashboard.php页面中检查是否设置了cookie-如果已设置,请查看dashboard.php,否则请查看login.aspx

Where is the problem now? 现在问题出在哪里?

You need to give full server path for it, 您需要为其提供完整的服务器路径,

for example 例如

if (!isset($_COOKIE["AuthoerCode"])){ $url = "http://". $_SERVER['HTTP_HOST']."/login.aspx"; header("Location: ". $url); }else{ $url = "http://". $_SERVER['HTTP_HOST']."/dashboard.php"; // HERE PUT your php file's full path. you can able to access it if it also on another server. header("Location:".$url); }

Check if you are not in a loop. 检查您是否不在循环中。 Your dashboard page may be redirecting you back to the current page where you are checking cookie 您的信息中心页面可能会将您重定向到您正在检查Cookie的当前页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM