Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

open php file

Posted on 2004-03-21
9
Medium Priority
?
280 Views
Last Modified: 2008-03-06
hi,
i have recently made a script to check the whois records for a domain my user inputs.
i now want to make a page which will check if the domain has a whois record or not and so display whether the domain is available or not.
i want to do this by running the page whois.php which returns the whois record for the domain but i don't want to use include or require because they will just echo whatever whois.php returns.
i want to get the source of whois.php after the script has been run but not have it echoed.
is there a function to do this or do i need to find a way of opening "php.exe whois.php" and getting whatever that returns?
thanks in advance
mark
0
Comment
Question by:enasni_mark
  • 4
  • 3
9 Comments
 

Expert Comment

by:dneff68
ID: 10644392
Hello,

You can try using fopen() and pass the url rather than a filename.  You may however have some problems if you are passing parameters, you'll have to try.

I believe there is also a way to redirect the output buffer to a custom function.  You could then parse it and wipe out the buffer, or replace it.  I can't remember the functions to do this.  I'll find it and post unless somebody posts it before me.

-David
0
 

Author Comment

by:enasni_mark
ID: 10644516
i was thinking of using fopen() but i also need to use GET to state the domain name.
0
 

Accepted Solution

by:
dneff68 earned 500 total points
ID: 10644578
Here's how I did it.  You can disable the buffer output and redirect it to a function you write, then kill ther buffer.

In my case, I was trying to export a dynamically generated page to a static HTML page, also without outputting the contents back to the client.  I have a callback($buffer) function that handles what would normally be pumped back to the client, and my exportPage function that does a require on the file I'm interested in.  The ob_end_flush() returns things to normal.

function callback($buffer)
{
  // do whatever you want with the buffer contents
}

ob_start("callback");
exportPage($file);  // does a require on $file
ob_end_flush();

Hope this helps.

-David
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:enasni_mark
ID: 10644615
how does the ob_start() function work? why do you have "callback" in ob_start?
0
 

Expert Comment

by:dneff68
ID: 10644645
"callback" is the name of the function you'll write to parse the results of your 'include'.  You can call it whatever you like, so long as your function name matches.  The function you write (in this case, 'callback') take a parameter that wil hold the buffer contents.  You can then parse that $buffer variable to see if 'whois' contains what you're looking for.

To make sure this doesn't get back to the client, you can also call ob_clean() when you're finished parsing.  Be sure that you don't already have content going back to the client that you don't want wiped out (such as echo's, or content outside <? ?>).

-David
0
 

Author Comment

by:enasni_mark
ID: 10644658
that seems to be what i need but how can i use an include or a require with get fields?
i've just tried but i don't think you can send get fields with require or include
0
 

Expert Comment

by:dneff68
ID: 10645266
Ooo... that may be where my needs differed.  I was hitting a local PHP page and could just have global variables. The PHP documentation for 'include' does state that pamameters can be passed, but that you must make sure allow_url_fopen is set on.

I'll try this a bit more when I get the chance.  Take a look at the online php docs for include.

-David
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question