Unstoppable Domains โ€” Expired Auctions

PHP code not running properly

SpaceshipSpaceship
Watch
Impact
45
Hey guys,

I keep getting this error on a thing I am trying to configure so that people can login to my forums throughout my network. Here's what it displays on the page after a user has logged in:


Welcome Admin!
is_loggedin()) { // We're logged in. Display PM Status. echo 'Your PM box stats:
'; echo 'You have '.$SDK->get_num_total_pms().' PMs in total.
'; // Get Total PMs echo 'You have '.$SDK->get_num_new_pms().' new PMs since your last visit.
'; // Get New PMs } else { // Not logged in. echo "You are not logged in."; } // ===================== // END PM STATUS // ===================== ?>


Logout


As you can see, I bolded out the error in red.
Yes, believe it or not, the page actually displays the PHP code and therefor the PHP code isn't even running.

Here's the PHP code of the page:
Code:
<font face="Verdana" size="2">Welcome <b> <a href="{profile_link}" target="_blank">{member_name}</a></b>!<br>
<?php

// Load and Start IPB SDK
require_once "ipbsdk_class.inc.php";
$SDK =& new IPBSDK();



// =====================
// START PM STATUS
// =====================

if ($SDK->is_loggedin()) {
	// We're logged in. Display PM Status.

	echo '<strong>Your stats:</strong><br />';
	echo 'You have <strong>'.$SDK->get_num_total_pms().'</strong> PMs in total.<br />'; // Get Total PMs
	echo 'You have <strong>'.$SDK->get_num_new_pms().'</strong> new PMs since your last visit.<br />'; // Get New PMs
}
else {
	// Not logged in.
	echo "You are not logged in.";
}

// =====================
// END PM STATUS
// =====================
?>


<br />
<br />
<a href="{logout_link}" target="_self">Logout</a></font>

Does anyone know how I can fix this?

Thanks a lot to anyone who can help,
Andy M.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
sill question but what extension is the page you have that code in?
 
0
•••
Php

Here is the running version of it if you want to see for yourself. Just use the account "demo" with the password "demo" to login and see the error.


Thanks man,
Andy
 
0
•••
hmmmmm odd one

is that the entire content of login.php above?

or are you opening a file and replacing strings? i notice you have {logoutlink} etc tells me your opening a text file or html file?
 
0
•••
Technically the code I gave you above is from memberonly.php (which the code is used from that if the login is successful of a member).

Here's the login.php coding (caution: it's pretty long):
Code:
<?php

/*
+ ------------------------------------------------------------------------
+ IPB SDK Script - [SDK]Easy-to-edit Login Script
+ Copyright (C) 2004 Timothy Leucht (lightsup55)
+ ------------------------------------------------------------------------
+ Login and logout script using templates for easy editing.
+ ------------------------------------------------------------------------
*/


//-----------------------------------------------
// USER CONFIGURABLE ELEMENTS
//-----------------------------------------------

// Define the path to where the IPB SDK files are
// located. This might be "./forums/" for example.
// Don't forget the trailing slash!
define( 'IPBSDK_PATH', "/home/flametid/public_html/ipbsdk/" );


// Define the path to where the template file are
// located. This might be "./templates/" for example.
// Don't forget the trailing slash!
$templates_dir = "./";


// The file names of the templates
// Only change if using a different name
$template_main          =  "main.html";          // Main template
$template_redirect      =  "redirect.html";      // The redirection page
$template_form_guests   =  "form_guests.html";   // Login form and guests stuff
$template_memberonly    =  "memberonly.php";    // Member only information


// Redirection Time (in seconds)
$redirectSeconds = "5";


// --- Optional ---
// If using a portal other than IPDynamic Lite, define it here
// Example: http://www.domain.com/someotherportal.php
$portal_url = "";




//-----------------------------------------------
// NO USER EDITABLE SECTIONS BELOW
//-----------------------------------------------


// You got error!
error_reporting  (E_ERROR | E_WARNING | E_PARSE);



// Load and Start IPB SDK
require_once IPBSDK_PATH."ipbsdk_class.inc.php";
$SDK =& new IPBSDK();
$sdk_info = $SDK->get_advinfo();



$LoginScript = new scriptinfo();

class scriptinfo {
var $GetAction = "";
var $onload = "";
var $ipbMemberID = "";
var $ipbUsername = "";
var $ipbForumsURL = "";
var $portalURL = "";
var $scriptURL = "";
var $redirect = "";
var $message = "";
var $linkMsg = "";
var $ISloggedin = "";
var $NOTloggedin = "";
var $temp_form_guests = "";
var $temp_main = "";
var $temp_memberonly = "";
var $temp_redirect = "";
}


