Old 07-15-2009, 02:06 AM   #1
drummer392
Brandon R. Ray
 
drummer392's Avatar
Fla Box Session not working

OKay. So I am using the same server and coding that I always use to connect to the database and start a session when a user logs into a CMS I have. Now, all I have done is copy all of the files onto another domain like I usually do, but this time it's not working. I am pretty sure that the session is not holding for some reason because I told it to send me to a certain spot if there is not a session currently started on the index page.

Maybe something is wrong with my code?

This is the submit page from the login that should make the session start and usually holds is across multiple pages:
PHP Code:
<?php
$username 
"user";
$password "pass";
$database "db0";
$hostname "host"

//connection to the database
$handle mysql_connect($hostname$username$password$database)
 or die(
"");
echo 
"";

//select a database to work with
$selected mysql_select_db("db0",$handle)
  or die(
"Could not select db0");

session_start();
$usernamelog $_POST['username'];
$passwordlog sha1($_POST['password']);
$query="SELECT username,password FROM users WHERE username='".$usernamelog."' and password='".$passwordlog."'";
$result mysql_query($query) or die(mysql_error() . " ------ " $query);


if(!
$result) {
$err=mysql_error();
print 
$err;
exit();
}
if(
mysql_affected_rows()==0){
header('Location: login2.php');

exit();
}
else{
$_SESSION['username2009'] = $usernamelog;
$variable $_SESSION['username2009'];
$result mysql_query("SELECT is_admin FROM users WHERE username = '$variable'")
or die(
mysql_error());  
$data mysql_fetch_array($resultMYSQL_BOTH);

if ( 
$data['is_admin'] == ) {
header('Location:  URL');
echo 
$data['is_admin'];
}
else if ( 
$data['is_admin'] == 1) {
header('Location: URL');

else if ( 
$data['is_admin'] == 2) {
header('Location: URL');
}
}
?>
And here is the index.php page that sees if there is a session:
PHP Code:
if(!$_SESSION['username2009']){
    include (
"URL");
    exit();

Thanks so much. I am really stressing on this because it always works!
drummer392 is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 07-15-2009, 09:56 AM   #2
simplistik
PseudoMex
 
simplistik's Avatar
Location Tallahassee, FL

Posts 9,960
hrmm ... i think your if else statement is wrong. i could be mistaken but i think
Code:
mysql_affected_rows()==0
is the problem. i THINK mysql_affected_rows() only works if you did some sort of manipulation to the database, e.g. delete,insert or update. at least that's the only i've ever used it, or even seen it used. what you want if you're doing a regular select query is

Code:
mysql_num_rows() == 0
----------------

this won't affect the session but i'd also suggest not using MYSQL_BOTH in your fetch. chances are you will never use something like

Code:
$data[0]
over

Code:
$data['is_admin']
just stick w/ MYSQL_ASSOC

__________________
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
simplistik is offline   Reply With Quote
Old 07-15-2009, 10:16 AM   #3
drummer392
Brandon R. Ray
 
drummer392's Avatar
hmm. You were right about being mistaken, but it's cool. That just made it not find the information in the database and tell so. lol.

The problem is, I have just copied the same login code that always works on the same 1and1.com hosting service. Then when I login, the index page sees if there was a session started. But it always redirects me now. All my other CMS's are still working fine.

To make matters more interesting, I tried doing a cookie, and that didn't even work. I have read something about the php.ini file maybe not functioning properly?

Anyhow, thanks for reading simplistik, I know I am just a mediocre PHP programmer, but I am learning!
drummer392 is offline   Reply With Quote
Old 07-15-2009, 10:47 AM   #4
simplistik
PseudoMex
 
simplistik's Avatar
Location Tallahassee, FL

Posts 9,960
then i guess you should start small and make a tiny script that just tries to set a session
PHP Code:
<?php
session_start
();
$_SESSION['foo'] = 'bar';
?>
and then check to see if it set

__________________
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
simplistik is offline   Reply With Quote
Old 07-15-2009, 10:57 AM   #5
drummer392
Brandon R. Ray
 
drummer392's Avatar
weirdest thing just happened...it started working. I didn't change anything...hmm
drummer392 is offline   Reply With Quote
Old 07-15-2009, 11:01 AM   #6
simplistik
PseudoMex
 
simplistik's Avatar
Location Tallahassee, FL

Posts 9,960
Quote:
Originally Posted by drummer392 View Post
hmm. You were right about being mistaken, but it's cool. That just made it not find the information in the database and tell so
cause you didn't use the function right then ... it should be mysql_num_rows($result) if you're doing that

__________________
Let us live so that when we come to die even the undertaker will be sorry. - Mark Twain
Don't PM me your CSS, xHTML, JS or PHP questions. I will not reply to ANY IE6 questions.
simplistik is offline   Reply With Quote
Old 07-15-2009, 11:02 AM   #7
drummer392
Brandon R. Ray
 
drummer392's Avatar
haha...okay man. I will fix that too! I really appreciate your help!
drummer392 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:12 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com