开发者

Whats the best way to do a redirect in PHP with a hashtag?

开发者 https://www.devze.com 2023-03-23 05:18 出处:网络
After a successful authentication I send the user to the home page by calling header if($success) { header(\'Location: home.php\');

After a successful authentication I send the user to the home page by calling header

if($success) {
    header('Location: home.php');
    exit();
}

Ulitimatley I'd like to use a hashtag as part of the URL so for instance the URL开发者_JAVA技巧 to the user would look like this:

mysite/#!home

Can I do something like this or is there a better way to redirect them to the home page after a successful login?


That sort of hash tag is usually used with what is called, "addressing" or "deep linking", a type of javascript page navagation. What you want is URL Rewriting, which allows you to do things like www.website.com/home

Deep Linking : http://www.asual.com/jquery/address/

Url rewrite: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html


Because this :

if($success) {
    header('Location: yoursite/#!home');
    exit();
}

is not working ?


You can also pass a parameter to the successful page, and fire off some javascript to anchor the user down if that parameter is set:

<script type="text/javascript">
    <?php if (isset($_GET['val'])) { ?>
        // redirect to the appropriate hash from parameter
        document.location.hash = "<?php echo $_GET['val'] ?>";
    <?php } ?>
</script>

This won't give you a clean URL, but its a quick fix if you don't have access to any URL rewriting.

0

精彩评论

暂无评论...
验证码 换一张
取 消