Dylanh - PHP Hulp

Gestart doorDylan2 reacties40 weergaven

3 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Hoi, ik ben bezig met een upload site inc. inlog systeem etc.

Dit topic dient ervoor om mij wat te helpenbiggrinAangezien ik niet goed PHP kan zou ik graag dat je het nummer van het probleem er bij zet. (in je reactie) Alvast bedanktemoAlle opgeloste problemen komen in een spoiler!
Probleem 1:
Ik wil graag dat als ik inlog met naam komt te staan,

Log in.php:

[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/include"]include[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]menu.php[/COLOR][COLOR= #007700]);[/COLOR] ?>



<html>
    <head>
        <title>Uploadmania.nl <3 - Upload al jou favorite plaatjes/afbeelding!</title>
        <style type="text/css">
        Overbodige tekst :")
        </style>
    </head>
    <body>
        <div id="boven">
            <div id="logo">
            <a href="index.php"><marquee><img src="logo.png" alt="logo" /></marquee></a>
            </div>
            
        </div>
        <div id="midden">
            <div id="big">
                <div id="menu">[COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$url[/COLOR] ?></a></div>
                
                
                
                

    <center><br /><br />
    [COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]// session_start();[/COLOR]
[URL="http://www.php.net/include"]include[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]mysql.php[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700])
{[/COLOR]
    [COLOR= #0000BB]$arrErrors[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]]) &&[/COLOR] [URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        [COLOR= #0000BB]$sQuery[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM users WHERE username = "[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_real_escape_string"]mysql_real_escape_string[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
    
        [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR][COLOR= #007700])
        {[/COLOR]
            [COLOR= #0000BB]$userFetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$sQuery[/COLOR][COLOR= #007700]);[/COLOR]
    
            [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$userFetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]wachtwoord[/COLOR][COLOR= #007700]])
            {[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Je bent succesvol ingelogd, je word doorgestuurd[/COLOR][COLOR= #007700];[/COLOR]
                               [COLOR= #FF8000]// Doorsturen of session stuff hier[/COLOR]
                
                [URL="http://www.php.net/header"]header[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Location: ./in/index.php[/COLOR][COLOR= #007700]);
            }[/COLOR]
            [URL="http://www.php.net/else"]else[/URL]
            [COLOR= #007700]{[/COLOR]
                [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Wachtwoord klopt niet.[/COLOR][COLOR= #007700];
            }
        
        }[/COLOR]
        [URL="http://www.php.net/else"]else[/URL]
        [COLOR= #007700]{[/COLOR]
            [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Gebruikersnaam niet gevonden[/COLOR][COLOR= #007700];
        }
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]Voer uw gebruikersnaam en wachtwoord in.[/COLOR][COLOR= #007700];
    }[/COLOR]
    
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er [/COLOR] [COLOR= #007700]. ([/COLOR][URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700]) ==[/COLOR] [COLOR= #0000BB]1[/COLOR] [COLOR= #007700]?[/COLOR] [COLOR= #DD0000]is 1 fout[/COLOR] [COLOR= #007700]:[/COLOR] [COLOR= #DD0000]zijn [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] fouten[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] opgetreden:<br />[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$arrErrors[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$errId[/COLOR] [COLOR= #007700]=>[/COLOR] [COLOR= #0000BB]$errMelding[/COLOR][COLOR= #007700])
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$errMelding[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];        
    }
}[/COLOR]


?>
<form action=login.php method=POST>
    
    Gebruikersnaam: <input type=text name=username> <br />
    Wachtwoord: <input type=password name=wachtwoord><br />
    <input type=submit value=Log in!>
    
    </form>


</center>






                <br />
                <h2>Nog geen account? <a href="">REGISTEER GRATIS!</a>
             </div>
             
                            <div id="footer">
                 <center>&copy; - [COLOR= #0000BB]<?php[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/date"]date[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Y[/COLOR][COLOR= #007700])[/COLOR] ?> by UploadMania.nl, alle rechten voorbehouden</center>
                 </div>
        </div>
    </body>
</html>


Pagina als je bent ingelogd:

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]])[/COLOR]
[COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]username[/COLOR][COLOR= #007700]];[/COLOR]

[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #007700]([/COLOR][COLOR= #DD0000]Je bent ingelogd als, [/COLOR][COLOR= #007700]);[/COLOR]

?>


Ik wil graag dat het er zo uit ziet;

Je bent ingelogd als, admin

Hoe doe ik dat?

Probleem 2:

Log uit werkt niet,

Code:

[COLOR= #0000BB]<?php[/COLOR]


[URL="http://www.php.net/session_start"]session_start[/URL][COLOR= #007700]();[/COLOR]

[URL="http://www.php.net/session_destroy"]session_destroy[/URL][COLOR= #007700]();[/COLOR]


[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Je bent uitgelogd"[/COLOR][COLOR= #007700];[/COLOR]
?>


Werkt niet omdat; als je weer terug gaat naar die pagina staat er nog: Je bent ingelogd.
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
1:

if($userFetch[wachtwoord] == $_POST[wachtwoord])
            {
                echo Je bent succesvol ingelogd, je word doorgestuurd;
                               // Doorsturen of session stuff hier
                
                header(Location: ./in/index.php);
            }


Je maakt geen sessie aan? Geen cookie? Je zet niks in de database?
Je word doorgelinkt naar index.php, maar daar weet hij al niet meer dat je hebt ingelogd..

Je moet dus een sessie maken met een hash (random gegenereerde code) en die hash zet je ook in de database, met je username / userid.

Dan kan je het als volgt ophalen

SELECT * FROM sessies WHERE hash = $_SESSION[hash]
fetch -> username smile
En dan werkt vraag 2 wss ook smile
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Wat is dan de SQL van die tabel?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren