0

I am coding a simple login member system using PHP but each time I go to the PHP page the source code for the page shows up instead of the username and password box. I have this code at the top of the page:

<?php
session_start();
?>

It is right at the top of the page before anything else but when I take that code away the page show up normally but this code appears below the username and password boxes:

"; if ($_POST ['loginbtn']){ $user = $_POST['user']; $user = $_POST['password']; if ($user){ if ($password){ echo "$user - $password
$form"; } else echo "you must enter your password $form"; } else echo "you must enter your username $form"; } else echo $form; ?> 

This code should only be appearing after the user has pressed submit and it shouldn't appear in that form.

14
  • 2
    Gonna need to see more code Commented Jan 22, 2014 at 18:47
  • Either PHP is not properly setup, or your server doesn't support PHP and is not being parsed, or you're using a file extension other than .php --- Show your full code and not just two lines of it. Commented Jan 22, 2014 at 18:48
  • @Dagon File extension definitely end with .php. Commented Jan 22, 2014 at 18:51
  • Are you running this on a local machine, or via WWW? Commented Jan 22, 2014 at 18:51
  • 1
    bingo, then there's no webserver and no php involved Commented Jan 22, 2014 at 18:58

2 Answers 2

2

You clearly have a syntax error somewhere, where something is treated as a string whereas it should be code.

Look for weird syntax coloring in your text editor...

Sign up to request clarification or add additional context in comments.

2 Comments

this should be a comment, not an answer
I agree with @Dagon . Even still, if it's showing up as code then obviously it's not wrapped inside proper <?php tag. If anything, it would throw a parse error or other type of error.
0
<?php  //this lets php know to start processing
session_start();
?>  // this tells PHP to STOP processing

I'm thinking based on what you said that you close your PHP tag and don't open it again for the rest of the code at the bottom. Instead use:

<?php 
session_start();

// rest of php code and page

2 Comments

I do add a new <?php tag after the closing one.
Oh well, worth a shot; it is impossible to tell with the small code snippet provided.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.