$LoginScript->scriptURL = $_SERVER["PHP_SELF"];
$LoginScript->redirect = '<meta http-equiv="refresh" content="'.$redirectSeconds.'; URL='.$LoginScript->scriptURL.'" />'."\r\n";
$LoginScript->ipbMemberID  =  $sdk_info['id'];     // IPB Member ID (number, 0 is Guest)
$LoginScript->ipbUsername  =  $sdk_info['name'];   // IPB Username
$LoginScript->ipbForumsURL =  $INFO['board_url']."/index.".$INFO['php_ext']."?";   // The forums URL
$LoginScript->temp_form_guests   =   $template_form_guests   ;
$LoginScript->temp_main          =   $template_main          ;
$LoginScript->temp_memberonly    =   $template_memberonly    ;
$LoginScript->temp_redirect      =   $template_redirect      ;



// Did we enter a different URL for the portal?
   if ($portal_url != "") {
   // We did, now use it!
   $LoginScript->portalURL = $portal_url;
   } else {
          // OK FINE! I'll use IPDynamic Lite.
          $LoginScript->portalURL = $LoginScript->ipbForumsURL."act=home";
          }



   if ( isset($_GET['act']) ) {
   $LoginScript->GetAction = $_GET['act'];
   } else {
          $LoginScript->GetAction = "";
          }


// ------------------
// Decide what to do
// ------------------

switch ( $LoginScript->GetAction )
{
	case 'Login':
		do_login();
		break;
		
	case 'Logout':
		do_logout();
		break;
		
	default:
		do_default();
		break;
}




// ------------------
// Deh {parse} template function
// ------------------

function parse_template( $template, $assigned=array() )
{
	global $SDK, $LoginScript, $templates_dir;

	foreach( $assigned as $word => $replace)
	{
		$template = preg_replace( "/\{$word\}/i", "$replace", $template );
	}
	
	return $template;
}



// ------------------
// Da load template function
// ------------------

function load_template($template="")
{
	global $SDK, $LoginScript, $templates_dir;

	$filename = $templates_dir.$template;
	
	if ( file_exists($filename) )
	{
		if ( $FH = fopen($filename, 'r') )
		{
			$template = fread( $FH, filesize($filename) );
			fclose($FH);
		}
		else
		{
			fatal_error("Couldn't open the template file");
		}
	}
	else
	{
		fatal_error("Template file does not exist");
	}
	
	return $template;

}



// ------------------
// Oh no, dare's a problem wit deh template
// Oh what ta do, what ta do.
// ------------------

function fatal_error($message="") {
	global $SDK, $LoginScript, $templates_dir;

	echo("An error occured whilst processing this directive");
	if ($message)
	{
		echo("<br />$message");
	}
	exit();
}





// ------------------
// Now pay attention when I'm talking to ya son.
// I said, I said... LOG-OUT son!
// ------------------

function do_logout() {
global $SDK, $LoginScript, $templates_dir;

$SDK->logout();


$LoginScript->message = "You have been logged out.";
$LoginScript->linkMsg = "Click here to continue";


$template = load_template($LoginScript->temp_redirect);

$to_echo = "";

$to_echo .= parse_template( $template,
							    array (
							    		 'redirect'       => $LoginScript->redirect,
							    		 'message'        => $LoginScript->message,
							    		 'link'           => $LoginScript->scriptURL,
							    		 'link_msg'       => $LoginScript->linkMsg
								    	  )
								    );

	echo $to_echo;
	exit();
}







// ------------------
// OK GUYS!... LOG-IN!
// ------------------

function do_login() {
global $SDK, $LoginScript, $templates_dir;



	if ($_SERVER['REQUEST_METHOD'] == "POST") {
		// The form was submitted. Lets authenticate!

		$username = $_POST['username'];
		$password = $_POST['password'];
		$anonlogin = $_POST['anonlogin'] ? "1" : "0";

			if ($SDK->login($username, $password, 1, $anonlogin)) {
			// The login worked. :)

			$LoginScript->message = "Login Successful!";
			$LoginScript->linkMsg = "Click here to continue";
			} else {
				  // The login failed :(

				  $LoginScript->message = "<b>Fatal Error:</b> ".$SDK->sdk_error();
				  $LoginScript->linkMsg = "Login again";
				  $LoginScript->redirect = "";
			       }

		$template = load_template($LoginScript->temp_redirect);
		$to_echo = "";
		$to_echo .= parse_template( $template,
							    array (
							    		 'redirect'       => $LoginScript->redirect,
							    		 'message'        => $LoginScript->message,
							    		 'link'           => $LoginScript->scriptURL,
							    		 'link_msg'       => $LoginScript->linkMsg
								    	  )
								    );

		echo $to_echo;
		exit();
		} else {
	            do_default();
	            }
// Ok, you can stop working with do_login!
}







