session_start()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
preston2003
Forum Newbie
Posts: 2
Joined: Fri Apr 08, 2005 9:34 am

session_start()

Post by preston2003 »

I built a authentication database with MySQL 5.0.3 and PHP 4.3.12 dev using Apache2 and when I get to login page and submit my user and pass the database sees my authentication, but then i am supposed to go to anoth session of the site. Instead the login session keeps looping back to login again. I need help...

Thanks

Code: Select all

<?php
session_start();
if ((isset($_SESSIONї'admin_logged']) &&
      $_SESSIONї'admin_logged'] != &quote;&quote;) ||
	(isset($_SESSIONї'admin_password']) &&
	  $_SESSIONї'admin_password'] != &quote;&quote;)) {
  include &quote;logged_admin.php&quote;;
} else {
  include &quote;unlogged_admin.php&quote;;
}
?>

Code: Select all

<?php
$conn = mysql_connect(&quote;localhost&quote;, &quote;some_user&quote;, &quote;some_pass&quote;)
  or die(mysql_error());
$db = mysql_select_db(&quote;some_db&quote;)
  or die(mysql_error());
?>

Code: Select all

<?php
if ((isset($_SESSIONї'admin_logged']) &&
	  $_SESSIONї'admin_logged']) != &quote;&quote; ||
	(isset($_SESSIONї'admin_password']) &&
	  $_SESSIONї'admin_password'] != &quote;&quote;)) {
   //Do Nothing!
} else {
  $redirect = $_SERVERї'PHP_SELF'];
  header(&quote;Refresh: 5; URL=admin_login.php?redirect=$redirect&quote;);
  echo &quote;You are currently not logged in, we are redirecting you, &quote; .
  	   &quote;be patient!<br>&quote;;
  echo &quote;(If your browser doesn't support this, &quote; .
      &quote;<a href=\&quote;admin_login.php?redirect\&quote;>Click here</a>&quote;;
  die();
}
?>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Post by Jade »

If it keeps saying that you need to login again then its a problem with initiating the session. Remember that you have to set the session to a value:

$_SESSION['admin_pass'] = $_GET['pass'];
$_SESSION['admin_log'] = $_GET['logged'];

This assumes that you are posting the data from a form. If your sessions aren't being set to a value then when you go to the next page and it checks the isset($_SESSION['admin_pass'] then it will return null
preston2003
Forum Newbie
Posts: 2
Joined: Fri Apr 08, 2005 9:34 am

session_start() example

Post by preston2003 »

So in the example below will be what?

if ((isset($_SESSION['admin_logged']) &&
$_SESSION['admin_logged'] != "") ||
(isset($_SESSION['admin_password']) &&
$_SESSION['admin_password'] != "")) {
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: session_start() example

Post by Jade »

preston2003 wrote:So in the example below will be what?

if ((isset($_SESSION['admin_logged']) &&
$_SESSION['admin_logged'] != "") ||
(isset($_SESSION['admin_password']) &&
$_SESSION['admin_password'] != "")) {

if $_SESSION['admin_logged'] or $_SESSION['admin_password'] have not been set to a value then that is why you are being logged out even if the member enters the correct login information.

Jade
Post Reply