Problem using http:// in GET variable..

Discussion in 'PHP' started by Methok, Jun 9, 2010.

  1. #1
    Hi all,

    Having a problem using http:// in a get variable. Obviously what its doing is splitting the variable as though i want to go to a new folder.

    I was wondering if anyone knew a way around this?

    sample code:
    
    
    <?php
    	$get_url = $_GET['l'];
    	
    	if(isset($get_url))
    		echo $get_url;
    	else
    		echo 'No url posted';
    		
    ?>
    
    
    PHP:
    My error:
    
    
    You don't have permission to access / on this server.
    
    
    PHP:

    Thanks for any advice you offer.
     
    Methok, Jun 9, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Are you trying to get the full url http:// domain.com or some part of the url http:// domain.com/l=something?
     
    MyVodaFone, Jun 9, 2010 IP
  3. Methok

    Methok Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Methok, Jun 9, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Try urlencode();

    
    <?php
        $get_url = urlencode($_GET['l']); // I'm not sure if thats the right format
       
        if(isset($get_url))
            echo $get_url;
        else
            echo 'No url posted';
           
    ?>
    
    PHP:
    EDIT: I just tried that and it seems to work, but you you might want to urldecode($get_url); your echo like this:
    
    <?php
    
        $get_url = urlencode($_GET['l']);
       
        if(isset($get_url))
            echo urldecode($get_url);
        else
            echo 'No url posted';
           
    ?>
    
    PHP:
     
    Last edited: Jun 9, 2010
    MyVodaFone, Jun 9, 2010 IP
  5. Methok

    Methok Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Doesn't work. I'm afraid.

    Still gives same error because the problem is its not letting me access the script. Its splitting the URL in to different folders. So its looking for a folder that does not exist.
     
    Methok, Jun 9, 2010 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    I'm lost sorry, I have no idea what your trying to do... my above answer works fine based on your first and second post.
     
    MyVodaFone, Jun 9, 2010 IP
  7. silviuks

    silviuks Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    try a print_r($_GET) to see what happens.
     
    silviuks, Jun 9, 2010 IP
  8. Methok

    Methok Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hiya,

    Sorry for the delay in responding, I had a visitor.

    Anyway, the problem is. When you type this url 'http://api.slworkz.com/?l=http://www.test.com in to your browser it will take you you to api.slworkz.com/?l=hhtp: and then it wont go any further as it think the next / is giving a new folder.

    Sorry if I am not describing this properly.
     
    Methok, Jun 9, 2010 IP
  9. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #9
    try using $_SERVER['QUERY_STRING'] to capture the GET
    Also you can try parse_url() function to receive the url and get parameters
     
    olddocks, Jun 9, 2010 IP
  10. Methok

    Methok Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Ok, I'll try that soon. need to get kids from school.

    Thanks all for your help. I'll post again soon.
     
    Methok, Jun 9, 2010 IP
  11. Methok

    Methok Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I still have exactly the same error.

    I get no errors if I type in to the address bar

    api.slworkz.com/?l=www.test.com
    PHP:
    its only when I use http:// like here

    api.slworkz.com/?l=http://www.test.com
    PHP:
    api.slworkz.com is the subdomain of slworkz.com.

    Talk about driving me mental. lol.

    No point me adding anything to the script because its not actually reading the script.

    Thanks for your help guys
     
    Last edited: Jun 9, 2010
    Methok, Jun 9, 2010 IP
  12. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #12
    If you are typing the URL in browser directly, You can try removing the http:// part and when you have $l stored in the variable, just add it there. Like:
    go to:
    http://api.slworkz.com/?l=www.test.com/test.php

    In that script:
    $l= 'http://'. $_GET['l'];

    That will work.

    however, if you are creating a link like:
    <a href="http://api.slworkz.com/?l=http://www.test.com/test.php"> link </a>

    then it'd be better to do it like this:
    <a href="http://api.slworkz.com/?l=<?php echo urlencode('http://www.test.com/test.php'); ?>"> link </a>

    That should work.
    Thanks :)
     
    JEET, Jun 9, 2010 IP
  13. Methok

    Methok Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Ok, If use a single letter as the GET tag as previously stated it throws the error.

    But if I use 'url' as the tag then the below code will work.

    <?php 
    	$get_url = $_GET['url'];
    	
    	if(isset($get_url))
    		echo $get_url;
    	else
    		echo 'No input';
    ?>
    PHP:

    ?url=http://test.com is as good for me as ?l=http://test.com

    Thanks all for your help. Appreciated.
     
    Methok, Jun 9, 2010 IP
  14. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #14
    Seems you got solved
    If you still in trouble just Post i will help you :)
     
    roopajyothi, Jun 9, 2010 IP