Jump to content

Login/Logout Script Issues


Darrish

Recommended Posts

I have a site that needs a little help with some login codes They've never really worked and I'm at my whit's end now.. I simply need a login/logout code that when users log in they see members only links. When they log out the links need to go away.

 

The codes I'm presently using DO connect to my MySQL database and once logged in you see the links. However the logout is worthless and doesn't DO anything. However on the login page it doesn't tell you you're already logged in. It will just let you do it again. I honestly just need a whole new batch of codes. It's ridiculous.

 

Sessions and cookies are all really foreign to me. I've been searching sites for months and can't find what I'm looking for. The original codes were done by my friend years ago and have been broken for almost that long.

 

Sorry for the wall of code.

 

<?

$CookieData = unserialize(stripslashes($_COOKIE['phpbb
2mysql_data']));
$myID = $CookieData['userid'];
echo "<!-- ";
var_dump($_COOKIE);
echo " -->";

?>

(id.php blah blah included on the overall header)

letting me do...


<?php if (is_numeric($myID)){?>
Member Linkage?
<? }else { ?>
Non member linkage!

<? } ?>

So that's what I'm working with as far as members only links, however, when I log in with my present login codes it doesn't...do this.

Logout:
<?
include "include/session.php";
session_unset();
session_destroy();
?>
<?
echo "<center><font face='Verdana' size='2' >Successfully logged out. <br><br> <a href=login.php>Login</a></font></center>";
?>

Login:


<form action='loginck.php' method=post>
<font face='verdana, arial, helvetica' size='2' align='center'> Login ID <BR>

<input type ='text' class='bginput' name='username' >
<BR><BR>
 Password <BR>

<input type ='password' class='btn' name='password' >

<input type='submit' value='Submit'>
</form>

newsession:
<?php

//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
$session['userid']=session_id();
$session['username']=$name;
//echo $session['username'];
?>

session:
<?php
session_start();
session_register("session");
?>

loginck:
<?
include "include/session.php";

$dbservertype='mysql';
$servername='xxxx.perfora.net';

// username and password to log onto db server
$dbusername='xxxx';
$dbpassword='xxxx';
// name of database
$dbname='xxxx';

////////////////////////////////////////
////// DONOT EDIT BELOW /////////
///////////////////////////////////////
connecttodb($servername,$dbname,$dbusername,$dbpassword);
function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
global $link;
$link=mysql_connect ("$servername","$dbuser","$dbpassword");
if(!$link){die("Could not connect to MySQL");}
mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
}
//////////////////////////////
?>
<?
$userid=mysql_real_escape_string($userid);

$name=mysql_real_escape_string($name);
$password=mysql_real_escape_string($password);

if($rec=mysql_fetch_array(mysql_query("SELECT * FROM Signup WHERE username='$username' AND Password = '$password'"))){
if(($rec['username']==$username)&&($rec['Password']==$password)){
include "include/newsession.php";
echo "<p class=data> <center>Welcome back<br></center>";
print "<script>";
print " self.location='index.php';"; // Comment this line if you don't want to redirect
print "</script>";

}
}
else {

session_unset();
echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Name and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/144326-loginlogout-script-issues/
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.