Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-30-2007, 09:20 PM   #1 (permalink)
pungi
Recruit
 
Join Date: Feb 2006
Posts: 17
pungi is on a distinguished road
open a url? fopen?

Hi,
I am trying to run a php script that opens a url but all I seem to get is a blank page:

<?php
$handle = fopen("http://www.google.com/", "r");
?>

fopen seems to suit my purpose best, as redirecting the headers means i will have to re-structure the code.

Thanks in advance and im sorry if it turns out to be something stupid,
Pungi
pungi is offline   Reply With Quote
Old 03-31-2007, 03:58 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 745
DJMaze is on a distinguished road
echo fopen("http://www.google.com/", "r");

header('Location: http://www.google.com/');
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-31-2007, 06:02 AM   #3 (permalink)
pungi
Recruit
 
Join Date: Feb 2006
Posts: 17
pungi is on a distinguished road
Hi,
the code you suggested did not work for me, i recieved this error:
Resource id #4
I could use the headers but id rather use the fopen if possible as it could save me alot of bother.
Thanks again,
Pungi
pungi is offline   Reply With Quote
Old 03-31-2007, 06:44 AM   #4 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 745
DJMaze is on a distinguished road
the "echo fopen()" was on purpose.

Now i know you are a complete newbie to PHP which you didn't tell us yet.
fopen() will fail on many webservers but alright here goes.

PHP Code:
if ($fp fopen('http://www.google.com/''r'))
{
    
fpassthru($fp);
    
fclose($fp);

TIP: Learn about single quoting, it will free CPU usage.

NOTE: you probably can't use google search this way, and if that happens don't ask in here "it doesn't work". Just use header() and fix your code then.
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 03-31-2007, 09:17 AM   #5 (permalink)
pungi
Recruit
 
Join Date: Feb 2006
Posts: 17
pungi is on a distinguished road
Hi,
I think i will have to use headers as fopen does not work, unless anyone can suggest an alternative method?
Thanks for the help,
Pungi
pungi is offline   Reply With Quote
Old 03-31-2007, 10:20 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,532
sde is on a distinguished road
you could try using fopen with fread()

it's possible your problem with getting fopen to work is in the php.ini settings. search your php.ini file for allow_url_fopen and make sure it's on.

which version of PHP are you using? PHP5 offers file_get_contents()

another alternative method would be fsockopen()
__________________
Mike
sde is offline   Reply With Quote
Old 03-31-2007, 01:29 PM   #7 (permalink)
pungi
Recruit
 
Join Date: Feb 2006
Posts: 17
pungi is on a distinguished road
Hi,
I think i will still use headers as the alternatives seem harder to understand.
I was hoping that fopen would be a shortcut to debugging errors i got when using the headers option but i noticed the address bar doesnt change to the url so ill have to use headers.
Thanks for all the help,
Pungi
pungi is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
REferrencing URL from DB joehouse MS Technologies ( ASP, VB, C#, .NET ) 0 08-02-2005 03:20 PM
URL query j.gohel Java 17 04-15-2005 11:22 AM
IBM urges Sun to make Java open source redhead Code Newbie News 0 03-01-2004 11:39 PM
Open Source by Osmosis revolution Code Newbie News 0 08-10-2003 06:36 PM


All times are GMT -8. The time now is 08:31 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting