Add this php variable into curl

Hi everyone again :unamused:

i just like to know a simple easy something

that is how to add mysql php variable to this code

<?php echo $user["Website"]; ?>
                    ^
this into the below code 

<?php
$host = 'Goes here';
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
}
?>

I’m not sure what you’re asking here. For one, the title suggests you’re using curl, but there is no function call related to curl anywhere in the code you posted.

Moreover, there is no clear question. What do you want to achieve?

i wanted to add a variable in the code
but now i have done that now i am stupid :frowning:
also its using curl as you are getting the status off a site
if its online or offline but now i am getting a offline message
when the site is up so guess this code from stuckoverflow is not good

30%20am

<?php
$user ['Website'];
if($socket =@ fsockopen($list, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline';
}
?>

fsockopen only tells you if you can connect to the host the website is running on. It doesn’t tell you anything about the answer (if any) you would get back when you do an HTTP request.

I would suggest you read up on this topic and the different stages a connection goes through to get a website.

This line

$user ['Website'];

makes no sense, it’s just an array variable name, and without any kind of statement, it should be giving you an error message. In addition, you don’t do anything with it, or define it anywhere.

if($socket =@ fsockopen($list, 80, $errno, $errstr, 30)) {

Where does $list come from in this line? This parameter should contain the address of the site you are trying to open. Unless you have edited the code down to post on the forum and assign it a value in your real code, it has no idea what site to open.

Putting an @ symbol at the start of the line causes PHP to suppress any error messages. I would suggest that while you are debugging your code, you remove that symbol so you can see what is going wrong. There is code on this forum to show how to enable more comprehensive error reporting than default, I would suggest that’s a good idea to add for now, too.

CURL refers to a specific set of functions - it’s not a generic term used to describe opening a connection to a network server. Unless there is other code that you’ve left out of the post, you are not using CURL here, as rpkamp said above.

1 Like

Like i said i got the code from stackoverflow :angry:

so i have no idea how to sort it or what to remove from it
i only got little knowledge off php

also like people say Google before you ask things

Yep i done that

i am going to keep researching it

if i dont find any thing i just leave it

You could start off by looking through the documentation for each of the functions you are using on php.net - often the sample code on those sites will give you enough to get going. I don’t know what level of knowledge you have for programming in general or PHP in particular, so some general tuition sites might come in useful.

Also, as rpkamp said above, just because you can connect to the server that hosts the web site you are checking, doesn’t mean that the site itself is working. Once you have opened a socket, the next thing that the server might return is some kind of error message, so you may need to go into this more deeply. Note that, for various reasons, there could be many hundreds of individual sites hosted on the same physical server, all your code does it check that the server is responding to connections.