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 8 of 8

Thread: Redirect stuff

  1. #1
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts

    Redirect stuff

    So I wanna create redirects after a form is complete.

    Here is how it goes, I have the information page and "edit new info" link, which links to the form to edit new info. And... i have another link on the Control panel page which also links to the form to edit info. I want it so if i submit a form i can go back to w/e page I originated from.

    info page -> Form -> info page
    CP page -> Form -> CP page

    So what i created is this a link

    Example:

    Code:
    <a href="www.domain.com/cp/form.php?category=apple&id=1&redirect=www.domain.com/cp/?category=apple&id=1">Edit category</a>
    Obviously you see the prob the redirect $_GET stops after apple cause of the '&'

    Any solutions?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Encode the string before passing it through the url: http://php.ca/manual/en/function.urlencode.php
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Thanks but why doesn't this work?

    PHP Code:
    $link '/anime/?id='.$data_entry['entry_id'].'&type=anime';
    $link urlencode($link); 

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    Quote Originally Posted by Dat View Post
    Thanks but why doesn't this work?

    PHP Code:
    $link '/anime/?id='.$data_entry['entry_id'].'&type=anime';
    $link urlencode($link); 
    Because it should be
    PHP Code:
    $link '/anime/?id=' urlencode($data_entry['entry_id']) . '&type=anime'
    You should urlencode only values in the query string, not the whole URL.

  • #5
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SKDevelopment View Post
    Because it should be
    PHP Code:
    $link '/anime/?id=' urlencode($data_entry['entry_id']) . '&type=anime'
    You should urlencode only values in the query string, not the whole URL.
    but im trying to encode that url: '/anime/?id='.$data_entry['entry_id'].'&type=anime'

    /anime/?id=6&type=anime if it gives you a better understanding.

    So... i want the link to be like <a href="www.domain.com/cp/edit.php?id=6&type=anime&rd=%2Fanime%2F%3Fid%3D6%26type%3Danime ">Edit this</a>

  • #6
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Okay so i tested the urlencode() function by copying a test from google.

    PHP Code:
    <?php 

    $s 
    "This is a test string"

    $url "urlencode.php?data=" urlencode($s); 
    print 
    "<a href=\"$url\">Click me</a><br>"
    if (isset(
    $_REQUEST["data"])) { 
       print 
    "URL: " $_SERVER['REQUEST_URI'] . "<br>"
       print 
    "Decoded data: " urldecode($_REQUEST["data"]); 


    ?>
    It doesn't work wtf?

  • #7
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    That code works exactly as expected for me.

    Output:
    Code:
    URL: /urlencode.php?data=This+is+a+test+string
    Decoded data: This is a test string
    John

  • #8
    Dat
    Dat is offline
    Regular Coder
    Join Date
    Oct 2007
    Posts
    147
    Thanks
    28
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PappaJohn View Post
    That code works exactly as expected for me.

    Output:
    Code:
    URL: /urlencode.php?data=This+is+a+test+string
    Decoded data: This is a test string
    It works now >.< Bangs on table.


  •  

    Posting Permissions

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