Is this wrong in PHP?

PHP:
<?php

$p = $_GET['p'];
$filename="http://www.abc.com/bcd?cde=".$p;
$fp = fopen($filename,"r") or die("cant open file");
$data = fread($fp,4096);

echo $data;
?>

Is this the right way to do things? Of course, there is some manipulations to be done before $data is echoed back. It's working fine in my place and my friend's place. But in college it says "cant open file". Its not a firewall problem as the URL works fine if I enter it in the address bar of the browser. Any help appreciated.
 
When you say "working at home" and "working at friends place" and "not working in college" are these all client side changes? Meaning, is the code still running on the same server for all three places?

See the PHP docs for fopen at PHP: fopen - Manual

Try including "t" for text or "b" for binary, and check for "safe mode" as mentioned in the link...
 
PHP: fopen - Manual

Note: When safe mode is enabled, PHP checks whether the directory in which the script is operating has the same UID (owner) as the script that is being executed.

If you are experiencing problems with reading and writing to files and you're using the server module version of PHP, remember to make sure that the files and directories you're using are accessible to the server process.

Also is your PHP installation allowed to access external url data?
 
vishalrao said:
When you say "working at home" and "working at friends place" and "not working in college" are these all client side changes? Meaning, is the code still running on the same server for all three places?

Not the same server, we're running it on standalone systems, meaning (http://localhost)...

Gurpartap Singh said:
PHP: fopen - Manual

Also is your PHP installation allowed to access external url data?

where do I check that?

EDIT: checked my php.ini, allow_url_fopen=on and safe_mode=off

What's baffling me is, it's working on my friend's laptop, but it won't work when its connected to the net at college. :( anyway will check the php.ini on his laptop and also the desktop at college.
 
are u trying to open a file on the internet?? are there any proxy settings required to open the url at ur college?? i guess tht might be the issue in trying fopen without proxy settings..u need to set the proxy in ur code in that case..
 
Back
Top