Page 1 of 1

[solved] url question mark problem

Posted: Tue Dec 08, 2009 12:42 pm
by nazg
Hi, I am using a proxy which takes a url in a url variable and gets the site content. It works, although there are some kinks to be worked out with using the proxy. However, when I ask the proxy to go to a page whose url contains a question mark it instead goes to the page whose url is only up to the question mark of the url I want.
i.e.
I request the page whose url is http://somedomain.php?var1=stuff&var2=morestuff
by linking to http://mydomain/myproxy.php?http://some ... =morestuff
It instead gets the page http://mydomain/myproxy.php?http://somedomain.php

myproxy.php contains the following:

Code: Select all

<html>
 
<?php
$daurl = $_GET['url'];
echo '<head><base href='.$daurl.'></head><Body>';
 
// Set your return content type 
//header(Content-type: application/xml);
 
// Website url to open
 
// Get that website is content
$handle = fopen($daurl, "r");
 
// If there is something, read and return
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>
 
</body>
</html>
Thanks

Re: url question mark problem

Posted: Tue Dec 08, 2009 1:06 pm
by AbraCadaver
Wherever you have a link use:

Code: Select all

$link = '<a href="http://mydomain/myproxy.php?url=' . urlencode('http://somedomain.php?var1=stuff&var2=morestuff') . '">Link</a>';
Then in the code you posted:

Code: Select all

$daurl = urldecode($_GET['url']);

Re: url question mark problem

Posted: Tue Dec 08, 2009 1:12 pm
by incubi
Seems to work for me when I define the url using newegg.com
If you echo out the head tag it messes will the page display.

Code: Select all

 
<?php
 //$daurl = $_GET['url'];
 $daurl = 'http://www.newegg.com/Store/Computer.aspx?name=Computer-Hardware';
 
// echo '<head><base href='.$daurl.'></head><Body>';
  
 // Set your return content type
 //header(Content-type: application/xml);
  
 // Website url to open
  
 // Get that website is content
 $handle = fopen($daurl, "r");
  
 // If there is something, read and return
 if ($handle) {
     while (!feof($handle)) {
         $buffer = fgets($handle, 4096);
         echo $buffer;
     }
     fclose($handle);
 }
 
?>
 

Re: url question mark problem

Posted: Tue Dec 08, 2009 1:16 pm
by AbraCadaver
incubi wrote:Seems to work for me when I define the url using newegg.com
If you echo out the head tag it messes will the page display.

Code: Select all

 
<?php
 //$daurl = $_GET['url'];
 $daurl = 'http://www.newegg.com/Store/Computer.aspx?name=Computer-Hardware';
 
// echo '<head><base href='.$daurl.'></head><Body>';
  
 // Set your return content type
 //header(Content-type: application/xml);
  
 // Website url to open
  
 // Get that website is content
 $handle = fopen($daurl, "r");
  
 // If there is something, read and return
 if ($handle) {
     while (!feof($handle)) {
         $buffer = fgets($handle, 4096);
         echo $buffer;
     }
     fclose($handle);
 }
 
?>
 
That's because you're not trying to pass it in using $_GET like the OP, so of course it works.

Re: url question mark problem

Posted: Tue Dec 08, 2009 1:37 pm
by nazg
To AbraCadaver:
Thanks for responding. However, the links themselves are in a .html file. I guess I could a .php file and do what you suggested. Could you think of anyway to fix the following:

(In html tag)

Code: Select all

onClick = "goTo('http://somedomain/');"
javascript function:

Code: Select all

fr = 0;
proxyAddress = "http://mydomain/myproxy.php";
frameWidthOffset = -46;
 
function goTo(url){
  fr = document.getElementById("fr");
  fr.src = proxyAddress + "?url=" + url;
  resizeFrame();
}

Re: url question mark problem

Posted: Tue Dec 08, 2009 1:46 pm
by AbraCadaver
You might try:

Code: Select all

fr.src = proxyAddress + "?url=" + escape(url);

Re: url question mark problem

Posted: Tue Dec 08, 2009 1:50 pm
by nazg
Excellent thanks to AbraCadaver I found the solution. I simply went to http://www.albionresearch.com/misc/urlencode.php and encoded my url (which I put in my html link). The funny thing is that I did not decode the url in the php proxy and it somehow worked?! Thank to all for responding.

Oh, and one more thing, the javascript escape solution works as well.

Re: url question mark problem

Posted: Tue Dec 08, 2009 1:59 pm
by AbraCadaver
nazg wrote:Excellent thanks to AbraCadaver I found the solution. I simply went to http://www.albionresearch.com/misc/urlencode.php and encoded my url (which I put in my html link). The funny thing is that I did not decode the url in the php proxy and it somehow worked?! Thank to all for responding.

Oh, and one more thing, the javascript escape solution works as well.
Yeah, I forgot that $_GET variables are automatically decoded.