[solved] url question mark problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nazg
Forum Newbie
Posts: 12
Joined: Thu Dec 03, 2009 11:52 am

[solved] url question mark problem

Post 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
Last edited by nazg on Thu Apr 29, 2010 10:56 am, edited 1 time in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: url question mark problem

Post 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']);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
incubi
Forum Contributor
Posts: 119
Joined: Mon Dec 07, 2009 1:47 pm

Re: url question mark problem

Post 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);
 }
 
?>
 
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: url question mark problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
nazg
Forum Newbie
Posts: 12
Joined: Thu Dec 03, 2009 11:52 am

Re: url question mark problem

Post 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();
}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: url question mark problem

Post by AbraCadaver »

You might try:

Code: Select all

fr.src = proxyAddress + "?url=" + escape(url);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
nazg
Forum Newbie
Posts: 12
Joined: Thu Dec 03, 2009 11:52 am

Re: url question mark problem

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: url question mark problem

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply