Jump to content

Recommended Posts

this is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Tribuguadagno!</title>
  <link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
session_start();
function sql_quote( $value )
{
if( get_magic_quotes_gpc() )
{
      $value = stripslashes( $value );
}
//check if this function exists
if( function_exists( "mysql_real_escape_string" ) )
{
      $value = mysql_real_escape_string( $value );
}
//for PHP version < 4.3.0 use addslashes
else
{
      $value = addslashes( $value );
}
return $value;

}
if (isset($_POST['username'])) {
$username = sql_quote($_POST['username']);
$password = sql_quote($_POST['password']);
$mysqli = new mysqli("localhost", "root", "", "tribuguadagno");
$risultato = $mysqli->query("SELECT * FROM users WHERE userid='$username' AND password='$password'");
$mysqli->close();
if ($risultato->num_rows == 0){
    header("location: index.php");
    exit;
}
session_start();
$_SESSION['user'] = $username;

header("location: index.php");
}

if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header("location: index.php");
exit;
}
if (isset($_SESSION['user'])) {
echo ('You are logged in!');
echo ('<br><a href=\'?logout\'>Log out</a>');
} else {
echo('<h2>Member Login</h2><form action="cpanel.php" method="POST">Username:<br><input type="text" name="username"><br>Password:<br><input type="password" name="password"><br><input type="submit" name="submit" value="login"></form>');
}
?>
</body>
</html>

 

and this is the output i get (HTML source code)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head> 
  <title>Tribuguadagno!</title> 
  <link href="style.css" rel="stylesheet" type="text/css" /> 
</head> 

<body> 
query("SELECT * FROM users WHERE userid='$username' AND password='$password'");
$mysqli->close();
if ($risultato->num_rows == 0){
    header("location: index.php");
    exit;
}
session_start();
$_SESSION['user'] = $username;

header("location: index.php");
}

if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header("location: index.php");
exit;
}
if (isset($_SESSION['user'])) {
echo ('You are logged in!');
echo ('<br><a href=\'?logout\'>Log out</a>');
} else {
echo('<h2>Member Login</h2><form action="cpanel.php" method="POST">Username:<br><input type="text" name="username"><br>Password:<br><input type="password" name="password"><br><input type="submit" name="submit" value="login"></form>');
}
?>
</body> 
</html>

 

basically, the script is no longer parsed when it encounters a ">"... no a ?>, just a single > that i have to use in $mysqli->query .... anyone knows how to fix this?

I can't see anything to cause the parse issue.  However, session_start() must be called BEFORE anything is sent to the browser.  Where you have it, it is causing an error, which you are not seeing.  Add the following to the very top of the file (before even the DOCTYPE):

<?php
error_reporting(E_ALL);
session_start();
?>

 

Then you will see the error messages.  Note, you will have to remove the other session_start() calls that you have in the file.

 

Post the error message you get and maybe we can help.

 

the file is a .php, and the error is not showing, the php doesn't parse that part at all. ( i set my php.ini to E_ALL to check, nothing appears)

 

 

 

EDIT: i did some other tests, while all the other pages that i created on my local host works just fine, on this page NO php scripts will work... i even tryed adding this:

<?php
echo('test');
?>

to the top of the file (before anything) and nothing shows up. the other pages hosted work fine. i'm using XAMPP last version (1.7).... any tips?

The characters making up the php tag could be corrupted; the character encoding or the file it self could be corrupted; the characters making up the .php extension could be corrupted.

 

Create a new file and copy/paste the contents of the existing file into it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.