# Problem with Session Variables

**URL:** <https://www.phphelp.com/t/problem-with-session-variables/20005>\
**Category:** Beginners - Learning PHP\
**Created:** [April 7, 2013, 7:02pm UTC](https://www.phphelp.com/t/problem-with-session-variables/20005 "2013-04-07T19:02:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xerxes](https://www.phphelp.com/user_avatar/www.phphelp.com/xerxes/32/386_2.png) [@xerxes](https://www.phphelp.com/u/xerxes)\
**Post date:** [April 7, 2013, 7:02pm UTC](https://www.phphelp.com/t/problem-with-session-variables/20005/1 "2013-04-07T19:02:45Z")

</div>

Hi,

I’m trying to create a login page. Here’s my code:

[php]  
if (isset($\_POST[“Submit”])){  
$strUser = funcStripText($\_POST[“txtUser”]);  
$strPass = funcStripText($\_POST[“txtPass”]);

```
if (($strUser != "")&&($strPass != "")){
	$rsRow = mysqli_query($connBike, "SELECT UserID FROM tbl_Users WHERE Username='" . $strUser . "' AND UserPass='" . $strPass ."'");
	if (mysqli_num_rows($rsRow)>0){
		$rsDetails = mysqli_fetch_assoc($rsRow);
		mysqli_free_result($rsRow);
		mysqli_close($connBike);
		
		session_start();
		$_SESSION["UserID"] = $rsDetails["UserID"];
		$intStatus = 1;
	}
	else{
		$intStatus = 2;
	}
}

```

}  
[/php]

This seems to work fine, but as soon as I navigate to another page in the site it logs me out, almost as if there’s a session\_destroy() on every other page, which there isn’t.

Any ideas what I’m missing?

---

<div class="post-metadata">

**Author:** ![Thiago](https://www.phphelp.com/user_avatar/www.phphelp.com/thiago/32/868_2.png) [@Thiago](https://www.phphelp.com/u/Thiago)\
**Post date:** [April 7, 2013, 8:32pm UTC](https://www.phphelp.com/t/problem-with-session-variables/20005/2 "2013-04-07T20:32:47Z")

</div>

Hello, How you described the problem, i think in the another page you don’t started the session again, always that you redirect to another page, you need to session\_start… But if it isn’t the problem, please, explain me better the problem…

---

<div class="post-metadata">

**Author:** ![xerxes](https://www.phphelp.com/user_avatar/www.phphelp.com/xerxes/32/386_2.png) [@xerxes](https://www.phphelp.com/u/xerxes)\
**Post date:** [April 7, 2013, 9:34pm UTC](https://www.phphelp.com/t/problem-with-session-variables/20005/3 "2013-04-07T21:34:06Z")

</div>

OK, so I need session\_start(); on each page within the site.

Thanks very much, working perfectly now. 🙂

---

<div class="post-metadata">

**Author:** ![Thiago](https://www.phphelp.com/user_avatar/www.phphelp.com/thiago/32/868_2.png) [@Thiago](https://www.phphelp.com/u/Thiago)\
**Post date:** [April 7, 2013, 9:46pm UTC](https://www.phphelp.com/t/problem-with-session-variables/20005/4 "2013-04-07T21:46:32Z")

</div>

you’re welcome 😃

---

<div class="post-metadata">

**Author:** ![Thiago](https://www.phphelp.com/user_avatar/www.phphelp.com/thiago/32/868_2.png) [@Thiago](https://www.phphelp.com/u/Thiago)\
**Post date:** [April 7, 2013, 9:48pm UTC](https://www.phphelp.com/t/problem-with-session-variables/20005/5 "2013-04-07T21:48:03Z")

</div>

If you want other help, contact me on gtalk -\> [thiago.mx2012@gmail.com](mailto:thiago.mx2012@gmail.com)
