Hi,

I got this function on index.php:

//user 'logado' ou nao
function is_logged()
{
if(isset($_SESSION['username'])) {
return true;
}else{
return false;
}
}

And i want to use it on top.php (on top is the banner and the menu).

<div>
<ul class="menu">
	<li class="top"><a href="index.php" class="top_link"><span>Página Principal</span></a></li>
	<li class="top"><a href="inscricao.php" class="top_link"><span>Inscrições Online</span></a></li>
	<li class="top"><a href="cursos.php" class="top_link"><span>Cursos</span></a></li>
	<li class="top"><a href="contact.php" class="top_link"><span>Contacte-nos</span></a></li>
	
	<?PHP
	if(is_logged())
	{
	?> 
	<li class="top"><a href="index.php" class="top_link"><span> 
	<?PHP $_SESSION['username'] ?> 
	</span></a></li> 
	<?PHP
	;}
	?>
</ul>
</div>

What's wrong here?

Recommended Answers

All 3 Replies

If you don't include the function, then top.php can't execute it.

I think line 13 is missing an echo.

If you don't include the function, then top.php can't execute it.

I think line 13 is missing an echo.

Stupid error :S

Now i'm in trouble with something i have this validationpass.php

<?php
    session_start();
     
    include "db_connect.php";
     
    $username = $_POST['username'];
    $pass = $_POST['pass'];
	
    $sql="SELECT username, password FROM alunos WHERE username='". $username. "'";
     
    $resultado = mysql_query($sql, $connect) or die(mysql_error());
     
    $num = mysql_fetch_assoc($resultado);
     
	$_SESSION['nome_aluno'] = $nome;
	 
    if ($username == $num['username'] AND $pass == $num['password']) {
    $_SESSION['username'] = $username;
    header("Location: index.php"); // sorry xD
    } else {
    header("Location: login_form.php"); 
    }
    mysql_close($connect);
    ?>

and i want that instead of the username appears the name of the user:

index.php/menu

<!--begin menu_css-->
<div>
<ul class="menu">
	<li class="top"><a href="index.php" class="top_link"><span>Página Principal</span></a></li>
	<li class="top"><a href="inscricao.php" class="top_link"><span>Inscrições Online</span></a></li>
	<li class="top"><a href="cursos.php" class="top_link"><span>Cursos</span></a></li>
	<li class="top"><a href="contact.php" class="top_link"><span>Contacte-nos</span></a></li>
	
	<?PHP
	if(is_logged())
	{
	?> 
	<li class="top"><a href="index.php" class="top_link"><span> 
	<?PHP echo $_POST['nome'] ?> 
	</span></a></li> 
	<?PHP
	;}
	?>

registrationform.php

<form action="envia.php" method="post" onsubmit="return validar()" >
    <fieldset>
    <legend> ALUNO </legend>
     
    <br/>
    <div class="field"><label>Username*: </label><input type="text" size="30" name = "username"/></div>
    <br/>
    <div class="field"><label>Password*: </label><input type="password" size="25" name = "pass"/></div>
    <br/>
    <div class="field"><label>Confirma Password*: </label><input type="password" size="25" name = "conf_pass"/></div>
    <br/>
    <div class="field"><label>Nome*: </label><input type="text" size="40" name = "nome"/></div>

In index.php file, on line 14, you should put something like that

echo $_SESSION['nome_aluno']

. So, if the user is logged, it will show his name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.