PDA

View Full Version : Login Script - Video 2


cdavenport4
05-18-2007, 05:12 PM
I'm still have the issue with Video #2. My user_name and user_password are being accepted but after the header redirects me to the welcome page, the welcome page kicks me back to the login page. I'm at a loss here.

Welcome.php

require_once("connection.php"); // database connection

session_start();

if (!isset($_SESSION['id'])) {

header("location: http://www.cdavenport4.com/ProfileLogin.php");
exit;
}

$id = $_SESSION['id'];

//////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users WHERE user_id = '$id' ");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
//////////////////////////////////////////////////////////////


Any thoughts?

Davidj - has helped me out but this didn't seem to help. I really want to understand this and utilize this.

Previous Post.
http://www.dreamweaverclub.com/forum/showthread.php?t=25431

davidj
05-18-2007, 05:51 PM
post your login script

cdavenport4
05-18-2007, 07:05 PM
Thank you David...Here you go.


ProfileLogin.php:lol:

require_once("connection.php"); // database connection

session_start();

////catch field data////
$userid = $_POST['userid'];
$password = $_POST['password'];
$submitted = $_POST['submitted'];

if ($userid && $password) {
//////////////////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users WHERE user_name = '$userid' and user_password = '$password'");
$result = @mysql_query($query);
$rowAccount = @mysql_fetch_array($result);
//////////////////////////////////////////////////////////////
}

if ($rowAccount) {

$_SESSION['id'] = $rowAccount['user_id'];

header("location: http://www.cdavenport4.com/Welcome.php");
exit();

} elseif ($submitted) {

echo "<h1><center>You dont exist in the system!</center></h1><h2><center>Please Call or email the Administrator for support!</center></h2>";
}

davidj
05-18-2007, 07:16 PM
in the login page where you have...

$_SESSION['id'] = $rowAccount['user_id'];

header("location: http://www.cdavenport4.com/Welcome.php");
exit();

comment out the header and add a test echo like this...

$_SESSION['id'] = $rowAccount['user_id'];

echo $_SESSION['id']."-test";

//header("location: http://www.cdavenport4.com/Welcome.php");
//exit();

then run the page and tell me what displays when you login

cdavenport4
05-18-2007, 07:26 PM
Just incase here is the MySql database information...

149

cdavenport4
05-18-2007, 07:37 PM
I get "1-test" on the ProfileLogin.php page.

davidj
05-18-2007, 07:44 PM
ok so we know the login is working properly

ok return the login back to its original and lets look at the welcome page

where you have...

if (!isset($_SESSION['id'])) {

header("location: http://www.cdavenport4.com/ProfileLogin.php");
exit;
}

try this...

if (! isset($_SESSION['id'])) { //<< notice the gap between the ! and isset

echo "logout";

//header("location: http://www.cdavenport4.com/ProfileLogin.php");
//exit;
}

cdavenport4
05-18-2007, 07:55 PM
Ok?! :-?

I get the welcome page with the "logout" echoed at the top of the page.

davidj
05-18-2007, 08:03 PM
ok

change to this...


if (! isset($_SESSION['id'])) { // << notice the gap between the ! and isset

echo $_SESSION['id']."logout";

//header("location: http://www.cdavenport4.com/ProfileLogin.php");
//exit;
}

cdavenport4
05-18-2007, 08:10 PM
I'm still getting the "Logoff" at the top of the Welcome.php page.

This is what I was afraid of, It's not passing the "id" information to the next page. <at least that's what I'm thinking>.


Welcome.php

require_once("connection.php"); // database connection

session_start();

if (! isset($_SESSION['id'])) {

echo $_SESSION['id']."logout";
//header("location: http://www.cdavenport4.com/ProfileLogin.php");
//exit;

davidj
05-18-2007, 08:14 PM
ok in your login where you have your header


header("location: http://www.cdavenport4.com/Welcome.php");


change to this..

header("location:Welcome.php");


also return the welcome page back to the original

cdavenport4
05-18-2007, 08:36 PM
This didn't work either. I keep getting the login page. Could there be a problem with the php.ini? A setting of some sort?

davidj
05-18-2007, 08:44 PM
are you using a unix server

cdavenport4
05-18-2007, 08:53 PM
I'm on a linux box.

davidj
05-18-2007, 08:54 PM
chmod your remote directory to 777

then try again

cdavenport4
05-18-2007, 09:11 PM
This is something I believe I don't have any control of. I'm using 1&1.com for hosting.

davidj
05-18-2007, 09:16 PM
im at a loss

when you FTP the files select all the files and right click (do this from your FTP client)

there should be a rights option (you may have to select the files individually)

make sure each file has read write and execute rights for everyone

I dont know what else to advise... sorry

cdavenport4
05-19-2007, 02:24 AM
Ok, neither of us are crazy... I found this article :arrow: http://drupal.org/node/102114 The version of PHP I'm using is 5.2.1. Just though you should know.

Thank You for all your help, David. 8-)

cdavenport4
05-20-2007, 06:04 PM
Disregard my last post - I'm still learning.
---------------------------------------------------

I figured out my problem!!!! With a lot of searching on the web. I found someone with the same problem as me.

In the PHP.INI the session.save_path was set for this - "/var/php_sessions" This folder didn't exist.

I just though I would share my discovery!!!

davidj
05-20-2007, 08:46 PM
excellent
im pleased you sorted it.
never had anyone have that problem before so saved the solution in my memory.