Jump to content

mannyguy

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

mannyguy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. IT WORKED!!! WORDS CANNOT EXPLAIN HOW MUCH I APPREACIATE THIS! THANK YOU SO MUCH TO BOTH POSTER WHO HELPED ME! I REALLY REALLY REALLY APPRECIATE IT.
  2. It worked thanks! EXCEPT. Now if i go back to the home page the log in form is superimposed on the welcome message. So now What i need is for the log in form to always be gone if I am signed in. <?php //Starts the PHP Sesssion session_start(); //Includes the MYSLQ Connection Info from another PHP Page include ('spartacus_mysql.php'); if(isset ($_POST['loginsubmit']) && !isset($_SESSION['loggedin'])){ /*Log in queries etc. here.*/ $username = mysql_escape_string($_POST['username']); $userpassword = mysql_escape_string(md5($_POST['userpassword'])); if (!empty ($username) && !empty ($userpassword)) { //Runs Query to Selects the Username and Password from the Database $sql = mysql_query ("SELECT * FROM users WHERE username='".$username."' AND userpassword='".$userpassword."' LIMIT 1"); //Finds and Matches the Log In Info from the Database to the one submitted if(mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; } else { //Runs This Error if the Username/Password do not match the Database echo '<div id="welcome_member"> Your username and/or password is incorrect! <a href="spartacus_home.php">Try Again</a> </div>'; } } else { //Runs This Code if the Log In Form is Left Blank echo '<div id="welcome_member"> You must enter a username and a password! <a href="spartacus_home.php">Try Again</a> or <a href="spartacus_joinsite.php">Register</a> </div>';} } else { /* echo login form here*/ //This is the code for the Log in Form echo'<div id="join"> <a href="spartacus_joinsite.php">{ JOIN! }</a><br /> </div> <div class="signin"> <div id="titles"> { SIGN IN } </div><br /> <form method="post" action="spartacus_home.php"> <table> <tr><td> Username: <input type="text" name="username" /> </td></tr> <tr><td> Password: <input type="password" name="userpassword"/> </td></tr> <tr><td> <input class="submit" name="loginsubmit" type="submit" /> </tr></td> </table> </form> </div>'; } if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) { /* echo welcome message */ //Runs This Message if the right Username/Password is entered echo '<div id="welcome_member"> Welcome, '.$_SESSION['username'].'.<br /> You are now logged in!<br/> The Combat Tips and Downloads is now accessible!<br /> Enjoy!<br /> <a href="spartacus_logout.php">Log Out</a> </div>'; } ?>
  3. So do I just add this code in my code? Or is there something I need to remove and replace it with this. Sorry to ask. I'm new at php and still learning Thanks.
  4. Hi. I have problem and I would like to know if anyone here has any ideas on how to fix it. My home page is where my log in form resides. If I leave the home page to browse other pages of my site I want to stay logged in. However, when I return to the home page I see the log in form. The log in form should not be there if I already logged in. Instead I should see the welcome message. Which does appear after loggin in but does not stay on the home page when I leave the page and come back. <?php //Starts the PHP Sesssion session_start(); //Includes the MYSLQ Connection Info from another PHP Page include ('spartacus_mysql.php'); //Submits Log In Info to Database and encrypts Password if (isset ($_POST['loginsubmit'])) { $username = mysql_escape_string($_POST['username']); $userpassword = mysql_escape_string(md5($_POST['userpassword'])); if (!empty ($username) && !empty ($userpassword)) { //Runs Query to Selects the Username and Password from the Database $sql = mysql_query ("SELECT * FROM users WHERE username='".$username."' AND userpassword='".$userpassword."' LIMIT 1"); //Finds and Matches the Log In Info from the Database to the one submitted if(mysql_num_rows ($sql) > 0) { $_SESSION['loggedin'] = true; $_SESSION['username'] = $username; //Runs This Message if the right Username/Password is entered echo '<div id="welcome_member"> Welcome, '.$_SESSION['username'].'.<br /> You are now logged in!<br/> The Combat Tips and Downloads is now accessible!<br /> Enjoy!<br /> </div>'; } else { //Runs This Error if the Username/Password do not match the Database echo '<div id="welcome_member"> Your username and/or password is incorrect! <a href="spartacus_home.php">Try Again</a> </div>'; } } else { //Runs This Code if the Log In Form is Left Blank echo '<div id="welcome_member"> You must enter a username and a password! <a href="spartacus_home.php">Try Again</a> or <a href="spartacus_joinsite.php">Register</a> </div>'; } } else { //This is the code for the Log in Form echo'<div id="join"> <a href="spartacus_joinsite.php">{ JOIN! }</a><br /> </div> <div class="signin"> <div id="titles"> { SIGN IN } </div><br /> <form method="post" action="spartacus_home.php"> <table> <tr><td> Username: <input type="text" name="username" /> </td></tr> <tr><td> Password: <input type="password" name="userpassword"/> </td></tr> <tr><td> <input class="submit" name="loginsubmit" type="submit" /> </tr></td> </table> </form> </div>'; } ?> <!--end sign in PHP--> Here is my code
  5. I appologize for my ignorance, but what do you mean by:
  6. I tried this and it didn't work maybe i'm not using it right. The session_start() goes at the top of the page right? not at the beggining of the log in php? Should I copy that code into the log in page and into all the pages that I want the log in to continue active?
  7. Well the issue is that I log in and when I switch to another page within the site I'm automatically logged out. so i'm forced to log in again everytime i change pages in the site. I hope this makes sense, because I'm not trying to auto log in the user. I'm just rying to stay logged in when i click on another page WITHIN my own site.
  8. Not at all harsh. I know very little about php I'm learning as I go. NO offense taken. I just need help having the code work on all the pages of my site. 1. I copied the code from a tutorial…What should I do instead of a cookie? 2. those are just my errors that i made right now when i was deleted my info to post here 3. I will fix the this error asap 4. I'm not sure what you mean here. 5. Like I said I used a tutorial 6. I did the session_start() but it didn't do anything for me. but i will put it back in 7. I'll delete this if its doing nothing for me 8. I will delete the quotes
  9. My bad. Thanks! Anyone have any ideas?
  10. <?php //connects to database mysql_connect("hose "name", "password") or die(mysql_error()); mysql_select_db("name") or die (mysql_error()); //checks if there is a login cookie if(isset($_COOKIE['ID_my_site'])) //if there is, it logs in and directs to members page { $username = $_COOKIE['ID_my_site']; $userpassword = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'") or die(mysql_error()); while($info = mysql_fetch_array( $check )) { if ($userpassword != $info['password']) { } else { header(" testing_login.php"); } } } //if the log in form is submitted if (isset($_POST['loginsubmit'])) { //if form has been submitted //makes sure forms is filled in if(!$_POST['username'] | !$_POST['userpassword']) { die("<div id='welcomesign2'>You did not fill in all of the required fields.<br /> <a href='spartacus_home.php'>Try Again.</a></div>"); } //checks against database if (!get_magic_quotes_gpc()) { $_POST['email'] = addslashes($_POST['email']); } $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error()); //gives error if user doesn't exist $check2 = mysql_num_rows($check); if ($check2 == 0) { die("<div id='welcomesign2'>Username does not exist in our database. <br /> <a href='spartacus_joinsite.php'>Register</a> or <a href='spartacus_home.php'>Try Again. </a></div>"); } while($info = mysql_fetch_array( $check)) { $_POST['userpassword'] = stripslashes($_POST['userpassword']); $info['userpassword'] = stripslashes($info['userpassword']); $_POST['userpassword'] = md5($_POST['userpassword']); //gives error if the password is wrong if ($_POST['userpassword'] != $info['userpassword']) { die("<div id='welcomesign2'>Sorry, incorrect password, please retry.<br /> <a href='spartacus_home.php'> Try Again. </a></div>"); } else { //keeps username in form after 'Incorrect password' error $_SESSION['username'] = $_POST['username']; //if log in is ok we add a cookie $_POST['username'] = stripslashes($_POST['username']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['username'], $hour); setcookie(Key_my_site, $_POST['userpassword'], $hour); //then redirect to members area header("testing_login.php"); } } } else { //if they are not logged in ?> Thast my check loggin php. Its the code used to log in. I assume this is where the error lies? Here's my welcome php. <?php function CheckLogin() { session_start(); $sessionvar = $this->GetLoginSessionVar(); if(empty($_SESSION['$sessionvar'])) { return false; } return true; } require("spartacus_home.php"); $username=filter_input(INPUT_POST, 'username'); print "<div id='welcomesign'><h4>Welcome, $username!</h4></div>"; ?> <div id="welcomesign2"> <p> You now have access to all content including,<br /> the Downloads and Combat Tips.<br />Enjoy! </p> <form action="spartacus_home.php" method="post"> <input type="submit" class="submit" name="logout" value="Log Out" /> </form> MOD EDIT: . . . BBCode tags added.
  11. Hi. I'm new to php. I created a register, log in, welcome, and log out page for my site. They are all working accordingly. I'm having one problem that I can't seem to fix. I would like to stay logged in as I navigate other pages of my site. Everytime i click on a link to another page within my site I get logged out. I know this issue might pertain to using session but thats all I was able to find using google search. Can anyone help? Much appreciated.
×
×
  • 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.