Jump to content

[SOLVED] need a little help please :)


runnerjp

Recommended Posts

hey guys...heres the deal.... i use $content = "pagename.php" to show the content on a template page

but i have the problem with im using this code to register members

 

<?php


session_start();
session_regenerate_id(true); // Generate new session id and delete old (PHP >= 5 only)

// registration
include_once("includes/functions.php");
include_once("includes/config.php");

// Inserts the given (username, password) pair into the database.
// Returns true on success, false otherwise.
function addNewUser($username, $password, $email){
global $conn;
/* Add slashes if necessary (for query) */
if(!get_magic_quotes_gpc()) {
	$username = addslashes($username);
	$password = addslashes($password);
	$email = addslashes($email);
}
$q = "INSERT INTO ".DB_PREFIX."users VALUES ('', '$username', '$password', '$email', ".time().", '".$_SERVER['REMOTE_ADDR']."', ".time().")";
return mysql_query($q,$conn);
}



// Display registration result page
if(isset($_SESSION['registered'])){

// html
include_once(HTML_PATH."html_register_result.php");

unset($_SESSION['reguname']);
unset($_SESSION['registered']);
unset($_SESSION['regresult']);
return;
}



// If the register form has been submitted: check for errors.
// No errors (count($alertArr) == 0)? Add record to database.
// Errors? Display error messages and show form again.
if(isset($_POST['subform'])){

// clean up
if ($_POST['user'])				$_POST['user'] = cleanString($_POST['user'], 30);
if ($_POST['pass_field_1'])		$_POST['pass_field_1'] = cleanString($_POST['pass_field_1'], 30);
if ($_POST['pass_field_2'])		$_POST['pass_field_2'] = cleanString($_POST['pass_field_2'], 30);
if ($_POST['email'])			$_POST['email'] = cleanString($_POST['email'], 140);
if ($_POST['pass1'])			$_POST['pass1'] = cleanString($_POST['pass1'], 40);
if ($_POST['pass2'])			$_POST['pass2'] = cleanString($_POST['pass2'], 40);
if ($_POST['salt'])				$_POST['salt'] = '';
if ($_POST['key'])				$_POST['key'] = '';

// check for errors
$alertArr = array();

if(!$_POST['user']) {
	$alertArr[] = $ALERT['USER_NO'];
}

if(strlen($_POST['user']) > 30) {
	$alertArr[] = $ALERT['USER_TOLONG'];
}

if($_POST['user'] && strlen($_POST['user']) < 6) {
	$alertArr[] = $ALERT['USER_TOSHORT'];
}

if(!$_POST['pass_field_1']) {
	$alertArr[] = $ALERT['PASS_NO'];
}

if($_POST['pass_1'] != $_POST['pass_2']) {
	$alertArr[] = $ALERT['PASS_DIFF'];
}

if(strlen($_POST['pass_field_1']) > 30) {
	$alertArr[] = $ALERT['PASS_TOLONG'];
}

if($_POST['pass_field_1'] && strlen($_POST['pass_field_1']) < 6) {
	$alertArr[] = $ALERT['PASS_TOSHORT'];
}

if(!$_POST['email']) {
	$alertArr[] = $ALERT['EMAIL_NO'];
}

if(strlen($_POST['email']) > 140) {
	$alertArr[] = $ALERT['EMAIL_TOLONG'];
}

if($_POST['email'] && !emailValid($_POST['email'])) {
	$alertArr[] = $ALERT['EMAIL_INVALID'];
}

if($_POST['email'] && emailExist($_POST['email'])) {
	$alertArr[] = $ALERT['EMAIL_TAKEN'];
}

if(usernameTaken($_POST['user'])) {
	$alertArr[] = $ALERT['USER_TAKEN'];
}

// Captcha
if (empty($_POST['validator']) || $_POST['validator'] != $_SESSION['rand_code']) {
	$alertArr[] = $ALERT['CAPTCHA'];
}
unset($_SESSION['rand_code']);

if (count($alertArr) == 0) {
	// Add the new account to the database
	// (password has already been encrypted using javascript)
	$_SESSION['reguname'] = $_POST['user'];
	$_SESSION['regresult'] = addNewUser($_POST['user'], $_POST['pass1'], $_POST['email']);
	$_SESSION['registered'] = true;
	$refresh = $HTTP_SERVER_VARS[php_SELF];
	exit(include_once(HTML_PATH."html_refresh.php")); // stop script
}
}

$alert = displayAlert($alertArr);

if ($_POST['pass_field_1']) $_POST['pass_field_1'] = "";
if ($_POST['pass_field_2']) $_POST['pass_field_2'] = "";

// html sign-up form
include_once(HTML_PATH."html_register_form.php");
?>

 

 

and using this as the html sign up form

 

