•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 373,375 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,813 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1031 | Replies: 55
![]() |
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 165
Reputation:
Rep Power: 1
Solved Threads: 2
admin.php
validated.php
I've two pages as displayed above. I wanted to enable sessions so that the user can not go to validated.php straight without any validation. But the the code above does not create any sessions at all. The codes in validated.php is working fine and the codes in admin.php is working fine without the line 32 - 36. This line did not create/store any sessions when executed. Each time, after I log in using the correct username and password, it will redirect me bak to the index.php. Please help.
php Syntax (Toggle Plain Text)
<?php // connection to MySQL server mysql_connect('localhost','root',''); mysql_select_db('administration'); if (isset($_POST['username'])) { $loginUsername=$_POST['username']; $loginPassword=$_POST['password']; $MM_redirectLoginSuccess = "validated.php"; $MM_redirectLoginFailed = "admin.php"; $MM_redirecttoReferrer = true; $errors = array(); if(empty($_POST['username'])) { $errors[] = 'You think whom going to fill up the USERNAME for you?'; } if(empty($_POST['password'])) { $errors[] = 'You think whom going to fill up the PASSWORD for you?'; } if (empty($errors)) { $loginUsername = get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername); $password = get_magic_quotes_gpc() ? $password : addslashes($password); $LoginRS_query = "SELECT username, password FROM adminprofile WHERE username='$loginUsername' AND password='$loginPassword'"; $LoginRS = mysql_query($LoginRS_query) or die(mysql_error()); $loginFoundUser = mysql_num_rows($LoginRS); if ($loginFoundUser) { session_name ('YourVisitID'); session_start(); $_SESSION['user_id'] = $loginFoundUser[0]; $_SESSION['first_name'] = $loginFoundUser[1]; $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>"; exit(); } else { echo "<script type='text/javascript'>location.href='$MM_redirectLoginFailed';</script>"; } } mysql_close(); } ?>
validated.php
php Syntax (Toggle Plain Text)
<?php session_name ('YourVisitID'); session_start(); // Start the session. $MM_redirectLoginFailed = "admin.php"; $MM_redirecttoReferrer = true; // If no session value is present, redirect the user. if (!isset($_SESSION['agent']) OR ($_SESSION['agent'] != md5($_SERVER['HTTP_USER_AGENT'])) ) { echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>"; exit(); // Quit the script. } ?>
I've two pages as displayed above. I wanted to enable sessions so that the user can not go to validated.php straight without any validation. But the the code above does not create any sessions at all. The codes in validated.php is working fine and the codes in admin.php is working fine without the line 32 - 36. This line did not create/store any sessions when executed. Each time, after I log in using the correct username and password, it will redirect me bak to the index.php. Please help.
"I might not be the BEST but I'm not like the REST!"
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
in validated.php page, print out the session variables.
print_r($_SESSION); Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 165
Reputation:
Rep Power: 1
Solved Threads: 2
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 165
Reputation:
Rep Power: 1
Solved Threads: 2
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
Have 2 pages.
In page2.php, write this.
See if it prints test in page2.
php Syntax (Toggle Plain Text)
<?php //page1.php session_start(); $_SESSION['name']="test"; header("location: page2.php"); ?>
php Syntax (Toggle Plain Text)
<?php session_start(); print_r($_SESSION); ?>
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 165
Reputation:
Rep Power: 1
Solved Threads: 2
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
So, session exists.
Redirect to a dummy page, for eg, page2.php and have print_r($_SESSION) in it. Check if session is being passed !
Redirect to a dummy page, for eg, page2.php and have print_r($_SESSION) in it. Check if session is being passed !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 165
Reputation:
Rep Power: 1
Solved Threads: 2
•
•
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,026
Reputation:
Rep Power: 8
Solved Threads: 227
Strange! Are you sure, $loginFoundUser[0], $loginFoundUser[1], md5($_SERVER['HTTP_USER_AGENT']) have values ? I think nothing is assigned to session variables.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Email addrress in Sessions (PHP)
- Identifing all Active sessions in PHP (PHP)
- previous sessions not visible burning multisession DVDs (Storage)
- Do all programs in Windows XP compactible in Linux? (Getting Started and Choosing a Distro)
- Sharing object instances between applications (VB.NET)
- How do I create own Shout box/or input and display form? (PHP)
- Trying to create a login system (PHP)
- login script using sessions (PHP)
- Create Windows Authentication (VB.NET)
Other Threads in the PHP Forum
- Previous Thread: contains
- Next Thread: OPTION problem



Linear Mode