Jump to content

Worst PHP experience :(


captaintyson

Recommended Posts

I've been having so much trouble with this login.

It's saying its logged in but its not showing up...

login success:

<?php 
session_start();
if(!session_is_registered($PID) AND !session_is_registered($pwd)){
header("location:index.php?m=worked");
}
?>

Part where its not showing the Member Center on index.php?m=worked

<?php
if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])) {   ?><div id="loginbox">
<span style="font-size:14px;">Pilot Login</span><br><br>
<form name="form1" method="post" action="includes/checklogin.php">
  PID: 
  <label>
    <input type="text" name="PID" id="PID" size="5" maxlength="4">
  </label>
  <br>PIN:<?php echo $_SESSION['PID']; ?>
  <label>
    <input type="text" name="pwd" id="pwd" maxlength="30">
  </label>
  <br>
  <label>
    <input type="submit" name="submit" id="submit" value="Login">
  </label>
</form>
<br>
<div align="center">Forgot Password | Join Here</div>
</div><?php } else{ ?><li>
<h2>Member Center</h2>
          <ul>
            <li><a href="#">Aliquam libero</a></li>
            <li><a href="#">Consectetuer adipiscing elit</a></li>
            <li><a href="#">Metus aliquam pellentesque</a></li>
            <li><a href="#">Suspendisse iaculis mauris</a></li>
            <li><a href="#">Proin gravida orci porttitor</a></li>
            <li><a href="#">Aliquam libero</a></li>
          </ul>
        </li>
<?php } ?>

Link to comment
Share on other sites

session_is_registered is deprecated. So this....

 

<?php 
session_start();
if(!session_is_registered($PID) AND !session_is_registered($pwd)){
header("location:index.php?m=worked");
}
?>

 

should be....

 

<?php 
session_start();
if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])){
header("location:index.php?m=worked");
}
?>

 

And your other snippet needs a call to session_start.

Link to comment
Share on other sites

And here's check login, starting to think it's a problem with this:

<?php
$host="asdfsdf"; // Host name 
$username="asdfsadfdsfasdf"; // Mysql username 
$password="asdf"; // Mysql password 
$db_name="asdf"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$PID = $_POST['PID']; 
$pwd = $_POST['pwd'];



$sql="SELECT * FROM Roster WHERE PID='$PID' and pwd='$pwd'";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count > 0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("PID");
session_register("pwd"); 
header("location:login_success.php");
echo 'Login Worked';
}
else {
mysql_error();
header("location:index.php?page=crew");;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Loading</title>
</head>

<body>
</body>
</html>

Link to comment
Share on other sites

So that means I need to make my login success and home page

<?php 
session_start();
if(!session_is_registered($_SESSION['PID']) AND !session_is_registered($_SESSION['pwd'])){
header("location:index.php?m=worked");
}
?>

to this

<?php 
session_start();
if(!session_is_registered($_SESSION[$PID]) AND !session_is_registered($_SESSION[$pwd])){
header("location:index.php?m=worked");
}
?>

Link to comment
Share on other sites

So that means I need to make my login success and home page

<?php 
session_start();
if(!session_is_registered($_SESSION['PID']) AND !session_is_registered($_SESSION['pwd'])){
header("location:index.php?m=worked");
}
?>

to this

<?php 
session_start();
if(!session_is_registered($_SESSION[$PID]) AND !session_is_registered($_SESSION[$pwd])){
header("location:index.php?m=worked");
}
?>

 

No.

 

<?php 
session_start();
if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])){
  header("location:index.php?m=worked");
}
?>

Link to comment
Share on other sites

Thanks so far for your help guys. It means allot when you've been up for 5 hours strait working on the same problem.

 

Still not working, but let me get each page up to make sure I didn't miss anything.

 

Panel.php:displays the login and when logged in the members area

<?php
session_start();
if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])) {   ?><div id="loginbox">
<span style="font-size:14px;">Pilot Login</span><br><br>
<form name="form1" method="post" action="checklogin.php">
  PID: 
  <label>
    <input type="text" name="PID" id="PID" size="5" maxlength="4">
  </label>
  <br>Password:<?php echo $_SESSION['PID']; ?>
  <label>
    <input type="password" name="password" id="password" maxlength="30">
  </label>
  <br>
  <label>
    <input type="submit" name="submit" id="submit" value="Login">
  </label>
</form>
<br>
<div align="center">Forgot Password | Join Here</div>
</div><?php } else{ ?><li>
<h2>Pilot Center</h2>
          <ul>
            <li><a href="#">Aliquam libero</a></li>
            <li><a href="#">Consectetuer adipiscing elit</a></li>
            <li><a href="#">Metus aliquam pellentesque</a></li>
            <li><a href="#">Suspendisse iaculis mauris</a></li>
            <li><a href="#">Proin gravida orci porttitor</a></li>
            <li><a href="#">Aliquam libero</a></li>
          </ul>
        </li>
<?php } ?>

