Login to TechLifeForum X
Board Index Go to Reboot.Pro
  • Account Login
  • Register
TechLifeForum
  • Home
  • Members
  • Awards
  • Rules
  • Help
  • Donate
  • Live IRC
TechLifeForum / Programming and Development / Web Development & Web Graphics v
« Previous 1 ... 3 4 5 6 7 ... 10 Next »
/ [PHP] Help Reading Data[Advanced Search]
Reply to thread
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

[PHP] Help Reading Data

06-28-2012, 04:21 PM (This post was last modified: 06-28-2012 04:23 PM by BreShiE.)
Post: #1
BreShiE Offline
Knowledge Is Power
*****
Posts: 1,122
Joined: Sep 2011
Reputation: 12
Donation AwardCoding Award
[PHP] Help Reading Data
Okay, well I'm trying to grab the response of a website, and tell the document that if it returns "404" then to echo online, and if not to echo offline. The code I've got works, but I can put if it equals to anything, it'll still say "online". I want it to echo "Offline" if it doesn't return the string "404".

Here's my code:
PHP Code: (SELECT ALL CODE)
<?PHP
        $url 
= "http://fyibooter.net/api.php";
        
$ch = curl_init();
        
$timeout = 5;
        
curl_setopt($ch, CURLOPT_URL, $url);
        
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        
$data = curl_exec($ch);
        
curl_close($ch);

        if(
$data = "404"){ // You can change the text inside the quotation marks to anything, and it'll still return "Online"
            
echo 'online';
        }else{
        echo 
'offline';
        }
?>

Any help's appreciated.



"It was pretty impressive to watch a missile fly down an air vent, but couldn't we feasibly use that same technology to shoot food at hungry people?"
WWW Find
Reply
06-28-2012, 04:25 PM
Post: #2
KoBE Offline
¯\_(ツ)_/¯
*******
Administrators
Posts: 4,197
Joined: Jun 2011
Reputation: 47
RE: [PHP] Help Reading Data
Unfortunately I'm not to familiar with curl. I will try to find some time to look at this when I'm off work.

-> TechLifeForum on Facebook<- 
-> TechLifeForum on YouTube<-
-> TechLifeForum on Twitter<-

Tech.Reboot.Pro
WWW Find
Reply
06-28-2012, 04:43 PM
Post: #3
BreShiE Offline
Knowledge Is Power
*****
Posts: 1,122
Joined: Sep 2011
Reputation: 12
Donation AwardCoding Award
RE: [PHP] Help Reading Data
It doesn't have to be cURL, I just though that'd be the easiest way to do it.



"It was pretty impressive to watch a missile fly down an air vent, but couldn't we feasibly use that same technology to shoot food at hungry people?"
WWW Find
Reply
06-28-2012, 08:56 PM
Post: #4
AceInfinity Offline
∞ IҊϜIɴITϵ ☭
*****
Microsoft MVP
Posts: 8,693
Joined: Jun 2011
Reputation: 61
RE: [PHP] Help Reading Data
Never used curl other than in the command line from a curl binary, but it is definitely a good tool.



Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


Development Site: aceinfinity.net
WWW Find
Reply
06-28-2012, 09:47 PM
Post: #5
BreShiE Offline
Knowledge Is Power
*****
Posts: 1,122
Joined: Sep 2011
Reputation: 12
Donation AwardCoding Award
RE: [PHP] Help Reading Data
So you guys have nothing to offer me? D:

I don't have to use CURL...



"It was pretty impressive to watch a missile fly down an air vent, but couldn't we feasibly use that same technology to shoot food at hungry people?"
WWW Find
Reply
06-29-2012, 06:22 AM (This post was last modified: 06-29-2012 06:23 AM by Florin.)
Post: #6
Florin Offline
Junior Member
Team Reboot
Posts: 340
Joined: Dec 2011
Reputation: 11
Forum SupporterSpam ProtectionVisual Basic School Graduate
RE: [PHP] Help Reading Data
I don't know quite good php, but shouldn't be like this:

PHP Code: (SELECT ALL CODE)
$data == "404" 

??

Thanks!
Find
Reply
06-29-2012, 07:33 AM
Post: #7
BreShiE Offline
Knowledge Is Power
*****
Posts: 1,122
Joined: Sep 2011
Reputation: 12
Donation AwardCoding Award
RE: [PHP] Help Reading Data
(06-29-2012 06:22 AM)florin Wrote:  I don't know quite good php, but shouldn't be like this:

PHP Code: (SELECT ALL CODE)
$data == "404" 

??

Thanks!

You know what's hilarious? That actually fixed it, haha! Thanks.



"It was pretty impressive to watch a missile fly down an air vent, but couldn't we feasibly use that same technology to shoot food at hungry people?"
WWW Find
Reply
06-29-2012, 10:10 AM
Post: #8
KoBE Offline
¯\_(ツ)_/¯
*******
Administrators
Posts: 4,197
Joined: Jun 2011
Reputation: 47
RE: [PHP] Help Reading Data
Ha! Florin.you're.awesome.

Man. I was overshadowed by my 'unknowing' of curl, that I completely overlooked that. I should have seen that.

Good thing you got it working.

-> TechLifeForum on Facebook<- 
-> TechLifeForum on YouTube<-
-> TechLifeForum on Twitter<-

Tech.Reboot.Pro
WWW Find
Reply
06-29-2012, 07:45 PM
Post: #9
AceInfinity Offline
∞ IҊϜIɴITϵ ☭
*****
Microsoft MVP
Posts: 8,693
Joined: Jun 2011
Reputation: 61
RE: [PHP] Help Reading Data
Ahh, see I was in KoBE's same boat here, but to be honest I didn't even actually look at the PHP script you had because of the lack of time I had that day. I'm off in another 30mins/1hour to do something today, but then i'm good for time on the weekend. Unless something else comes up.

= is an assignment operator
== is used for comparison



Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer


Development Site: aceinfinity.net
WWW Find
Reply
Reply to thread


  • View a Printable Version
  • Send this Thread to a Friend
  • Subscribe to this thread
Forum Jump:


Users browsing this thread
1 Guest(s)
Youtube Facebook Twitter Digg
Return to Top
All content © copyright TechLifeForum
Powered By MyBB, © 2002-2013 MyBB Group
Designed by ThemeFreak
Mobile Version