Jump to content

marquel2k69

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

marquel2k69's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi all I need a little help how would I code a button in php that checks to see if you are logged in for example if the button was labled "my account" if you were logged in it would take you to "my account" but if you weren't logged in on the button roll over it would say log in and to you to the log in/register page thanks in advance for any help if php isn't what I should be using what should I use
  2. I was able to get my login script working thanks for the suggestions, now that I'm able to log in how do I display Welcome $username to the header of the home page here is my login script <?php $errorMsg = ''; $username = ''; $password = ''; if (isset($_POST['username'])) { $username = $_POST['username']; $password = $_POST['password']; $remember = $_POST['remember']; $username = stripslashes($username); $password = stripslashes($password); $username = strip_tags($username); $password = strip_tags($password); // error handling conditional checks go here if ((!$username) || (!$password)) { $errorMsg = 'Username and Password fields can not be empty!'; } else { // Error handling is complete so process the info if no errors include 'scripts/connect_to_mysql.php'; // Connect to the database $username = mysql_real_escape_string($username); // After we connect, we secure the string before adding to database $password = mysql_real_escape_string($password); // After we connect, we secure the string before adding to database $password = md5($password); // Add MD5 Hash to the password variable they supplied after filtering it // Make the SQL query $sql = mysql_query("SELECT * FROM myMembers WHERE username='$username' AND password='$password' AND email_activated='1'"); $login_check = mysql_num_rows($sql); // If login check number is greater than 0 (meaning they do exist and are activated) if($login_check > 0){ while($row = mysql_fetch_array($sql)){ $id = $row["id"]; $_SESSION['id'] = $id; $username = $row["username"]; $_SESSION['username'] = $username; $firstname = $row["firstname"]; $_SESSION['firstname'] = $firstname; mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id' LIMIT 1"); } // close while // Remember Me Section if($remember == "yes"){ setcookie("idCookie", $id, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days } // All good they are logged in, send them to homepage then exit script header("location: index.php"); exit(); } else { // Run this code if login_check is equal to 0 meaning they do not exist $errorMsg = "Username or Password incorrect, please try again"; } } // Close else after error checks } //Close if (isset ($_POST['username'])){ ?> and here is the header that I want the Welcome $username script to output to <link href="style/main.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style6 {font-size: 16px} .style7 {font-size: 18px} --> </style> <table width="950" align="center" cellpadding="0" style="height:100px; background-image:url(style/header.jpg); background-repeat:no-repeat;"> <tr> <td colspan="2"><p><span class="style6"><a href="register.php">Register an Account</a></span></p> </td> <td colspan="5" class="blueColor style7"></td> <td rowspan="2"><div align="center"><a href="#" class="style6">Log Out </a></div></td> </tr> <tr> <td colspan="7"><a href="login.php" class="style6">Log In </a></td> </tr> <tr> <td width="111"><div align="center"></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com">HOME</a></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/my_account.php">MY ACCOUNT</a> </div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/how_it_works.php">HOW IT WORKS</a> </div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/contact_us.php">CONTACT US </a></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/about.php">ABOUT</a></div></td> <td width="118"><div align="center"><a href="http://www.westoreyouscore.com/faq.php">FAQ</a></div></td> <td width="111"> </td> </tr> </table>
  3. line 40 is just a php include for the header file i'm trying to process <?php include_once"header_template.php";?>
  4. I commented out session_start() because if I don't I get this error in the browser when my page loads line 40 is where I include_once the header template that is weird to me cause its like its looping on itself
  5. Hi everyone I am trying to write a login script that lives inside of my universal header I can't get the remember me function to work nor can I start the session at the start of my script so i've commented out those lines I was able to get the script to log me in working but when I click any of the links in my header and the new page loads I think I am no longer logged in I would also like some sort of welcome text to display within the header upon successful login I've looked for answers on the web but can only find tuts on separate login page that redirects to the home page after a successful login <?php // Start Session to enable creating the session variables below when they log in //session_start(); // Initialize some vars $errorMsg = ''; $username = ''; $password = ''; if (isset($_POST['username'])) { $username = $_POST['username']; $password = $_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $username = strip_tags($username); $password = strip_tags($password); // error handling conditional checks go here if ((!$username) || (!$password)) { $errorMsg = 'The Username or the Password field cannot be empty'; } else { // Error handling is complete so process the info if no errors include 'scripts/connect_to_mysql.php'; // Connect to the database $username = mysql_real_escape_string($username); // After we connect, we secure the string before adding to query $password = mysql_real_escape_string($password); // After we connect, we secure the string before adding to query $password = md5($password); // Add MD5 Hash to the password variable they supplied after filtering it // Make the SQL query $sql = mysql_query("SELECT * FROM myMembers WHERE username='$username' AND password='$password' AND email_activated='1'"); $login_check = mysql_num_rows($sql); // If login check number is greater than 0 (meaning they do exist and are activated) if($login_check > 0){ while($row = mysql_fetch_array($sql)){ // Create session var for their raw id $id = $row["id"]; $_SESSION['id'] = $id; // Create the idx session var $_SESSION['idx'] = base64_encode("g4p3h9xfn8sq03hs2234$id"); // Create session var for their username $username = $row["username"]; $_SESSION['username'] = $username; /* Create session var for their email $useremail = $row["email"]; $_SESSION['useremail'] = $useremail;*/ // Create session var for their password $userpass = $row["password"]; $_SESSION['userpass'] = $userpass; mysql_query("UPDATE myMembers SET last_log_date=now() WHERE id='$id' LIMIT 1"); } // close while /* // Remember Me Section if($remember == "yes"){ $encryptedID = base64_encode("g4enm2c0c4y3dn3727553$id"); setcookie("idCookie", $encryptedID, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days setcookie("passCookie", $pass, time()+60*60*24*100, "/"); // Cookie set to expire in about 30 days } // All good they are logged in, send them to homepage then exit script header("location: index.php?test=$id"); exit();*/ } else { // Run this code if login_check is equal to 0 meaning they do not exist $errorMsg = "Incorrect login data, please try again"; } } // Close else after error checks } //Close if (isset ($_POST['username'])){ ?> I hope I have not violated any rule this is my first post and as you can tell i'm also a noob thanks in advance for any help
×
×
  • 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.