function
Moderator: General Moderators
function
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).
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).
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
I don't understand and so I don't know how to begin???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.
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'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;
}
}
}
?>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'];Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
feyd | Please use
Read for more details http://www.php.net/session.
feyd | Please use
Code: Select all
,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;feyd | Please use
Code: Select all
,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]Thankssss all
I have solve and this is code for whom don't know how to use session.
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>- aaronhall
- DevNet Resident
- Posts: 1040
- Joined: Tue Aug 13, 2002 5:10 pm
- Location: Back in Phoenix, missing the microbrews
- Contact:
Just a tip: if you use mysql_fetch_assoc, you bypass having to call mysql_result for every column.