function

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
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

function

Post 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).
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post 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;
                }         
 
}
}


?>
User avatar
neel_basu
Forum Contributor
Posts: 454
Joined: Wed Dec 06, 2006 9:33 am
Location: Picnic Garden, Kolkata, India

Post by neel_basu »

I Think You want Somethuing Like This Welcome $login
You Can Use Cookies For That
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post 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!
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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'];
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.
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post 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 ???
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post by Rovas »

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;
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]
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

I would like to know how to use again $login for command SELECT???
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post 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>
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Just a tip: if you use mysql_fetch_assoc, you bypass having to call mysql_result for every column.
Post Reply