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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.