I have a C program and i need to connect to a computer (i have its IP) and read a php file... any suggestions on how can i do that?
I have a C program and i need to connect to a computer (i have its IP) and read a php file... any suggestions on how can i do that?
Last edited by ltcabral; 03-18-2008 at 09:52 AM.
Can you describe in a "bigger picture" what you want to do? There are probably several things that you could do, but it would help to understand more of what you are actually trying to do, so we can get the right solution.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Your request is vague and leaves a lot to the imagination.
Your C program (running on your computer, a client) needs to connect to some Server, and then what needs to happen? You want the server to read a file? You want that file downloaded to your client program? You want to pretend that file is local to your machine and read it as a local stream?
Please clarify.
Mainframe assembler programmer by trade. C coder when I can.
Well the computer you're connecting to is going to have to be running a server of some sort. Also, your going to need the port that the server is listening on. I would read up on socket programming and that should get your going.
-Dustin
www.theCprogrammer.com
let me explain better...
i have a c program and a configuration file with the server IP (and port if needed) and i need my program to connect to that computer, open and read a php file like:
and get the info inside it to use in the C program... in the example i need the xxxx part so if i can read the file i can get these...Code:<? $db_name = "xxxx"; $db_ip = "xxx.xxx.x.xxx"; $db_port = "xxxx"; $db_user = "xxxx"; $db_passwd = "xxxx"; ?>
what i want to know is a way to connect to the server from the C program and go to file's path to read it... i suppose i can read the file with fopen / fread right?
To read files from another machine, you need some sort of file transfer service on the remote machine.
If you have free access to the server, then you should set up an SSH server, and use a SSH client (specifically "scp") on the local machine to copy the file across. Then it's a matter of reading/writing the file format. Which is
If you haven't got free access to the server, you are either breaking the forum rules (cracking - not allowed to help you there), or you need to ask the owner of the server what services they supply when it comes to fetching/updating files, e.g. ftp or ssh for example.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
i have free access to the server... i must connect to this computer to read the info (usr, passwd, database etc) to use this info in my C program to connect to a mysql server automaticaly, but this info i need to read is in this specific computer and and i gota connect and read it automaticaly too...
There are three parts to this problem.
1. Connecting to the server
2. Preventing the server from interpretting the PHP file
3. Parsing the PHP file.
#1 can be accomplished with wininet or libcurl, depending on your platform. #3 is a dirty parsing problem. And #2 might actually be impossible.
If this is a PHP file running on a web server, there is no way to cause the server to send you the actual text of the PHP file. It's going to interpret it as a PHP script and send you the output.
i heard something about get n post methos... could that help me?
read about libCurl if you need to connect to that PHP script..
Assuming you attempt to access it via the web-server, you mean.
I have several times used SCP to copy a PHP file to/from a server. FTP also works, but is less secure.
Writing a small script-file to first copy the PHP file, then process it and copy it back is trivial, e.g.:
The above assumes that you have unix-like shell - if you are using Windows-based system, then the script would be slightly different, but only the first line would be noticeably different, really. [You may also use "pscp" instead of "scp", if you use "putty" as your SCP client - but that's minor detail].Code:#!/bin/sh scp server:/somedir/dbdefs.php dbdefs.php processfile dbdefs.php scp dbdefs.php server:/somedir/dbdefs.php
If you have free access, you should be able to set things up so that you don't have to type passwords when copying too.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
thx for the advices... ill take a look in these suggestions