<?php

// HTML code
// (replace (questionmark) with ?)
/*
<form name="register" action="<(questionmark)php print $HTTP_SERVER_VARS['PHP_SELF']; (questionmark)>" method="post" onsubmit="javascript:doRegister(this);">
<table align="left" border="0" cellspacing="0" cellpadding="3">
	<tr><td>Username:</td><td><input type="text" name="user" value="<(questionmark)php printField('user'); (questionmark)>" maxlength="30"></td></tr>
	<tr><td>Password:</td><td><input type="password" name="pass_field_1" maxlength="30"><input type="hidden" name="pass1" value="" /></td></tr>
	<tr><td>Retype password:</td><td><input type="password" name="pass_field_2" maxlength="30"><input type="hidden" name="pass2" value="" /></td></tr>
	<tr><td>Email:</td><td><input type="text" name="email" value="<(questionmark)php printField('email'); (questionmark)>" maxlength="140"></td></tr>
	<td>Read captcha code:</td>
	<td><img src="captcha.php" alt="CAPTCHA image" width="60" height="20" /></td></tr>
	<td>Fill in captcha code:</td>
	<td><input type="text" name="validator" id="validator" size="4" /></td></tr>
	<tr>
		<td colspan="2" align="right">
			<input type="hidden" name="salt" value="<(questionmark)php print $salt; (questionmark)>" />
			<input type="hidden" name="key" value="<(questionmark)php print $_SESSION['key']; (questionmark)>" />
			<input type="submit" name="subform" value="Submit">
		</td>
	</tr>
</table>
</form>
*/

?>
<html>
<head>
<title>Registration page</title>
<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="login.js"></script>
</head>
<body>
<?php print $alert; ?>
<h1>Registration</h1>
<script language="JavaScript" type="text/javascript">
<!--
// converted using http://accessify.com/tools-and-wizards/developer-tools/html-javascript-convertor/
function writeJS(){
var str='';
str+='	<form name="register" action="<?php print $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post" onsubmit="javascript:doRegister(this);">';
str+='		<table align="left" border="0" cellspacing="0" cellpadding="3">';
str+='			<tr><td>Username:<\/td><td><input type="text" name="user" value="<?php printField('user'); ?>" maxlength="30"><\/td><\/tr>';
str+='			<tr><td>Password:<\/td><td><input type="password" name="pass_field_1" maxlength="30"><input type="hidden" name="pass1" value="" \/><\/td><\/tr>';
str+='			<tr><td>Retype password:<\/td><td><input type="password" name="pass_field_2" maxlength="30"><input type="hidden" name="pass2" value="" \/><\/td><\/tr>';
str+='			<tr><td>Email:<\/td><td><input type="text" name="email" value="<?php printField('email'); ?>" maxlength="140"><\/td><\/tr>';
str+='			<td>Read captcha code:<\/td>';
str+='			<td><img src="captcha.php" alt="CAPTCHA image" width="60" height="20" \/><\/td><\/tr>';
str+='			<td>Fill in captcha code:<\/td>';
str+='			<td><input type="text" name="validator" id="validator" size="4" \/><\/td><\/tr>';
str+='			<tr>';
str+='				<td colspan="2" align="right">';
str+='					<input type="hidden" name="salt" value="<?php print $salt; ?>" \/>';
str+='					<input type="hidden" name="key" value="<?php print $_SESSION['key']; ?>" \/>';
str+='					<input type="submit" name="subform" value="Submit">';
str+='				<\/td>';
str+='			<\/tr>';
str+='		<\/table>';
str+='	<\/form>';
document.write(str);
}
writeJS();
//-->
</script>
<noscript>You need Javascript to use this page.</noscript>
</body>
</html>

 

 

iv tried adding both into the content but all i keep getting is a new page with the html script on it... what am i doing wrong?

 

 

Link to comment
https://forums.phpfreaks.com/topic/51324-solved-need-a-little-help-please/
Share on other sites

well when people want to register on my site they go to register.php

 

<?php
$content="login/html/html_register_form.php";
include("include/header.inc.php");
include("include/body.inc.php");
?>

 

the header.inc.php is my header of the website.... on body.inc.php is basicly my website template and on it has

if (file_exists($content)) {
include($content);
} else {?>
      <?echo $content;?>

so this shows what i want the content to be in this area...

 

so thats why it shows $content="login/html/html_register_form.php";

 

but the problem is when i add $content="login/html/html_register_form.php"; all it does is takes the user to the html_register_form.php"; page and does not display it in the content area...i have tried it with both $content="login/html/html_register_form.php"; and $content="login/register.php"; but fails to work and i want to know why.... do i have to add

include("include/header.inc.php");
include("include/body.inc.php");

into html_register_form.php itself??

 

does that make better sence

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.