Jump to content

PHP Session Help


dalerex

Recommended Posts

Hi All,

 

I was wondering if anyone here can help me out. I'm in the process of creating a simple social networking website with some very basic code. I'm currently stuck at a point where if my users log in, I am not able to pass their credentials from one page to another. The session doesn't pass properly. I have attached the codes for your review. Please let me know what I'm doing wrong. Any and all help is appreciated.

 

Thanks,

dalerex

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/142577-php-session-help/
Share on other sites

You can try removing the caps <HTML> tag on member-profile.php. You already have a tag above that line.

<html xmlns="http://www.w3.org/1999/xhtml">

<HTML> // you can remove this.

 

and also try adding

<?php session_start(); ?> 

 

on top of your member-profile.php page

 

Ex:

<?php session_start(); ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Strike A Style.com - My Profile</title>

 

Try it out.  ;)

 

Regards,

Link to comment
https://forums.phpfreaks.com/topic/142577-php-session-help/#findComment-747212
Share on other sites

Shouldn't this:

 

//Check whether the query was successful or not
if($result) {
	if(mysql_num_rows($result) == 1) {
		//Login Successful
		session_regenerate_id();
		$member = mysql_fetch_assoc($result);
		$_SESSION["member_id"] = $member_id;
		$_SESSION["firstname"] = $firstname;
		$_SESSION["lastname"] = $lastname;
		$_SESSION["login"] = $login;
		$_SESSION["sex"] = $sex;
		$_SESSION["month"] = $month;
		$_SESSION["day"] = $day;
		$_SESSION["city"] = $city;
		$_SESSION["country"] = $country;
		header("location: profile.php?id=$login");
		exit();

 

Be this:

 

//Check whether the query was successful or not
if($result) {
	if(mysql_num_rows($result) == 1) {
		//Login Successful
		session_regenerate_id();
		$member = mysql_fetch_assoc($result);
		$_SESSION["member_id"] = $member['member_id'];
		$_SESSION["firstname"] = $member['firstname'];
		$_SESSION["lastname"] = $member['lastname'];
		$_SESSION["login"] = $member['login'];
		$_SESSION["sex"] = $member['sex'];
		$_SESSION["month"] = $member['month'];
		$_SESSION["day"] = $member['day'];
		$_SESSION["city"] = $member['city'];
		$_SESSION["country"] = $member['country'];
		header("location: profile.php?id=$login");
		exit();

 

In the future just post the code that you are having problems with. Also, you need to say more than it didn't work. you need to tell us what didn't work, if you got any errors, etc. All I did there was change the sessions to get the data from the database. An easier was to see if your values are getting set is to just echo them to make sure.

Link to comment
https://forums.phpfreaks.com/topic/142577-php-session-help/#findComment-753485
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.