// ------------------
// Do da default
// ------------------

function do_default() {
global $SDK, $LoginScript, $templates_dir;



      // =====================
      // START MEMBER ONLY
      // =====================

      if ($SDK->is_loggedin()) {
            // Code for logged in users goes here

            $ISloggedin_T = load_template($LoginScript->temp_memberonly);

            $LoginScript->ISloggedin = "";

            $LoginScript->ISloggedin .= parse_template( $ISloggedin_T,
								    array (
	 'logout_link'    => $LoginScript->scriptURL."?act=Logout",
	 'profile_link'   => $LoginScript->ipbForumsURL."showuser=".$LoginScript->ipbMemberID,
	 'profile_id'     => $LoginScript->ipbMemberID,
	 'member_name'    => $LoginScript->ipbUsername,
	 'forums_url'     => $LoginScript->ipbForumsURL."act=idx",
	 'portal_url'     => $LoginScript->portalURL
								    	  )
								    );
            } else {
                   // Code for GUESTS goes here

                   // Give focus to the "username" field --- bug fix for Mozilla
                   $LoginScript->onload = 'document.theLoginForm.username.focus();';


                   $NOTloggedin_T = load_template($LoginScript->temp_form_guests);

                   $LoginScript->NOTloggedin = "";

                   $LoginScript->NOTloggedin .= parse_template( $NOTloggedin_T,
						    array (
						    	 'form_action'     => $LoginScript->scriptURL."?act=Login",
						    	 'form_method'     => "POST",
						    	 'forums_url'      => $LoginScript->ipbForumsURL."act=idx",
						    	 'portal_url'      => $LoginScript->portalURL,
						    	 'forums_reg_url'  => $LoginScript->ipbForumsURL."act=Reg&CODE=00"
							    	  )
							    );
                   }

      // =====================
      // END MEMBER ONLY
      // =====================




// =====================
// Print deh main template
// =====================

$template = load_template($LoginScript->temp_main);

$to_echo = "";

$to_echo .= parse_template( $template,
						    array (
						    		 'memberonly'  => $LoginScript->ISloggedin,
						    		 'form_guests' => $LoginScript->NOTloggedin,
						    		 'onload'      => $LoginScript->onload
							    	  )
							    );

	echo $to_echo;
	exit();
}


?>

I am puzzled as to why it continues to display the error :s


Thanks for your help,
Andy
 
0
•••
right i think i know why now

the reason is the when you hit logon.php its opening the php file. so because your opening it (like you open a text file in a text editor) its not putting to php to parse, its just opening the file as text and then doing string searches for your {logoutoutlink}

it will only parse php in seperate files if you use include or require.

so what you need to do is take out the php code and create a new rule like you have for {logoutlink} and parse the php code in login.php.

if that makes any sense?
 
0
•••
Thanks Adam! Now I know what you mean.
My only problem now is trying to find out where (and how) I can make a new rule in the coding.
 
0
•••
no problem

i think you need to take a look at this bit

function parse_template( $template, $assigned=array() )
{
global $SDK, $LoginScript, $templates_dir;

foreach( $assigned as $word => $replace)
{
$template = preg_replace( "/\{$word\}/i", "$replace", $template );
}

return $template;
}
 
0
•••
Wouldn't I have to edit something around here? :

'logout_link' => $LoginScript->scriptURL."?act=Logout",
'profile_link' => $LoginScript->ipbForumsURL."showuser=".$LoginScript->ipbMemberID,
'profile_id' => $LoginScript->ipbMemberID,
'member_name' => $LoginScript->ipbUsername,
'forums_url' => $LoginScript->ipbForumsURL."act=idx",
'portal_url' => $LoginScript->portalURL

I'm still pretty confused on where they store the info for the rules :-$
 
0
•••
i would suggest contacting ibp (im guessing its invsion board right?)

they would best be able to help you with it. im not to sure of hte ins and outs of it.
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back