Jump to content

Login Script


Claite

Recommended Posts

I'm writing a login script for a site I'm making. I made a file called loginScript.php which contains the following code:

 

<?php
function loggedIn () {
session_start();

if(isset($_SESSION['phone']) && isset($_SESSION['pass']){
	return true;
} else {
	return false;
}

session_write_close()
}

function login ($phone, $pass){
$connect = mysql_connect(stuff);
if(!$connect) {
	die(mysql_error());
}
mysql_select_db('site') or die(mysql_error());

session_start();

$newPass = base64_encode($pass);
$phoneQry = "SELECT * FROM members WHERE phone = '$phone'"
$qry = mysql_query($phoneQry);

if(mysql_num_rows($qry) > 0){
	$table = mysql_fetch_assoc($qry);
	if($newPass = $table['pass']){
		$_SESSION['phone'] = $phone;
		$_SESSION['pass'] = $newPass;
		$_SESSION['username'] = $table['username'];
	} else {
		$errorLogin = "You typed in the wrong password";
	}
} else {
	$errorLogin = "That phone number does not exist";
}

include "index.php";

session_write_close();
}

 

Then, my index.php does as follows:

 

	if(loggedIn()){
	<center>Welcome <?php $_SESSION['username']; ?>!</center>
	<a href="controlP.php">User Panel</a>
} else {
	<form action="login.php" method="post">
	Phone Number: <br><input type="text" name="username" maxlength="60"><br>
	Password: <br><input type="password" name="pass" maxlength="60"><br>
	<input type="submit" value="submit">
}

 

And last but no least, login.php:

 

<?php
include "loginScript.php";
login($_POST['phone'], $_POST['pass']);
?>

 

So, here's my issue. The line "include "loginScript.php" in login.php is causing this error:

 

Fatal error: Cannot redeclare loggedin() (previously declared in *path*/loginScript.php:3) in *path*/loginScript.php on line 12

 

where *path* is an actual path.

 

If I remove it however, it tells me login() is not defined. If I remove it from my index.php it'll throw errors because is use "if(loggedIn())"

 

I tried maybe having my form call the function, but I don't know how to do that :S

 

Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/147963-login-script/
Share on other sites

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.