Results 1 to 8 of 8

Thread: redirect url

  1. #1
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default redirect url

    Hi,
    I've set up a simple script to redirect to a page depending on what the &url= parameter is...

    PHP Code:
    <?php
    $goto 
    $_GET['goto'];
    ?>
    <html>
    <head>
    <title>Mobile Phone Deals</title>
    <meta http-equiv="Content-Language" content="en-gb">
    <meta http-equiv="refresh" content="40;url=<?php echo ("$goto")?>">
    </head>
    <body>
    </body>
    <html>
    the problem being, if the URL i am redirecting to, has a " & " in it, it doesnt work... (i'm using affiliate links, so sum URL could have more than one " & " in the URL...

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php echo(htmlentities($goto)); ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    tha doesnt work Twey..
    it just ignores anything after a question mark ? or a and sign &

    the other problem is that there are more parametres that will be called..

    e.g. /goto.php?1=this&2=that&goto=http://www.google.co.uk/search?hl=en&q=php&meta=

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hm. The question mark should be fine, but the ampersand would usually cause trouble: they're meant to be escaped as &amp;. Can you show me the output of your script?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    yeah, was just gunna edit to say that theres no problem with the question mark...
    if goto is this url:
    http://www.google.co.uk/search?hl=en&q=php&meta=

    i get this...
    HTML Code:
    <html> 
    <head> 
    <title>Redirect</title> 
    <meta http-equiv="Content-Language" content="en-gb"> 
    <meta http-equiv="refresh" content="4;url=http://www.google.co.uk/search?hl=en"> 
    </head> 
    <body> 
    </body> 
    <html>

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Aaaaaah. Of course you do. You need to escape the ampersands as %26 when you first feed them into the script.
    redir.php?goto=http%3A%2F%2Fwww%2Egoogle%2Eco%2Euk%2Fsearch%3Fhl%3Den%26q%3Dphp%26meta%3D
    If you call the urlencode() function on the string in PHP, it'll perform this replacement for you.
    I suggest you use an HTTP redirect rather than a meta refresh, though.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2005
    Posts
    174
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thought i would of had to do that...

    could you give me an example of a HTTP redirect script/code?!?

    Cheers.

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <?php header("Location: http://www.google.co.uk/search?hl=en&q=php&meta="); ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

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