Reply
file_get_contents not working for some reason
Old 10-24-2009, 03:38 PM file_get_contents not working for some reason
Physicsguy's Avatar
Extreme Talker

Posts: 191
Name: Physicsguy
Location: On Earth
Trades: 0
Hello all,

This is my code:

PHP Code:
$url "userreview.php?reviewID=1";
$str file_get_contents($url);
echo 
$str
Simple, right? That's supposed to get the contents of userreview.php with reviewID as 1. But this doesn't work. Just typing userreview.php works, but the ?reviewID=1 does not work.

How could I make it so that it works?

Thanks
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
 
When You Register, These Ads Go Away!
Old 10-24-2009, 03:40 PM Re: file_get_contents not working for some reason
NullPointer's Avatar
Will Code for Food

Latest Blog Post:
Easy PHP Search with Opera
Posts: 1,070
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$url 'http://domain.com/path/userreview.php?reviewID=1'
Try using the complete url
__________________
Tinsology | How to Post Code | EverythingDev

Last edited by NullPointer; 10-24-2009 at 03:41 PM..
NullPointer is online now
Reply With Quote
View Public Profile
 
Old 10-24-2009, 03:42 PM Re: file_get_contents not working for some reason
Physicsguy's Avatar
Extreme Talker

Posts: 191
Name: Physicsguy
Location: On Earth
Trades: 0
That still won't work, because it's local. Besides, you can put an <a href" like what I put and it works...
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-24-2009, 04:35 PM Re: file_get_contents not working for some reason
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
but the ?reviewID=1 does not work.
describe "does not work".
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-24-2009, 04:40 PM Re: file_get_contents not working for some reason
Physicsguy's Avatar
Extreme Talker

Posts: 191
Name: Physicsguy
Location: On Earth
Trades: 0
It doesn't work... Like, if I put just the userreview.php in the variable, then it would grab userreview.php, but I want it to grab only the reviewID of 1. It doesn't work, it's not functionable.

Like in YouTube, there's always youtube.com/?watch=v then random crap. They have it so that on the results page it shows the title of the video. That's exactly what I need. I need it to look at that page, find the title, and then echo it.

How, though?
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-24-2009, 05:46 PM Re: file_get_contents not working for some reason
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
So there is no errors, no message.
Just that the page doesn't do what it should do.
Is that right ?

In that case, the problem is in your userreview.php script, not in the part you pasted up there.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-24-2009, 09:57 PM Re: file_get_contents not working for some reason
Physicsguy's Avatar
Extreme Talker

Posts: 191
Name: Physicsguy
Location: On Earth
Trades: 0
Oh, I have an error that says:

Warning: file_get_contents(userreview.php?reviewID=8) [function.file-get-contents]: failed to open stream: No such file or directory in /home/pgreviews/web/userreview.php on line 95

Which pretty much says that userreview.php?reviewID=8 doesn't exist...?

Sorry I didn't post the error before, I can be really stupid sometimes :S
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-25-2009, 10:49 AM Re: file_get_contents not working for some reason
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
Which pretty much says that userreview.php?reviewID=8 doesn't exist...?
No, file_get_contents() can work with url, but as NullPointer told you, you need to use the full url to access an url.
By giving just what you given, the funxtion tries to find a file named "userreview.php?reviewID=8", which doesn't exists.

Your solution: give the full url, as pointed before.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 10-25-2009, 06:21 PM Re: file_get_contents not working for some reason
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,556
Name: Keith Marshall
Location: West Hartford, CT
Trades: 0
I think when there is no protocol and domain, it sees it as a local file path. (???)
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-25-2009, 07:59 PM Re: file_get_contents not working for some reason
Physicsguy's Avatar
Extreme Talker

Posts: 191
Name: Physicsguy
Location: On Earth
Trades: 0
Oh...

I think I was doing this whole thing wrong anyway... What I really need done is the script to grab everything between the <div id="reviewmaintitle"> and the first </div>. That's seriously all I need.
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-27-2009, 07:54 AM Re: file_get_contents not working for some reason
mtishetsky's Avatar
King Spam Talker

Posts: 1,166
Name: Mike
Location: Mataro, Spain
Trades: 0
It won't work for local domain if your server cannot resolve the domain name correctly (which it most like cannot because you did not setup DNS).

What is the reason of getting page contents from LOCAL domain with file_get_contents()? Can't you just read it from database or wherever else it is stored?
__________________
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 10-27-2009, 04:12 PM Re: file_get_contents not working for some reason
Physicsguy's Avatar
Extreme Talker

Posts: 191
Name: Physicsguy
Location: On Earth
Trades: 0
Yes, true. I could do that, but the trouble it, I need only part of it.

I had enough trouble getting it to display at all... Let alone getting part of it...

I would need to

Get the reviewID for it.
Get the contents of the div 'reviewmaintitle'.
Send it back to userreview.php
Echo it. Only the last 2 reviews (the new ones)!

It's tough. And I'm just getting into this.
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Old 10-27-2009, 04:22 PM Re: file_get_contents not working for some reason
NullPointer's Avatar
Will Code for Food

Latest Blog Post:
Easy PHP Search with Opera
Posts: 1,070
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Physicsguy View Post
I had enough trouble getting it to display at all...
Maybe you should rethink your approach in that case? What are you trying to display and what makes it so hard?
__________________
Tinsology | How to Post Code | EverythingDev
NullPointer is online now
Reply With Quote
View Public Profile
 
Old 10-27-2009, 04:24 PM Re: file_get_contents not working for some reason
Physicsguy's Avatar
Extreme Talker

Posts: 191
Name: Physicsguy
Location: On Earth
Trades: 0
I've gotten that working, I don't really need to explain it, I'm not gonna touch it, it works!
Physicsguy is offline
Reply With Quote
View Public Profile Visit Physicsguy's homepage!
 
Reply     « Reply to file_get_contents not working for some reason
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.17774 seconds with 13 queries