简体   繁体   English

重定向到以上目录PHP

[英]Redirect to above directory PHP

I'm trying to redirect my app to another php page thats located above at the root folder of the project. 我正在尝试将我的应用程序重定向到位于项目根文件夹上方的另一个php页面。 I'm having issues saving my SESSION variable and i think this will solve it. 我在保存SESSION变量时遇到问题,我认为这可以解决问题。

This is a very simple task i know but i'm very new this this so sorry if it's obvious. 我知道这是一个非常简单的任务,但是我对此很陌生,因此很抱歉。

I'm trying to avoid using http://../../../ .. etc therefore im looking for a relative URL solution. 我试图避免使用http://../../../ ..etc ,因此我正在寻找相对的URL解决方案。

Please see current setup: 请查看当前设置:

echo "<script type='text/javascript'>alert('Correct!');
       window.location='http://localhost/testing/yourprofile.php';
       </script>";
        exit();
// This is how you normally go one level above    
window.location.href = '../';

But may I give you some advise? 但是我可以给你一些建议吗? You should not need to redirect a user above the root directory. 您无需在根目录上方重定向用户。 Yo will encounter a huge number of problems. 哟会遇到很多问题。 Also your programs won't work on shared hosted Webservers. 另外,您的程序在共享的托管Web服务器上将无法运行。

Sometimes you may come up with an idea wich seems to work, but you can probably figure out a much easier solution. 有时您可能会想到一个似乎可行的想法,但是您可能会想出一个更简单的解决方案。 If you post more information about your question I will edit my answer. 如果您发布有关您问题的更多信息,我将编辑我的答案。

With JavaScript, you can return to the root by starting your path with / . 使用JavaScript,您可以通过/开头路径来返回到根目录。

For this example, change window.location='http://localhost/testing/yourprofile.php'; 对于此示例,更改window.location='http://localhost/testing/yourprofile.php'; to window.location.href='/testing/yourprofile.php'; window.location.href='/testing/yourprofile.php';

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

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