Jump to content

Problem with sessions


mike_g

Recommended Posts

I have a php page that checks logins, and if correct sets some fields in the session. My problem is that when i go back to the original page the variables in the session dont seem to have stayed set.Heres part of my page header:

<?php 	include('../Functions.php');	include('../CodeFunction.php');	include('../postdata.php');	session_start(); 		if(!isset($_SESSION['username']))	{			$_SESSION['username']="";		$_SESSION['password']="";	}?>

Heres a function called that adds either a login, or reply box:

	function AddPostData($topic)	{			$link = mysql_connect("10.13.7.1","michael","m");		mysql_select_db("michael1");		$result = mysql_query("SELECT * FROM posts WHERE title='$topic'");		while($row = mysql_fetch_object($result))		{			AddPost($row);		}		mysql_close($link);		mysql_free_result($result); 			//if(!session_is_registered('username'))		if($_SESSION['username'] == "")			AddLogin();		else			AddResponse();		}

And heres my check login script (which is a seperate page):

<?php// This code was grabbed from:  http://www.phpeasystep.com/workshopview.php?id=6ob_start();// Connect to server and select databse.mysql_connect("10.13.7.1","michael","m")or die("cannot connect");mysql_select_db("michael1")or die("cannot select DB");// Define $myusername and $mypassword$u=$_POST['uname'];$p=$_POST['pword'];$sql="SELECT * FROM users1 WHERE username='$u' and password='$p'";$result=mysql_query($sql);$count=mysql_num_rows($result);if($count==1){	//session_register("username");	//session_register("password");	$_SESSION["username"]=$u;	$_SESSION["password"]=$p;}ob_end_flush();header('Location: Pages/01_Index.php');?>

When I return to the main page after logging in why arent 'username' and 'password' set in the session?Thanks.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...