User Registration in PHP and Keyword Substitution [closed]

-4
Hello, I created a PHP login system that goes to a dashboard, but all users go to the same, I would like every registered user to have their own dashboard from a template, with their data (username) and that the same user name should replace some internal links.

Ex: I registered Jose and Maria in db; Jose's dashboard would have his name in the corner replacing the 'USER' field and some internal links (within the html)

(ex: src: "// site.com/teste/USERID/USER.html") replace the word USERID with the bank id and USER by Jose;

Same thing with Maria dash, register her in db, and generate her own dash replacing USER with Maria.

Note: my db has the fields: id, name, email, password;

My validation php:

Beginningofthedashboard:

Andherewouldbewherewouldreplacetheusername:

Butitalwaysgivesthiserror:

    
asked by anonymous 04.04.2018 / 15:01

3 answers

1

Yes My Friend this is simple, when you log it does a check in the database if you have this information right? so if it has it it is directed to your dashboard what you have to do and before it is directed you create a session variable and insert the data of it.

Let's go

Before but nothing at the top of your file when you are going to use session variables of a Start in the session.

session_start(); // isso vale em todos seus arquivos php e HTML que Vc for Usar as Variáveis tanto para atribuir quanto para exibir.

When you check:

    $email  = $_POST['email'];
    $senha  = $_POST['senha'];

    $q_usuario  = mysql_query("SELECT * FROM usuarios WHERE email = ".anti_sql($email,'text')." AND senha = ".anti_sql(md5($senha),'text'));     
    if($q_usuario == TRUE){
                $consulta = mysql_fetch_array($q_usuario);
                $_SESSION['ID'] = $consulta[0] // esse exemplo pega o id
                $_SESSION['USER'] = $consulta[1] // esse exemplo seria se o nome do usuario tivesse na posicao 1 da tabela.
                header("Location: dashboard.php");
    }else{
         echo "Dados errados";
    }

in your Dashboad.

<h1>Seja Beim Vindo <?php echo $_SESSION['USER'];?></h1>

<h2> O que vc quer fazer</h2>

<ul>
  <li><a href="user.php?id=$_SESSION['ID']">EDITAR</a></li>
</ul>

This is the logic no matter what version you use you will achieve the same with session variables.

    
04.04.2018 / 15:33
0

After login, in your php file you redirect it with the user id, you get it in the same query, and then redirect to the page with the variables in the url:

header('Location: home.php?&userid=$meuid&username=$username');

In your url, to get the src you do:

src:"//site.com/teste/<?= $_GET['userid']>?/<?= $_GET['username'] ?>.html"

This will take the path file according to the variables

But in the case, the right thing would be with the variables you mount dashboard fields

Where the name is set you can use the $ _SESSIONS or the $ _GET msm and change directly. Ex:

 Nome:
<h3><?= $_GET['username'] ?></h3>

Got it? You mount according to the data received after login

    
04.04.2018 / 15:18
0

Make the following changes.

1: a session_start (); comes on top soon after that: '

<?php session_start(); ?>

2: Is your $ _POST ['username'] coming from where? Are you really carrying any data? check this out.

3: sometimes the session variable does not work locally try to do a test in the hosted domain to verify.

    
04.04.2018 / 23:59