我可以使用PHP重定向到内部链接? [英] can i redirect to an internal link using php?

查看:224
本文介绍了我可以使用PHP重定向到内部链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php设置重定向到内部链接。基本上,我正在使用jquerymobile做一个应用程序,导航要求您浏览div而不是文档。但是,我想出的代码看起来像这样

I am trying to set a redirect to an internal link with php. Basicaly, i am doing an app using jquerymobile, and the navigation requires that you navigate through divs rather than documents. However, the code i figured out looks like this

if (isset($_POST['insert'])) {
    $post = $_POST['wish'];
    $fk_id = $_SESSION['id'];
    $succes = "";
    $succes .= "<h1>SUCCES</h1>";
    $insert_wish_sql = "INSERT INTO wishlist(wish_id, wish, fk_id, datetime) VALUES ('', '$post', '$fk_id' , CURDATE())";//insert new post
    $res = mysql_query($insert_wish_sql);

    if ($insert_wish_sql) {
        header('Location:#wishlist');
    }
}

我也试过位置:index.php#wishlist < br>
任何想法?

I also tryied Location:index.php#wishlist
any ideas?

推荐答案

不,你不能。 位置:标头用于HTTP客户端,HTTP并不真正关心锚片段。此外,RFC要求该标题中指定的URL为完整URL。

No, you can't. The Location: header is for the HTTP client, and HTTP doesn't really care about the anchor fragment. Plus, the RFCs require that URLs specified in that header be full URLs.

现在,您可以通过锚片段链接到实际资源。

Now, what you can get away with sometimes is linking to the actual resource with the anchor fragment.

header('Location: http://example.com/someResource#wishlist');

此外,您应该知道您的代码对SQL注入攻击是开放的,并且您将被黑客攻击如果你还没有。 学习使用PDO准备/参数化查询或类似内容以避免这个问题。

Also, you should know that your code is wide open to SQL injection attacks, and you will be hacked if you haven't been already. Learn to use prepared/parameterized queries with PDO or similar to avoid this problem.

这篇关于我可以使用PHP重定向到内部链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