/    Sign up×
Community /Pin to ProfileBookmark

Redirecting after login

I’m working on a project for a class i’m taking. Right now i’m stuck on my login script. When logging in (with a valid or invalid user/pass) it attempts to login but it can’t find Template.php. But if i add a set_include_path for template or an exact url to template the login will work but the logout continues to throw a similar error.

Any suggestions would be appreciated.

Example Webpage (Without set_include_path() in login.php):
[url]http://babbage.cs.missouri.edu/~bar338/webProject/index.php[/url]

Example Webpage (WITH set_include_path() in login.php):
[url]http://babbage.cs.missouri.edu/~bar338/test/webProject/index.php[/url]

You can login using the username: test Password: pass
But if you enter an invalid username/pass the error below happens.

Brief File Structure

[QUOTE]

Index.php
login.php
System (Folder)
—-Template.php
—-RedirectBrowserException.php

[/QUOTE]

Error Message:

[QUOTE]

Warning: require_once(Template.php) [function.require-once]: failed to open stream: No such file or directory in /students/b/bar338/public_html/webProject/login.php on line 2

Fatal error: require_once() [function.require]: Failed opening required ‘Template.php’ (include_path=’.:/usr/share/pear:/usr/share/php’) in /students/b/bar338/public_html/webProject/login.php on line 2

[/QUOTE]

Files (let me know if you need more)

Index.php

[code=php]<?php
// this creates the home page

// tell php what directories to search when doing include and require
$paths = ‘system’ . PATH_SEPARATOR . ‘components’ . PATH_SEPARATOR . ‘templates’;
set_include_path($paths);

require_once(‘Template.php’);
require_once(‘Page.php’);

// do any processing of application first

// create components and run them
$page = new Page(‘Home’);
$page->run(array(‘uname’ => ‘Kevin’, ‘id’ => ’22’));

// create this application’s content

$tmpl = new Template();

$html = $tmpl->build(‘maincol.html’);
$css = $tmpl->build(‘maincol.css’);

$mainContent = array(array(‘html’=>$html, ‘css’=>$css));

$html = $tmpl->build(‘login.html’);
$css = $tmpl->build(‘login.css’);
$html2 = $tmpl->build(‘options.html’);
$css2 = $tmpl->build(‘options.css’);

$sideContent = array(array(‘html’=>$html, ‘css’=>$css), array(‘html’=>$html2, ‘css’=>$css2));

// create the page
print $page->build($mainContent, $sideContent);
?>
[/code]

Login.php

[code=php]<?php
require_once(‘Template.php’);
require_once(‘RedirectBrowserException.php’);

$action = empty($_POST[‘action’]) ? ” : $_POST[‘action’];

if ($action == ‘do_login’) {
handle_login();
} else {
login_form();
}

function handle_login() {
$username = empty($_POST[‘username’]) ? ” : $_POST[‘username’];
$password = empty($_POST[‘password’]) ? ” : $_POST[‘password’];

if ($username == “test” && $password == “pass”) {
setcookie(‘username’, $username);
throw new RedirectBrowserException(‘memberhome.php’);
} else {
$error = ‘Incorrect Username/Password.’;

$tmpl = new Template();
$tmpl->error = $error;
$tmpl->username = $username;

print $tmpl->build(‘index.php’);
}
}

function login_form() {
$tmpl = new Template();
print $tmpl->build(‘index.php’);
}

?>[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiApr 20.2009 — From the php manual page for set_include_path:

Sets the include_path configuration option [B]for the duration of the script[/B].

Setting the path in index.php will not have any effect in login.php. Also you appear to be on a unix type system, which means it will be case sensitive, so System != system.
Copy linkTweet thisAlerts:
@bryceray1121authorApr 20.2009 — Ya i have the set_include_path in the second link. Which works fine if the username/pass is a valid one. But if it isn't it is supposed to redirect back to index.php. I'm not sure why its not working, logically in my head it shouldn't be a problem. And all folder names are in lowercase so they match what is in the include.

The error i'm still receiving when it is an unsuccessful login:

Warning: include(index.php) [function.include]: failed to open stream: No such file or directory in C:apachehtdocswwwwebProjectsystemTemplate.php on line 12

Warning: include() [function.include]: Failed opening 'index.php' for inclusion (include_path='system;components;templates') in C:apachehtdocswwwwebProjectsystemTemplate.php on line 12
[/QUOTE]


Here is a template file (pretty simple):
[code=php]<?php
class Template {

public function __construct() {
}

function build($templateFilePath) {
$tmpl = $this;
// suppress non-existent variable warnings
error_reporting(E_ALL - E_NOTICE);
ob_start();
include($templateFilePath);
return ob_get_clean();
}
}
?>
[/code]


And an updated login.php with include:
[code=php]<?php
$paths = 'system' . PATH_SEPARATOR . 'components' . PATH_SEPARATOR . 'templates';
set_include_path($paths);
require_once('Template.php');
require_once('RedirectBrowserException.php');

$action = empty($_POST['action']) ? '' : $_POST['action'];

if ($action == 'do_login') {
handle_login();
} else {
login_form();
}

function handle_login() {
$username = empty($_POST['username']) ? '' : $_POST['username'];
$password = empty($_POST['password']) ? '' : $_POST['password'];

if ($username == "test" && $password == "pass") {
setcookie('username', $username);
throw new RedirectBrowserException('memberhome.php');
} else {
$error = 'Incorrect Username/Password.';

$tmpl = new Template();
$tmpl->error = $error;
$tmpl->username = $username;

print $tmpl->build('index.php');
}
}

function login_form() {
$tmpl = new Template();
print $tmpl->build('index.php');
}

?>[/code]


I appologize if this is trivial, i just can't figure otu the logic to why this is not working.
Copy linkTweet thisAlerts:
@robertketterApr 21.2009 — Maybe you need to make path global? Just a guess.. ?
×

Success!

Help @bryceray1121 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...