Jump to content

Explanation of "undefined function"


smc

Recommended Posts

Hello,

I was wondering what the error "Call to undefined function" means.

I am baffeled by a few things going on involving my login script. One of which is I get an error of Call to undefined function for my functions adminlink(); and stafflink();. The functions are called in then HTML of a php page (<?php adminlink(); ?>). My functions are in a functions.php file which I included at the start of the page under session_start. These are the functions below

[code=php:0]
/Function for showing the link to the staff panel

function stafflink(){
if ( $_SESSION['srank'] == "staff" || $_SESSION['srank'] = "admin"){
$displaytxt = "<a href=\"/staff/index.php\">Staff panel</a>";
echo $displaytxt;
}
else {
$displaytxt = "";
echo $displaytxt;
}
}

//Function for showing the link to the admin panel

function adminlink(){
if ( $_SESSION['srank'] == "admin" ){
$displaytxt = "<a href=\"/admin/index.php\">Admin panel</a>";
echo $displaytxt;
}
else {
$displaytxt = "";
echo $displaytxt;
}
}
[/code]

Thanks for any help!
Link to comment
Share on other sites

I changed to require and it didn't change anything I still get

Fatal error: Call to undefined function: stafflink() in /home/een/public_html/een/templates/login_result.php on line 145

Here is my login.php (which is also giving me funky errors) and my login_result.php . login.php includes login_result.php in the event of success in logging in.

login_result.php :
[code]
<?php
/*/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
////                         login_result.php                            //
////---------------------------------------------------------------------//
////                      Content Managment System                       //
////                                v0.9                                 //
///////////////////////////////////////////////////////////////////////////
////                        Coded by: Shane Chism                        //
////                          smchism@gmail.com                          //
///////////////////////////////////////////////////////////////////////////
//// File Specifics:                                                     //
////   ----------------------------------------                          //
////   File creation: January 21st, 2007                                 //
////   Last file update: January 22nd, 2007                              //
////   ----------------------------------------                          //
////   File ID: login_result.php - Shows results of the login function   //
///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////*/

session_start();

$cms_root_path = '../';
require('http://een.eagleeye5.com/functions.php');

?>
<html>

 <head>
   <meta http-equiv="Content-Language" content="en-us">
     <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
       <link rel="stylesheet" href="/css/css.css" type="text/css" />
       <title>Eagle Eye News :: Login</title>
     </head>

 <body>
   <div align="center" valign="top">
     <table border="0" class="defaultframe" valign="top" cellpadding="0" cellspacing="0" id="table5">
       <tr>
         <td height="177" background="/images/header.jpg" width="100%">
           <table border="0" width="100%" id="table7" cellspacing="0" cellpadding="0" height="100%">
             <tr>
               <td colspan="8">&nbsp;</td>
             </tr>
             <tr>
               <td height="26" width="2%">&nbsp;</td>
               <td height="26" width="13%">
                 <p align="center">
                   <font face="Arial Black">
                     <a class="nav" href="index.php">HOME</a>
                   </font>
               </td>
               <td height="26" width="21%">
                 <p align="center">
                   <font face="Arial Black">
                     <a class="nav" href="topstories.php">TOP STORIES</a>
                   </font>
               </td>
               <td height="26" width="18%">
                 <p align="center">
                   <font face="Arial Black">
                     <a class="nav" href="features.php">FEATURES</a>
                   </font>
               </td>
               <td height="26" width="15%">
                 <p align="center">
                   <font face="Arial Black">
                     <a class="nav" href="sports.php">SPORTS</a>
                   </font>
               </td>
               <td height="26" width="14%">
                 <p align="center">
                   <font face="Arial Black">
                     <a class="nav" href="about.php">ABOUT</a>
                   </font>
               </td>
               <td height="26" width="16%">
                 <p align="center">
                   <font face="Arial Black">
                     <a class="nav" href="contact.php">CONTACT</a>
                   </font>
               </td>
               <td height="26" width="2%">&nbsp;</td>
             </tr>
             <tr>
               <td height="9" colspan="8"></td>
             </tr>
           </table>
         </td>
       </tr>
       <tr>
         <td>
           <table border="0" width="735" id="table6" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" height="100%">
             <tr>
               <div align="center">
                 <td>
                   <table border="0" cellpadding="0" cellspacing="0" width="100%" id="table8" height="100%">
                     <tr>
                       <td valign="top">
                         <div align="center">
                           <table border="0" cellpadding="0" cellspacing="0" width="100%" id="table13" height="100%">
                             <tr>
                               <td width="10" height="18"></td>
                               <td valign="top" height="18">
                               </td>
                               <td width="13" height="18"></td>
                             </tr>
                             <tr>
                               <td width="10" height="18"></td>
                               <td valign="top" height="18">
                                 <b>
                                   <font face="Arial Black">
                                     Staff - Login
                                   </font>
                                 </b>
                               </td>
                               <td width="13" height="18"></td>
                             </tr>
                             <tr>
                               <td width="10" height="18"></td>
                               <td valign="top" height="18">
                                 <hr>
                               </td>
                               <td width="13" height="18"></td>
                             </tr>
                             <tr>
                               <td width="10" height="14"></td>
                               <td valign="top" height="14"></td>
                               <td width="13" height="14"></td>
                             </tr>
                             <tr>
                               <td width="10">&nbsp;</td>
                               <td valign="top">
                                 <font face="Arial">
                                   <?php echo "$statustxt" ?>
                               <br />
                               <br />
