Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts

    Encoding a URL and passing it as a variable

    This is driving me crazy, and I know it's an easy one. I need to encode a URL such that ampersands become "amp;" etc. This then needs to get passed from one page to another through the URL. Basically, if a user tries to access a page while not being logged in, the encoded URL of the page he tried to access is sent as the variable "redirect" through the URL to the login page.

    I tried using
    PHP Code:
    header("Location: login.php?a=logout&redirect=http://".urlencode($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
    exit(); 
    But this doesn't work for a URL like "www.mysite.com/profile.php?view=signature&action=change". Nothing gets passed for some reason.
    Last edited by wldrumstcs; 10-13-2009 at 06:27 AM.

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by wldrumstcs View Post
    This is driving me crazy, and I know it's an easy one. I need to encode a URL such that ampersands become "amp;" etc. This then needs to get passed from one page to another through the URL. Basically, if a user tries to access a page while not being logged in, the encoded URL of the page he tried to access is sent as the variable "redirect" through the URL to the login page.

    I tried using
    PHP Code:
    header("Location: login.php?a=logout&redirect=http://".urlencode($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']));
    exit(); 
    But this doesn't work for a URL like "www.mysite.com/profile.php?view=signature&action=change". Nothing gets passed for some reason.
    htmlspecialchars can change & to entity &
    http://www.php.net/manual/en/functio...ecialchars.php

    urlencode it's result.

    best regards

  • Users who have thanked oesxyl for this post:

    wldrumstcs (10-12-2009)

  • #3
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts
    Worked like a charm. Thanks!

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by wldrumstcs View Post
    Worked like a charm. Thanks!
    you are welcome,

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •