Page 1 of 1

[SOLVED]Need help on script

Posted: Mon Dec 22, 2003 2:48 pm
by vigge89
I have this in a file called index.php:

Code: Select all

<?php

require("cfg.php"); //Include important stuff

if ( empty($_POST['password']) and empty($_SESSION['password']) ) { //DEFAULT

$_SESSION['pass'] = "login";

echo_header();

echo_login();

echo $footer;

} elseif ($_POST['password'] == $pass1word) { //PASSWORD MATCHES

$_SESSION['pass'] = "ok";

echo_header("<META HTTP-EQUIV="refresh" content="3;URL=notes.php"> ");
?>
it's more than that, but there are no errors after "echo_header();" & "echo_login();".

the "cfg.php"-file contains this:

Code: Select all

<?php

session_start(); //Start session

//Password
$pass1word = "test";

//Notes-file
$filename = "vigge89.txt";


//FOOTER
$footer = <<<EOF
</table>
</BODY>
</HTML>
EOF; //END of footer

function echo_header($head) { //Function echo_header

//HEADER
echo <<<EOF
<HTML>
<HEAD>
	<title>vigge89's notes</title>
	<link rel="stylesheet" href="notes.css">
	$head
</HEAD>
<BODY>

<table border="1" align="center" border="0" cellspacing="0">

<tr height="20">
	<td class="title">@  vigge89.txt - notepad</td>
</tr>
EOF; //END of header

} //Function echo_header


function echo_login() { //Function echo_login

echo <<<EOF
<tr>
	<td colspan="2">
	<form name="password" action="index.php" method="post">
	Password: 	<input type="password" name="password">
	</td>
</tr>

<tr>
	<td align="center" colspan="2"><input type="submit" value="[ login ]">
</tr>
EOF;

} //Function echo_login

?>

Now to the problem;
I get " Parse error: parse error, unexpected '}' in C:\xampp\htdocs\notes\cfg.php on line 56", and also "Fatal error: Call to undefined function: echo_header() in C:\xampp\htdocs\notes\index.php on line 9".

I've checked both files many times, but i can't find anything wrong, also, i don't know why i get "unexpected }" in cfg.php.

Anyone?

Posted: Mon Dec 22, 2003 2:55 pm
by Gen-ik
As far as I know you can't call functions from with a <<EOF (or similar). You need to break out of it to call the functions and then start your <<EOF again.

Code: Select all

<?php

$justA = "test";

echo <<<EOF
This is just a {$justA}..
EOF;
someFunction();
echo <<<EOF
..with a function in it.
EOF;

?>

Posted: Mon Dec 22, 2003 3:02 pm
by vigge89
i think you can, from what i've remembered, it have worked before, but onto the question, what have i forgot / what is worng ?

Posted: Mon Dec 22, 2003 3:56 pm
by Gen-ik
You can't have space (or anything) after your EOF; bits in your script.. not even comments. Once you've removed the comments make sure you've got rid of the spaces as well.

Posted: Mon Dec 22, 2003 4:05 pm
by vigge89
great, works now! :D

Posted: Mon Dec 22, 2003 4:13 pm
by vigge89
BTW, how do it prevent this from showing up?
"Warning: Missing argument 1 for echo_header() in C:\xampp\htdocs\notes\cfg.php on line 20"

function echo_header($head) { //Function echo_header ($head should be optional)

Posted: Mon Dec 22, 2003 4:21 pm
by Gen-ik
You need to enter a 'default' value into your echo_header() function if you are not sure if you will be sending it a value.

For example the following code will echo() "Apple" if I don't send it any info, otherwise it will echo() whatever I send it.

Code: Select all

<?php

function echoSomething($info = "Apple")
{
     echo $info."<br />";
}

//This will echo Apple
echoSomething();

//This will echo Banana
echoSomething("Banana");

//This will echo nothing at all
echoSomething("");


?>

Posted: Mon Dec 22, 2003 4:27 pm
by vigge89
ok, thanks!