<br />
<b>Panel links:</b>
                               <br />
                               <br />
                               <a href="/logout.php">Logout</a>
                               <br />
                               <br />
                                <?php stafflink(); ?>
                               <br />
                               <br />
                                <?php adminlink(); ?>
                               </td>
                               <td width="13">&nbsp;</td>
                             </tr>
                             <tr>
                               <td width="10" height="12"></td>
                               <td valign="top" height="12"></td>
                               <td width="13" height="12"></td>
                             </tr>
                           </table>
                         </div>
                         <p></td>
                     </tr>
                   </table>
                 </td>
               </div>
             </tr>
           </table>
         </td>
       </tr>
       <tr>
         <td height="12" background="/images/footer.jpg">
         </td>
       </tr>
     </table>
   </div>
   <p>&nbsp;</p>

 </body>

</html>
[/code]

login.php :
[code]
<?php
/*/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
////                             login.php                               //
////---------------------------------------------------------------------//
////                      Content Managment System                       //
////                                v0.9                                 //
///////////////////////////////////////////////////////////////////////////
////                        Coded by: Shane Chism                        //
////                          smchism@gmail.com                          //
///////////////////////////////////////////////////////////////////////////
//// File Specifics:                                                     //
////   ----------------------------------------                          //
////   File creation: January 21st, 2007                                 //
////   Last file update: January 22nd, 2007                              //
////   ----------------------------------------                          //
////   File ID: login.php - Allows staff members to login                //
///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////*/

$cms_root_path = '';
include($cms_root_path . 'functions.php');

//We call the config.php file later on to know where the website is at and where to route
$cms_root_path = '';
include($cms_root_path . 'config.php');

//Start up the session incase they are already logged in
//session_start();

//Check to see if they are logged in
if(isset($_SESSION['username'])){
$statustxt = $_SESSION['username'].", it seems your already logged in!";
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_status.php');
die;
}

if ( $submit != "true" ) {
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_form.php');
die;
}

// NOTE:
//  $resulttxt will be used to monitor failures or successes in login

//This will test to make sure the fields are not empty
if ( $submit == "true" ) {
// This will translate the fields into variables PHP can use
$username = $_POST['username'] ;
$password = $_POST['password'] ;

//This will test to make sure the fields are not empty
if ( $username == "" || $password == "" ){
$statustxt = "You left one or more fields blank when logging in. I don't have all day you know.<br /><br />Try <a href=\"/login.php\">logging in</a> again.";
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_status.php');
die;
}
}

