need help bad, going nuts

I am building a music community website, been working on it for over a month, I am now stuck.

The registration works fine, everything gets written to the database, including the id info, which is what I am having problems with.

I am using a flash header to login, the flash movie also uses a php script to detect wether or not u are logged in, if not it displays email and password fields, if u are logged in, it displays three buttons, view, edit, and logout, now here is where I am having problems, when I log in, go to the profile.php page, there is nothing, none of the info written to the database is showing up, it does show up if I manually put the id number into the page, but not through the php scripting, a couple of guys and myself have been trying to debug it over at sitepoint, but all we could figure out is that it is not grabbing and implementing the id properly, so I put in some code to show me where the id comes from and where it becomes invalid, and this is what it output:

id from SESSION:
id after ` filter: 0
Invalid member

now obviously this means that the session was never even started properly, so here is my php code for the profile.php page, I am omitting the html since that (as of yet) is not causing a problem.

[php]<?php
session_start();

include_once “scripts/connect_to_mysql.php”;

$id = “”;
$username = “”;
$firstname = “”;
$lastname = “”;
$country = “”;
$state = “”;
$city = “”;
$zip = “”;
$bio_body = “”;
$bio_body = “”;
$website = “”;
$youtube = “”;
$user_pic = “”;
$blabberDisplayList = “”;

if (isset($_GET[‘id’])) {
echo "id from GET: " . $_GET[‘id’] . “
”; //debug
$id = (int) $_GET[‘id’];

} else if (isset($_SESSION[‘id’])) {
echo "id from SESSION: " . $_SESSION[‘id’] . “
”; //debug
$id = (int) $_SESSION[‘id’];

} else {

include_once “index.php”;
exit();
}
$id = str_replace(’', '', $id); echo "id after filter: $id
"; //debug

$id = (int)$id;
if( $id == 0 ) {
exit(‘Invalid member’);
}

$sql = mysql_query(“SELECT * FROM myMembers WHERE id=$id”);

while($row = mysql_fetch_array($sql)){

$username = $row["username"];
$firstname = $row["firstname"];
$lastname = $row["lastname"];
$country = $row["country"];	
$state = $row["state"];
$city = $row["city"];
$zip = $row["zip"];
$email = $row["email"];
//$email = "<a href=\"mailto:$email\"><u><font color=\"#006600\">Mail</font></u></a>";	
$sign_up_date = $row["sign_up_date"];
$sign_up_date = strftime("%b %d, %Y", strtotime($sign_up_date));
$last_log_date = $row["last_log_date"];
$last_log_date = strftime("%b %d, %Y", strtotime($last_log_date));	
$bio_body = $row["bio_body"];	
$website = $row["website"];
$youtube = $row["youtube"];

$check_pic = "members/$id/image01.jpg";
$default_pic = "members/0/image01.jpg";
if (file_exists($check_pic)) {
$user_pic = "<img src=\"$check_pic\" width=\"300px\" />";
} else {
$user_pic = "<img src=\"$default_pic\" width=\"300px\" />";
}

if ($youtube == "") {
$youtubeChannel = "<br />This user has no YouTube channel yet.";
} else {
$youtubeChannel = ' <script src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/youtube.xml&amp;up_channel=' . $youtube . '&amp;synd=open&amp;w=290&amp;h=370&amp;title=&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>  '; 
}	

}
$style_sheet = “default”;

?>[/php]

For login I use cookies. Find it easier to use than sessions, but people have to have cookies enabled. Which most people do.

[php] setcookie (‘name of cookie’, $variablestored, time()+6060, ‘/’, ‘’);[/php]
time()+60
60 means 60seconds times 60 minutes, so 1 hour.
606024 = 1 day.

Check if cookie is set.
[php]if(isset($_COOKIE[‘name of cookie’])) {[/php]

Logging out
[php]setcookie(‘name of cookie’, ‘$variablestored’, time()-60*60, ‘/’, ‘’);[/php]

For your issue, you check the database entry SELECT id WHERE username = ‘$_COOKIE[‘name of cookie’]’
Then you can return a link being profile.php?id=50

Thats just if you wanted to use cookies.
Hope its useful for you. I’m sure someone else can shed some light on sessions more than I could.

Sponsor our Newsletter | Privacy Policy | Terms of Service