Claite Posted March 4, 2009 Share Posted March 4, 2009 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 More sharing options...
br0ken Posted March 4, 2009 Share Posted March 4, 2009 It could be that you've included that file twice. When you only want a file included once try using include_once("Filename.php"); Change your include commands to include_once where ever you include that file and see if that helps. Link to comment https://forums.phpfreaks.com/topic/147963-login-script/#findComment-776588 Share on other sites More sharing options...
Claite Posted March 4, 2009 Author Share Posted March 4, 2009 That totally worked! Thank you very much! Link to comment https://forums.phpfreaks.com/topic/147963-login-script/#findComment-776629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.