//This next line we declare the huge bracket to surround the code. This is just verifying the credentials have been submitted
if ( $submit == "true" ) {

$username = $_POST['username'] ;
$password = $_POST['password'] ;

//This will now load the config login information, connect to the DB, select the DB, and then search for a matching username
$cms_root_path = './';
include($cms_root_path . 'config.php');
$conn = mysql_connect ($dblocation, $dbusername, $dbpassword)
or die ("Sorry - I got lost and couldn't find the database. Please try back later.");
$result = mysql_select_db("$dbdatabase", $conn)
or die("Sorry - the database decided to give me trouble. Please try back after I've put it in it's place.");
//This checks to see if there are any entries in the table users where the username matches the one just entered
$execute = mysql_query("SELECT * FROM users WHERE username='$username'")
or die ("Sorry - I couldn't find the table. Try back later.");
//This will check to see if there are no matches in the database with the username entered. If so it will trigger our nonamefound function
if (mysql_num_rows($execute) == 0) {
nonamefound();
}
//NOTE: SQL<MODIFIER> will represent the information retrieved from the database
while($row = mysql_fetch_array($execute)){
$sqlusername = $row["username"];
$sqlpassword = $row["pass"];
$sqlfirstname = $row["first_name"];
$sqllastname = $row["last_name"];
$sqlposition = $row["position"];
$sqlrank = $row["rank"];
$sqlemail = $row["email"];
}

//Now we are going to make sure the password is correct, if it isn't then our custom function will return to the error page
if ( $password != $sqlpassword ){
wrongpassword();
}
else{
//We will now start our session
session_start();
//Now we are going to assign all that information we retrieved from our database to our session so it can be used later
$_SESSION['susername'] = $sqlusername;
$_SESSION['spassword'] = $sqlpassword;
$_SESSION['sfirstname'] = $sqlfirstname;
$_SESSION['slastname'] = $sqllastname;
$_SESSION['sposition'] = $sqlposition;
$_SESSION['srank'] = $sqlrank;
$_SESSION['semail'] = $sqlemail;

//Now that all of our information is set in the session, we can go ahead and take them to the success page
$statustxt = $_SESSION['sfirstname']. " " . $_SESSION['slastname'].", you have succesfully logged in!";
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_result.php');
//include('http://een.eagleeye5.com/templates/login_result.php');
}
} //End huge bracket surrounding code

?>
[/code]
Link to comment
Share on other sites

