session variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
monel
Forum Newbie
Posts: 5
Joined: Thu Aug 26, 2004 5:20 am
Location: Bulgaria

session variables

Post by monel »

ImageBech100 | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

I have login frame on my page and I need to fill two fields to log registered users.If it is successfull a want to start a session and register these two variables.I need a sign out button to appear instead of the fields,  otheswise show the login form again.It works but the registered variables do not pass to the other frames:((
Here is the code:

Code: Select all

<?
require("functions.php");
session_start();
$_session['vn']="$vn"; 
$_session['egn']="$egn"; 
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>toolbar4e</TITLE>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1251'>
<link href='style.css' rel='stylesheet' type='text/css'></HEAD>
<BODY class='toolbar' topmargin='0' >
<FORM METHOD=POST ACTION='toolbar.php' target='toolbar'>
<table cellspacing='0' cellpadding='0' >
<tr>
	<td>
	<TABLE class='Toolbarhead' cellspacing='0' cellpadding='0'>
	<TR height='17px'>
<?php

if ((check_login($vn,$egn))==0)
	{
	echo"
	<TD >login</TD>
	</TR>
	</TABLE>
	<TABLE  width='140px'class='toolbar' cellspacing='0' cellpadding='0'>
	<TR >
		<TD class='normal'>
			<input type=text align=center valign=center color=#D7D5D5 value='VN' maxlength=4 name='vn' onfocus='if(this.value=='VN')this.value='';'  onblur='if(this.value=='')this.value='VN';'></input><br>
			<input type=text align='center' color=#D7D5D5 value='EGN' name='egn' maxlength=10 onfocus='if(this.value=='EGN')this.value='';' onblur='if(this.value=='')this.value='EGN';'></input>
			<input style='width:46%;text-align:center' type=submit name='loginbtn' align='center' color=#D7D5D5 value='[ Sign in]'></input>
	"; 
	}
	else 
	{
	echo"
	<TD >Log out</TD>
	</TR>
	</TABLE>
	<TABLE  width='140px'class='toolbar' cellspacing='0' cellpadding='0'>
	<TR >
		<TD class='normal'>
		<input style='width:46%;text-align:center' type=submit align='center' color=#D7D5D5 name='loginbtn' value='[Log out]'></input>
	";

	};
	?>
		</TD>
	</TR>
	</TABLE>
	</TD>
	
</tr>
<tr >
	<td>
	<BR>
<TABLE  width='136px' class='toolbar' cellspacing='0' cellpadding='0'>

	<TR >
	<TD>
		<?php 
		if ((check_login($vn,$egn))==1)
		{
		echo"
		<A class='toolbar' HREF='http://www.myweb.com/history.html' target='main'>&nbsp;Personal data</A><BR>";
		};
		?>
		<A class='toolbar' HREF='http://www.myweb.com/history.html' target='main'>&nbsp;History</A><BR>
		<A class='toolbar' HREF='http://www.myweb.com/schedule.html' target='main'>&nbsp;Schedule</A><BR>
    </TD>
</TR>

</TABLE>
</td>
</tr>
<tr>
<td >
</FORM>
</table>
</BODY>
</HTML>
?>
check_login function only checks if such user exist in the database and no session is being tarted in it:((
Can u help me??

ImageBech100 | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Please use $_SESSION[] not $_session[], that is a big difference.
monel
Forum Newbie
Posts: 5
Joined: Thu Aug 26, 2004 5:20 am
Location: Bulgaria

Post by monel »

I changed it to $_SESSION[] but now I cannot login even with existing user :(
I also tried session_register("vn");...... again it is not passed to the main frame:(
I also tried to initialize the session in check_login function -- no result

What am I doing wrong??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it appears like your code is reliant on register_globals being on, is this "feature" turn on?
monel
Forum Newbie
Posts: 5
Joined: Thu Aug 26, 2004 5:20 am
Location: Bulgaria

Post by monel »

Yes every visitor can check his own confidential data, that's because I need sessions.
it is turned on:(I checked many times:(
monel
Forum Newbie
Posts: 5
Joined: Thu Aug 26, 2004 5:20 am
Location: Bulgaria

Post by monel »

Any ideas how I can post these seeion variables to the main fraim from the toolbar????Pleaaaase
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

session_start();
print_r($_SESSION); // output ?
monel
Forum Newbie
Posts: 5
Joined: Thu Aug 26, 2004 5:20 am
Location: Bulgaria

Post by monel »

here is the output

Array ( [vn] => [egn] => )
Post Reply