php experts - simple php question?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • roly
    Confirmed User
    • Aug 2002
    • 1844

    #1

    php experts - simple php question?

    hi

    i'm trying to make a very simple jump script for a particular reason and it works to a point but seems to give me an error.

    i've got a redirect script link.php which contains the following:

    Code:
    <?php 
    $url = ($_GET['lnk']);
    header("Location: $url");
    exit;
    ?>
    and i'm linking to a url like this:
    Code:
    http://www.somesite.com/?some-query-string!&id=27
    and so i'm linking to my script like this:

    Code:
    http://mydomain.com/link.php?lnk=http://www.somesite.com/?some-query-string!&id=27
    but it seems to be cutting off the string from the ampersand and sending it to:

    Code:
    http://www.somesite.com/?some-query-string!
    and not to:

    Code:
    http://www.somesite.com/?some-query-string!&id=27
    i know it's something stupid i'm doing wrong anyone got any ideas, it would be really appreciated

    thanks in advance
  • Angelo22
    Writer
    • Feb 2007
    • 3123

    #2
    id suggest setting a variable for each of the sites you 'lnk', then just link it to the variable.... might work that way
    MAKE MORE MONEY FROM YOUR WEB TRAFFIC - 15% BONUS

    And contact me if you need high quality translating and writing work done - angelo22 (AT) gmail (DOT) com

    Comment

    • psili
      Confirmed User
      • Apr 2003
      • 5526

      #3
      try to urlencode(lnk) .. Query strings don't seem to dig two ? marks.
      Your post count means nothing.

      Comment

      • Briscoe
        Confirmed User
        • Mar 2003
        • 153

        #4
        Originally posted by psili
        try to urlencode(lnk) .. Query strings don't seem to dig two ? marks.
        You are correct sir.
        Earn up to 70% per sale and 15% on webmaster referrals
        Signup for Horny Teen Cum Sluts
        A CCBill and NoCreditCard partner

        Comment

        • J.P.
          Confirmed User
          • Jun 2004
          • 689

          #5
          Yep, the urlencode() will solve your problem...
          Webmasters! Looking for new affiliate programs to promote?
          Affiliate Program Search <-- Search for programs with FHGs, RSS feed, specific niche sponsors, ...

          Comment

          • roly
            Confirmed User
            • Aug 2002
            • 1844

            #6
            thanks guys for the responses. i've tried urlencode like this:

            Code:
            <?php 
            
            $url = urlencode($_GET['lnk']);
            
            header("Location: $url");
            
            exit;
            
            ?>
            unfortunatly it now shows a 404 on my server with the url encoded but it isn't a 404 if i just use the unencoded string, am i using urlencode correctly in the above example?

            Comment

            • roly
              Confirmed User
              • Aug 2002
              • 1844

              #7
              for anyone that's interested, i couldn't get it to work with urlencode, but this worked:

              Code:
              <?php
              
              $url=substr($_SERVER['QUERY_STRING'],4);
              header("Location: $url");
              
              ?>
              thanks again

              Comment

              • Ferrishyn
                Registered User
                • Nov 2005
                • 28

                #8
                That'll work but you really should encode the ampersand in your address (you can use urlencode or replace &'s with %26). The reason its chopping off the end of it is the ampersand is splitting it into another GET variable:

                $_GET['lnk'] and $_GET['id']

                Comment

                • roly
                  Confirmed User
                  • Aug 2002
                  • 1844

                  #9
                  Originally posted by Ferrishyn
                  That'll work but you really should encode the ampersand in your address (you can use urlencode or replace &'s with %26). The reason its chopping off the end of it is the ampersand is splitting it into another GET variable:

                  $_GET['lnk'] and $_GET['id']
                  ok thanks, i'll take a look another look at it.

                  Comment

                  • Nookster
                    Confirmed IT Professional
                    • Nov 2005
                    • 3744

                    #10
                    You really should sanatize your variables man. With the way it is there if I were a spammer I could use your script as my own redirect tool. And now that I think of it, using header like that to redirect complete url's is kinda dumb. Make a database hold the urls you want to use then call them by id. See sig for example.
                    Last edited by Nookster; 02-28-2007, 03:18 PM.
                    The Best Affiliate Software, Ever.

                    Comment

                    • roly
                      Confirmed User
                      • Aug 2002
                      • 1844

                      #11
                      Originally posted by Nookster
                      You really should sanatize your variables man. With the way it is there if I were a spammer I could use your script as my own redirect tool. And now that I think of it, using header like that to redirect complete url's is kinda dumb. Make a database hold the urls you want to use then call them by id. See sig for example.
                      hi, i'm not a programmer, i was just coming up with a simple solution to a problem i had. when you say sanatize the urls do you mean by using urlencode like the others were saying?

                      regarding using an id to call the url's, that's a good idea, but i'm using autoblogger to post to blogs and this relates to my sourcelinks on the blog posts, and i can't edit the autoblogger code. this was my only solution i could think of for the particular problem i had.

                      Comment

                      • Nookster
                        Confirmed IT Professional
                        • Nov 2005
                        • 3744

                        #12
                        Originally posted by roly
                        hi, i'm not a programmer, i was just coming up with a simple solution to a problem i had. when you say sanatize the urls do you mean by using urlencode like the others were saying?

                        regarding using an id to call the url's, that's a good idea, but i'm using autoblogger to post to blogs and this relates to my sourcelinks on the blog posts, and i can't edit the autoblogger code. this was my only solution i could think of for the particular problem i had.
                        Aye, sorry for not catching your reply sooner for one.
                        Two, it's a fairly ok solution to your problem, but you leave your script vulnerable because, like I stated above, anyone can use it to forward their own url's to wherever with your script.
                        Ok, so you're a newbie to PHP. Read up on mysql man. With php and mysql you can do literally anything you want with a dynamic website. Not everyone has the mental abilities to understand code, so you may be part of the little percentage of people who can understand how it works and how to use it to your advantage. Check out the tutorials at programmingtutorials.com on mysql and php. I've taught myself everything I know about programming in general so I know it's possible for others to teach themselves the same. If you're serious about it hit me up and I'll help you out.
                        The Best Affiliate Software, Ever.

                        Comment

                        • roly
                          Confirmed User
                          • Aug 2002
                          • 1844

                          #13
                          Originally posted by Nookster
                          Aye, sorry for not catching your reply sooner for one.
                          Two, it's a fairly ok solution to your problem, but you leave your script vulnerable because, like I stated above, anyone can use it to forward their own url's to wherever with your script.
                          Ok, so you're a newbie to PHP. Read up on mysql man. With php and mysql you can do literally anything you want with a dynamic website. Not everyone has the mental abilities to understand code, so you may be part of the little percentage of people who can understand how it works and how to use it to your advantage. Check out the tutorials at programmingtutorials.com on mysql and php. I've taught myself everything I know about programming in general so I know it's possible for others to teach themselves the same. If you're serious about it hit me up and I'll help you out.

                          hi nookster, thanks for the advice. yeah i see what you mean about other people being able to use the script to forward there own urls. i think i have a new solution now. thanks again.

                          Comment

                          Working...