Page 1 of 1
function
Posted: Sun Dec 10, 2006 12:26 pm
by hrubos
How to do to require user's login to next_page and how to solve if output user's profile by $login ($login is setted after register).
I have $login in class ..autorizace/autorizace.php. So I don't know how to do if I would like to use it again in differrent class. (exmple class ..student/edit.php).
Posted: Sun Dec 10, 2006 12:27 pm
by John Cartwright
To be honest I'm not quite sure what your saying. Could you be as specific as possible, and posting relevant code please.
Posted: Sun Dec 10, 2006 12:42 pm
by hrubos
Jcart wrote:To be honest I'm not quite sure what your saying. Could you be as specific as possible, and posting relevant code please.
I don't understand and so I don't know how to begin???
Example , I design a web_page. How to do in code if output user's profile after loging?
And in my program, I have settet class to login, but I don't know how to use $login in the differrent class to check :
example (just I think)
..student/edit_personal.phpI want to use $login from class
autorizace/autorizace.php
Code: Select all
query = "Select first_name, last_name FROM student WHERE rc_student = '$login'
class...
autorizace/autorizace.php
Code: Select all
<?php
Header("Pragma: No-cache");
Header("Cache-Control: No-cache, Must-revalidate");
Header("Expires: ".GMDate("D, d M Y H:i:s")." GMT");
$password = $_POST['password'];
$login = $_POST['login'];
session_start();
$MC = MySQL_Connect("localhost", "root", "");
$MS = MySQL_Select_DB("Student");
if(!$password||!$login){
echo 'full of informace';
exit;
}
if(!get_magic_quotes_gpc())
{
$password = addslashes($password);
$login = addslashes($login);
}
if ((IsSet($login)) AND (IsSet($password)) ){
$p = MD5($password);
//for only admin
$MSQ = MySQL_Query("SELECT * FROM users WHERE (login LIKE '$login') AND (password LIKE '$p') ");
$num_row = mysql_num_rows($MSQ);
if ($num_row == 1) {
//prihlaseni probehlo v poradku
//fetch the data and read into array
$row = mysql_fetch_array($MSQ);
$id = $row['id'];
$isAdmin = $row['isAdmin'];
$return_array = array($id,$isAdmin);
//admin's value = 1
//user's value = 2
if($isAdmin=='1'){
echo "you are admin";
echo '<p> <a href="autorizace.php?lo=true">Odhlásit se</a> </p>';
return $return_array;
}
//user value = null
else if($isAdmin =='2' ) {
echo '<p> <a href = "http://localhost/BP/Room/reservation_display.php">Rezervace</a></p>';
echo " <a href='../student/edit_personal.php'>Edit </a>";
echo '<p> <a href="autorizace.php?lo=true">Odhlásit se</a> </p>';
return $return_array;
}
}
}
?>
Posted: Sun Dec 10, 2006 11:21 pm
by neel_basu
I Think You want Somethuing Like This Welcome $login
You Can Use Cookies For That
Posted: Mon Dec 11, 2006 3:15 am
by hrubos
I would like to use session but you can show me how [in] detail, please.
feyd | aolspeak is unacceptable. I REALLY shouldn't have to do this!
Posted: Mon Dec 11, 2006 3:23 am
by s.dot
Code: Select all
echo '<form action="login.php" method="post">';
//username password fields...
//login page
if(user is authenticated)
{
$_SESSION['username'] = $username;
}
//redirect
//welcome page
echo 'Welcome, '.$_SESSION['username'];
Posted: Mon Dec 11, 2006 4:19 am
by hrubos
yeah, thank and I still have a question
after creating class login.php then I would like to create page class edit_personal.php, so I hve use to command
$query = "Select * from users where rc_student = '$login'".
If I use seesion, how to do select information with user's login ???
Posted: Mon Dec 11, 2006 4:46 am
by Rovas
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Use SESSION to retrieve the data stored in a session. In example below I retrieved the name from a session.
Code: Select all
$name='';
$name=$_SESSION['user_name'];
echo $name;
//you can change the values contain in the $_SESSION
$item=1024;
$_SESSION['item']=$item;
Read for more details
http://www.php.net/session.
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon Dec 11, 2006 8:46 am
by hrubos
I would like to know how to use again $login for command SELECT???
Posted: Mon Dec 11, 2006 11:24 am
by hrubos
Thankssss all
I have solve and this is code for whom don't know how to use session.
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, http://www.pspad.com">
<html>
<body>
<table border =1>
<tr>
<td>First name</td>
<td>Last name</td>
<?php
//require('function_student.php');
session_start();
$MC = MySQL_Connect("localhost", "root", "");
$MS = MySQL_Select_DB("");
//login($login,$password);
$s = $_SESSION['valid_user'];
$query = "SELECT last_name, first_name FROM student WHERE rc_student = '$s'";
$result = mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while($i<$num){
$first_name=mysql_result($result,$i,"first_name");
$last_name=mysql_result($result,$i,"last_name");
?>
<tr>
<?php
echo "<td>$first_name</td>" ;
echo "<td>$last_name</td>";
$i++;
}
?>
</tr>
<p> <a href="http://localhost/BP/autorizace/autorizace.php?lo=true">Odhlásit se</a> </p>
</body>
</html>
Posted: Mon Dec 11, 2006 11:51 am
by aaronhall
Just a tip: if you use
mysql_fetch_assoc, you bypass having to call mysql_result for every column.