Very Basic Question

This is an extremely basic question and I feel silly asking.

I wrote a basic php login script but I’ve never ran it until today only researched php, how to use it, etc.

The code is a basic login script and I can’t seem to even open it in a browser to see if I did it right and debug it :frowning:

[php]<?php

include(“config.php”);

// Check form if is submited
if(isSet($_POST[‘trimite’])) {
// Check if user is equal with username and password from config.php
if($_POST[‘user’] != $user || $_POST[‘pass’] != $pass) {
echo “Sorry, your data is invalid”;
} else {
// Open the session for store user logged
session_start();
// Setting the session
$_SESSION[‘logat’] = “da”;
// Redirecting user to admin page if is logged
Header(‘Location: admin.php’);
}
} else {
// Form
echo ’
Username:
Password:

'; }

?>[/php]

I thought I finally grasped it and then came across this and it’s making me feel dumb. All it shows up as in my folder is a Notepad. Maybe I need to go back to the basics? I don’t know. If someone could help it would be an immense favor. Thank you.

First you’ll need some kind of local server in order to run pages written in php and have the .php extension. For Windows users there’s WAMP, XAMPP (I use) and others (Google it) and for the Mac I believe they have a local server already running (A Mac user could tell you better). An if you were using a Linux computer I’m sure you would already know this. ;D If you have any problems setting it up there are plenty of people here that will help you troubleshoot the problem(s).

As for you code, I did a quick look at it. My first suggestion is to keep you php code separate from the HTML (as much as possible), even if you are goofing around with it.

for example
[php]<?php

if (isset($_POST[‘trimite’]) && $_POST[‘trimite’] == ‘Submit’) {
echo ‘ENTER CODE HERE
’;
if ( $_POST[‘pass’] == “hacked” && $_POST[‘user’] == ‘Thor’ ) {
echo “You may now proceed to hack me”;
}

}
?>

Username: Password: [/php]

Usually most coders put the php code at the top and the HTML at the bottom (there are times where you mingle php code among the HTML), plus one last observation the php code has to have proper syntax for example you have if(isSet($_POST[‘trimite’])) should had been if(isset($_POST[‘trimite’])) . Though for some strange reason when I ran you code the way it was it didn’t flag me any errors, very strange. Thinking about it, it probably would had when I pressed the submit button.

Sponsor our Newsletter | Privacy Policy | Terms of Service