Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc
Comunitatea PHP Romania
 

Transmiterea variabilelor de sesiune
Vezi mesajul original

 
       Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc -> PHP Incepători
Subiectul anterior :: Subiectul următor  
Autor Mesaj
Lions



Data înscrierii: 08/Mar/2005
Mesaje: 4

Trimis: Mar Mar 08, 2005 5:09 pm    Titlul subiectului: Transmiterea variabilelor de sesiune  

Am si eu o problema.Invat despre sesiunile in php din cartea:"Dezvoltarea aplicatiilor web cu php si Mysql". Folosesc nusphere techplat(contine: apache, php4 si Mysql 3).Am incercat scripturile pe care le atasez mai jos.
In primul script se realizeaza autentificarea:dupa ce introduc userul si parola imi apare esti autentificat cu numele "userid".Dar in momentul cand dau logout imi apare ca sunt neautentificat.Deci practic variabila de sesiune din primul script nu se transmite in scriptul doi.Am citit o multime de pareri potrivit carora ar trebui sa modific php.ini.
ok.Am register golbal=on.Am setat directorul pt sesiuni.(Cred ca l-am setat bine).
Alta parere este ca sa nu folosesc:$hhtp_SESSION_VARS['var'] ci sa folosesc
$_SESSION['var'], sau ceva de genul.(Nu merge)
Am mai citit ca daca este php-ul mai vechi nu mai folosesc chestiunile de mai sus ci folosesc cu session_register().Asta nu am inteles.
Mai este si o vrajeala tot pe la sesiuni: sa zicem ceva de genul: link.php?.variabila(nu stiu).
Sper sa ma puteti ajuta.Va multumesc anticipat.


auth.php
<?php
session_start();

if (isset($HTTP_POST_VARS['userid']) && isset($HTTP_POST_VARS['password']))
{
// if the user has just tried to log in
$userid = $HTTP_POST_VARS['userid'];
$password = $HTTP_POST_VARS['password'];

$db_conn = mysql_connect('localhost', 'webauth', 'webauth');
mysql_select_db('auth', $db_conn);
$query = 'select * from auth '
."where name='$userid' "
." and pass=password('$password')";
$result = mysql_query($query, $db_conn);
if (mysql_num_rows($result) >0 )
{
// if they are in the database register the user id
$HTTP_SESSION_VARS['valid_user'] = $userid;
}
}
?>
<html>
<body>
<h1>Home page</h1>
<?
if (isset($HTTP_SESSION_VARS['valid_user']))
{
echo 'You are logged in as: '.$HTTP_SESSION_VARS['valid_user'].' <br />';
echo '<a href="logout.php">Log out</a><br />';
}
else
{
if (isset($userid))
{
// if they've tried and failed to log in
echo 'Could not log you in';
}
else
{
// they have not tried to log in yet or have logged out
echo 'You are not logged in.<br />';
}

// provide form to log in
echo '<form method="post" action="authmain.php">';
echo '<table>';
echo '<tr><td>Userid:</td>';
echo '<td><input type="text" name="userid"></td></tr>';
echo '<tr><td>Password:</td>';
echo '<td><input type="password" name="password"></td></tr>';
echo '<tr><td colspan="2" align="center">';
echo '<input type="submit" value="Log in"></td></tr>';
echo '</table></form>';
}
?>
<br>
<a href="members_only.php">Members section</a>
</body>
</html>


logout.php

<?php
session_start();

$old_user = $HTTP_SESSION_VARS['valid_user']; // store to test if they *were*
logged in
unset($HTTP_SESSION_VARS['valid_user']);
session_destroy();
?>
<html>
<body>
<h1>Log out</h1>
<?php
if (!empty($old_user))
{
echo 'Logged out.<br />';
}
else
{
// if they weren't logged in but came to this page somehow
echo 'You were not logged in, and so have not been logged out.<br />';
}
?>
<a href="authmain.php">Back to main page</a>
</body>
</html>


Deci nu se transmite variabila valid_user.
Sus  
boo



Data înscrierii: 24/Mar/2004
Mesaje: 223
Locație: Ploiesti

Trimis: Mar Mar 08, 2005 5:20 pm    Titlul subiectului:  

http://www.phpromania.net/forum/viewtopic.php?p=9736&highlight=session#9736
Sus  
PHPRomania Bot
Bot Member


Data înscrierii: 27/Dec/2007
Mesaje: 1
Locaţie: Server Google
Trimis: Mie Dec 26, 2007 7:01 pm   Titlul subiectului: Ad  

Sus  
 
       Pagina de start a forumului Forum PHP Romania - Discutii despre PHP, MySQL, Javascript, AJAX, etc -> PHP Incepători
Pagina 1 din 1


Powered by phpBB 2.0.22 © 2001, 2002 phpBB Group
Varianta în limba română: Romanian phpBB online community