Require function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Require function

Post by Skywalker »

If have a page that is called test.php and in that page ther is an variable called $Test.


Then an other page called uitvoer.php and in when I insert the command require(test.php), can I then use the variable $Test in the page uitvoer.php?

Greathings Skywalker
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Why don't you create a couple of test pages to work out the result:

page1.php

Code: Select all

<?php
$test = 'Testing 123';
?>
page2.php

Code: Select all

<?php
include 'page1.php';
if (isset($test)) {
    echo $test;
} else {
    echo '$test doesn''t exist';
}
?>
Also have a read of the documentation:
http://www.php.net/manual/en/function.require.php
http://www.php.net/manual/en/function.include.php

Mac
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post by Skywalker »

I am having a ping script here and I want show the result of the pings on a other page if the are offline else show that ther is nothing offline.

Is this the right way to do it? Or not?

Code: Select all

//page1.php

<?php 

    $ip='www.test.nl';  

    $port=80; 

    $fp = fsockopen ($ip, $port, $errno, $errstr, 30); 

        if (!$fp) { 

            echo "<font color="#FF0000">img src="warning.gif"><b>System offline";

$Offline1 = "http server is ofline";

Down</b><p>Error $errno: $errstr"; 

        } else { 

            echo "<font color="#0000c0"><img src="online.gif"><b>All

systems are stable and running.</b>"; 

        }

?>		




//page2.php

<?php 
	require(page1.php)
	
	if (isset($Offline1)) {
	    echo $Offline1;
	} else {
	    echo "Alle servers zijn online"; }
		  

	if (isset($Offline2)) {
	      echo $Offline2;
	} else {
	     echo "Alle server zijn online"; }
	?>
Last edited by Skywalker on Tue Nov 12, 2002 5:52 am, edited 4 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Could you please edit your post to put your PHP code inbetween [syntax=php]...[/syntax] tags - it makes it a lot easier to read.

Mac
Post Reply