[quote author=genericnumber1 link=topic=123552.msg510793#msg510793 date=1169500602]
dont include functions.php as a URL

require('http://een.eagleeye5.com/functions.php');

should be

require('./functions.php');
[/quote]

Alright I've repaired that but it's showing me the admin link when only logged in under staff. I have included functions.php below.

Also the funky errors. In login.php for some reason it is not echoing for me. It is supposed to have:

$statustxt = $_SESSION['sfirstname']. " " . $_SESSION['slastname'].", you have succesfully logged in!";
$cms_template_path = '/templates/';
require($scriptlocation . $cms_template_path . 'login_result.php');

but it's blank... Same goes for

if ( $submit == "true" ) {
// This will translate the fields into variables PHP can use
$username = $_POST['username'] ;
$password = $_POST['password'] ;

//This will test to make sure the fields are not empty
if ( $username == "" || $password == "" ){
$statustxt = "You left one or more fields blank when logging in. I don't have all day you know.<br /><br />Try <a href=\"/login.php\">logging in</a> again.";
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_status.php');
die;
}
}

and

function wrongpassword(){
$cms_root_path = '';
include($cms_root_path . 'config.php');
$statustxt = "Sorry, that password does not match that username.";
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_status.php');
die;
}


here is functions.php

[code]
<?php
/*/////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
////                           functions.php                             //
////---------------------------------------------------------------------//
////                      Content Managment System                       //
////                                v0.9                                 //
///////////////////////////////////////////////////////////////////////////
////                        Coded by: Shane Chism                        //
////                          smchism@gmail.com                          //
///////////////////////////////////////////////////////////////////////////
//// File Specifics:                                                     //
////   ----------------------------------------                          //
////   File creation: January 20th, 2007                                 //
////   Last file update: January 22nd, 2007                              //
////   ----------------------------------------                          //
////   File ID: functions.php : Functions definition File                //
///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////*/

/*//This function will connect to the database using the credentials in config.php - Disabled 1/21 for lack of probable use
function dbconnect(){
$cms_root_path = './';       //Some kind of security in place to prevent out of function password variable calling, added to get around it (following line as well)
include($cms_root_path . 'config.php');
$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword)
or die ("Sorry - we could not connect to our database. Please try back later.");
mysql_select_db ("$dbdatabase")
or die("Sorry - we encountered a database error. Please try back later.");
}*/

//We call the config.php file later on to know where the website is at and where to route
$cms_root_path = '';
include($cms_root_path . 'config.php');

//This function will execute SQL defined in a file and inject it into the SQL
function injectsql($sql){
$cms_root_path = './';
include($cms_root_path . 'config.php');
$dbh=mysql_connect ($dblocation, $dbusername, $dbpassword)
or die ("Sorry - we could not connect to our database. Please try back later.");
$rs=mysql_query($sql,$dbh)
or die ("Sorry - we could not execute the SQL command. Please try back later.");
}

//This function will be used in login.php in the event that a user enters a username not found in our DB
function nonamefound(){
$cms_root_path = '';
include($cms_root_path . 'config.php');
$statustxt = "Sorry, that username was not found in our database.";
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_status.php');
die;
}

//This function will be used in login.php in the event the user enters a password not matching the username
function wrongpassword(){
$cms_root_path = '';
include($cms_root_path . 'config.php');
$statustxt = "Sorry, that password does not match that username.";
$cms_template_path = '/templates/';
include($scriptlocation . $cms_template_path . 'login_status.php');
die;
}

//Function for showing the link to the staff panel

function stafflink(){
if ( $_SESSION['srank'] == "staff" || $_SESSION['srank'] = "admin"){
$displaytxt = "<a href=\"/staff/index.php\">Staff panel</a>";
echo $displaytxt;
}
else {
$displaytxt = "";
echo $displaytxt;
}
}

//Function for showing the link to the admin panel

function adminlink(){
if ( $_SESSION['srank'] == "admin" ){
$displaytxt = "<a href=\"/admin/index.php\">Admin panel</a>";
echo $displaytxt;
}
else {
$displaytxt = "";
echo $displaytxt;
}
}

//This function will be our sendmail function for registrations.

function regemail($destinationemail,$username,$password,$firstname,$lastname,$position){
$mailto = 'noreply@eagleeye5.com' ;
$subject = "Your registration information" ;

$uself = 0;
$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;

$domain = $_POST['domain'] ;

$name = "Eagle Eye 5 Network";
$fullname = $firstname . " " . $lastname;

$messageproper =

"Thank you for registering on the Eagle Eye 5 network. Here is your registration information:\n" .
"\n" .
"-------------\n" .
"\n" .
"Full name: $fullname\n\n" .
"Username: $username\n\n" .
"Password: $password\n\n" .
"Position: $position\n\n" .
"Registered e-mail: $destinationemail\n\n" .
"-------------\n" .
"\n" .
"If you have any questions please feel free to contact schism@eagleeye5.com.\n" .
"\n" .
"\n" .
"Thank you,\n\n" .
"Eagle Eye 5 Network \n\n" .
"\n" ;

mail($destinationemail, $subject, $messageproper,
"From: \"$name\" <$mailto>" . $headersep . "Reply-To: \"$name\" <$mailto>" . $headersep . "X-Mailer: chfeedback.php 2.07" );
}
?>
[/code]
Link to comment
Share on other sites

Also,

as you can see in

[code]
  $statustxt = $_SESSION['sfirstname']. " " . $_SESSION['slastname'].", you have succesfully logged in!";
  $cms_template_path = '/templates/';
  require($scriptlocation . $cms_template_path . 'login_result.php');
[/code]

of login.php, I basically use variables to define a definite path since scriptlocation is defined in config.php as http://een.eagleeye5.com. But the problem is this script is in root and the one im linking to is in /root/templates/ so I can't realitive link to it
Link to comment
Share on other sites

[quote author=The Little Guy link=topic=123552.msg510810#msg510810 date=1169501247]
Should this:
[CODE]
function stafflink(){
if ( $_SESSION['srank'] == "staff" || $_SESSION['srank'] = "admin"){
[/CODE]

Look like this (extra = symbol):
[CODE]
function stafflink(){
if ( $_SESSION['srank'] == "staff" || $_SESSION['srank'] == "admin"){
[/CODE]

In those funtions, replace the [b]echo[/b] with [b]return[/b]
[/quote]

I added the symbol and now its not showing staff members the staff link. || means "or" correct?

Jesirose:

No there is a staff and admin link. See above though
Link to comment
Share on other sites

[quote author=smc link=topic=123552.msg510816#msg510816 date=1169501435]
I added the symbol and now its not showing staff members the staff link. || means "or" correct?
[/quote]

Correct

Instead of doing two seperate funtions, why don't you just do one?

Kind of like this:

[code]
<?php
function srank(){
if($_SESSION['srank'] == "staff"){
$text = "<a href=\"/staff/index.php\">Staff panel</a>";
return $text;
}elseif($_SESSION['srank'] == "admin"){
$text = "<a href=\"/admin/index.php\">Admin panel</a>";
return $text;
}else{
$text = "";
return $text;
}
}
?>
[/code]
Link to comment
Share on other sites

[quote author=The Little Guy link=topic=123552.msg510827#msg510827 date=1169502140]
[quote author=smc link=topic=123552.msg510816#msg510816 date=1169501435]
I added the symbol and now its not showing staff members the staff link. || means "or" correct?
[/quote]

Correct

Instead of doing two seperate funtions, why don't you just do one?

Kind of like this:

[code]
<?php
function srank(){
if($_SESSION['srank'] == "staff"){
$text = "<a href=\"/staff/index.php\">Staff panel</a>";
return $text;
}elseif($_SESSION['srank'] == "admin"){
$text = "<a href=\"/admin/index.php\">Admin panel</a>";
return $text;
}else{
$text = "";
return $text;
}
}
?>
[/code]
[/quote]

Because there are two links to be displayed

Staff panel

Admin panel

Why is it now showing neithier link though?

I am just so confused
Link to comment
Share on other sites

I tried yours but it doesn't show anything still. I then tried putting in test in the final else just to see if something was up and that didn't return eithier. So something must be wrong with the include, but I'm using require and it's not producing any errors
Link to comment
Share on other sites

If it isn't working, I have the feeling that your functions have some logic errors in them.
[code]
<?php
session_start();
function srank(){
if($_SESSION['srank'] == "staff"){
$text = "<a href=\"/staff/index.php\">Staff panel</a>";
return $text;
}elseif($_SESSION['srank'] == "admin"){
$text = "<a href=\"/admin/index.php\">Admin panel</a>";
return $text;
}else{
$text = "";
return $text;
}
}

echo srank();
?>
[/code]

my above function checks the users session to check to see if they are a staff member or an admin, if they are a staff, then it displays the staff link, if they are an admin, it displays the admin link.
Link to comment
Share on other sites

This is the function in my functions.php which is being called right now. It does nothing, however.

[code]
function loginlinks(){
session_start();
if($_SESSION['srank'] == "staff"){
$text = "<a href=\"/staff/index.php\">Staff panel</a>";
return $text;
}elseif($_SESSION['srank'] == "admin"){
$text = "<a href=\"/staff/index.php\">Staff panel</a><br /><br /><a href=\"/admin/index.php\">Admin panel</a>";
return $text;
}else{
$text = "";
return $text;
}
}
[/code]
Link to comment
Share on other sites

Right now, Im not sure if you are using mine or your function, but in login_result.php

If you are using my function it needs to look like this:
<?php echo srank(); ?>



If Your using your 2 functions:
<?php stafflink(); ?>
<?php adminlink(); ?>

They need to be change to this:
<?php echo stafflink(); ?>
<?php echo adminlink(); ?>
Link to comment
Share on other sites

I've added that but I have a sneaky suspicion that this might all be due to a cache error.

I get this error:
Fatal error: Call to undefined function: stafflink() in /home/een/templates/login_result.php on line 145

However after I started having seizures I moved everything back to the root root domain and deleted the een subdomain. Therefor what is it calling?

I've emptied my temporary internet files, though, and it still shows up.

If you want to help me out and see if it works or says the same thing for you go to http://eagleeye5.com/login.php and use username: register password: oranges
Link to comment
Share on other sites

Alright I've (somehow) fixed it.

I changed

[code=php:0]
if ( $username == "" || $password == "" ){
$statustxt = "You left one or more fields blank when logging in. I don't have all day you know.<br /><br />Try <a href=\"/login.php\">logging in</a> again.";
$cms_template_path = './templates/';
include($cms_template_path . 'login_status.php');
die;
}
}
[/code]

From an absolute path to a relative path. From there it finally produced some errors I was able to deal with which finally lead to the solution.

Not sure why this caused it but it's fixed.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.