Check login:

<?php
$host="asdfasdf.asdf.com"; // Host name 
$username="adsf"; // Mysql username 
$password="asdfadsf"; // Mysql password 
$db_name="asdf"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$PID = $_POST['PID']; 
$pwd = $_POST['password'];



$sql="SELECT * FROM `Roster` WHERE PID=$PID and pwd=$pwd";
$result=mysql_query($sql) or die(mysql_error());

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count > 0){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['PID'] = $PID;
$_SESSION['pwd'] = $pwd;
header("location:login_success.php");
echo 'Login Worked';
}
else {
mysql_error();
header("location:index.php?page=crew");;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Loading</title>
</head>

<body>
</body>
</html>

Login success:

<?php 
session_start();
if(!isset($_SESSION['PID']) AND !isset($_SESSION['pwd'])){
  header("location:index.php?m=worked");
}
?>

Link to comment
Share on other sites

Your query would be failing for sure. Try this....

 

<?php

$host="asdfasdf.asdf.com"; // Host name 
$username="adsf"; // Mysql username 
$password="asdfadsf"; // Mysql password 
$db_name="asdf"; // Database name 


// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from signup form 
$PID = mysql_real_escape_string($_POST['PID']); 
$pwd = mysql_real_escape_string($_POST['password']);

$sql = "SELECT * FROM `Roster` WHERE PID='$PID' and pwd = '$pwd'";
if ($result=mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    $_SESSION['PID'] = $PID;
    $_SESSION['pwd'] = $pwd;
    header("location:login_success.php");
    exit();
  } else {
    echo "Username / Password does not match";
  }
} else {
  trigger_error(mysql_error());
}

?>

 

Are you sure your passwords aren't hashed? They should be.

Link to comment
Share on other sites

Just checked error logs.. dont know what any of this means

PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 2 
PHP Parse error:  syntax error, unexpected $end in /hermes/bosweb/web164/b1644/ipg.icelandvacom/src/joincomplete.php on line 151 
PHP Warning:  Unknown: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in Unknown on line 0 
PHP Warning:  Unknown: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/php_sessions) in Unknown on line 0 

Link to comment
Share on other sites

Why isn't it saving sessions to (the default) /tmp? Are permissions set up properly in /var/php_sessions? CHMODDED to 755 should be sufficient, although i'm not sure if it is your direct problem as it should have warned you up front if the session could not be created.

 

Add the following lines above session_start(); :

ini_set('display_errors',1);
error_reporting(E_ALL);

 

And see if it reports any errors.

Link to comment
Share on other sites


Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php:4) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4

Link to comment
Share on other sites


Warning: session_start() [function.session-start]: open(/var/php_sessions/sess_e03e53657824366c7463fab135e7c2c9, O_RDWR) failed: No such file or directory (2) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php:4) in /hermes/bosweb/web164/b1644/ipg.icelandvacom/index.php on line 4

 

And there ya go. Are you ouputting anything, including whitespace (Newline/Space/HTML) before session_start() ? This will cause the session cookie to be voided, as headers are being sent after content.

Link to comment
Share on other sites

I don't have any white space is the problem. Even when I take out that snippit you gave me. And It's also saying undefined index?

 

At what lines is the undefined index? That error is usually called when in 'strict' error mode and is usually not the problem, but for some reason PHP cannot set the cookie for the session. It states headers have already been sent, which just leads you back to whitespace beforehand..

Link to comment
Share on other sites

I don't have any white space is the problem. Even when I take out that snippit you gave me. And It's also saying undefined index?

 

At what lines is the undefined index? That error is usually called when in 'strict' error mode and is usually not the problem, but for some reason PHP cannot set the cookie for the session. It states headers have already been sent, which just leads you back to whitespace beforehand..

Line 4.. which is session start. :\ Could it be the server I'm on?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.