8 Replies - 272 Views - Last Post: 05 December 2018 - 07:03 PM Rate Topic: -----

#1 kernelgeek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 18

confusing error with php 7.2 windows 10

Posted 30 November 2018 - 11:38 PM

i cannot get around always getting this error on the bellow code mainpage.php , i have tried to change this code alot of different ways it never works

This page isn’t working localhost is currently unable to handle this request.
HTTP ERROR 500.

could someone please tell me what is causing this error.......

the code for this project php code is the following

//-----------mainpage.php-------------------

<?php
session_start();    //session start
if(!isset($_SESSION['username']))     //if session not found redirect to homepage
{
header('location:index.php');
}
echo "Welcome &nbsp;";
echo $_SESSION['username'];      //retrieved using session
?>

<html>
<head>
</head>
<body>
<center>
<h2>Welcome to Main page</h2>
<a href="logout.php">logout</a>
</center>
</body>
</html>

//--------------(index.php)---------------------------------

<?php
session_start();    // Session start
 
if(isset($_POST['check']))    // Check form submit with IF Isset function
{
$username="admin";    // set variable value
$password="123";        // set variable value
if($_POST['username']==$username && $_POST['password']==$password)   // Check Given user name, password and Variable user name password are same
{
$_SESSION['username']=$username;    // set session from given user name
header('location:mainpage.php');
}
else
{
$err="Authentication Failed Try again!";
}
}
?>
 
<html>
<head>
<title>Main Page</title>
</head>
<body>
<Center>
<?php if(isset($err)){ echo $err; } ?>      <!-- Print Error -->
 
<form method="POST" name="loginauth" target="_self">
 
User Name: <input name="username" size="20" type="text" />
<br/><br/>
Password: 
<input name="password" size="20" type="password" />
<br/><br/>
<input name="check" type="submit" value="Authenticate" />
 
</form>
</center>
</body>
</html>




This post has been edited by CTphpnwb: 01 December 2018 - 05:30 AM
Reason for edit:: Fixed code tags. Use [ ]


Is This A Good Question/Topic? 0
  • +

Replies To: confusing error with php 7.2 windows 10

#2 RamonRobben   User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 596
  • Joined: 19-May 14

Re: confusing error with php 7.2 windows 10

Posted 01 December 2018 - 05:08 AM

I am running PHP version: 7.2.9 and for me it works without problems.
Because you are getting a 500 Internal Error I would suggest you to look into your logs and/or post them here.
Are you using XAMPP or LAMPP or a different web server? For XAMPP the log file could be found in here: C:\xamp\apache\logs if you installed it in the default location.
Was This Post Helpful? 0
  • +
  • -

#3 kernelgeek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 18

Re: confusing error with php 7.2 windows 10

Posted 04 December 2018 - 08:48 PM

View PostRamonRobben, on 01 December 2018 - 05:08 AM, said:

I am running PHP version: 7.2.9 and for me it works without problems.
Because you are getting a 500 Internal Error I would suggest you to look into your logs and/or post them here.
Are you using XAMPP or LAMPP or a different web server? For XAMPP the log file could be found in here: C:\xamp\apache\logs if you installed it in the default location.


well , i switched to php Version 7.1.1 and it works just perfectly , if i switch back to PHP version: 7.2.9 and restart Browser it does not work again, "very strange" , i'm just going to stay with php Version 7.1.1, Thank you for your response...
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is online

  • Stealth IT
  • member icon

Reputation: 6747
  • View blog
  • Posts: 27,781
  • Joined: 12-December 12

Re: confusing error with php 7.2 windows 10

Posted 05 December 2018 - 01:44 AM

Note that the center tag no longer exists and pages should have a DOCTYPE declaration.
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3811
  • View blog
  • Posts: 13,851
  • Joined: 08-August 08

Re: confusing error with php 7.2 windows 10

Posted 05 December 2018 - 05:51 AM

If there is anything (including spaces or line feeds) before the opening php tag it should not work, since headers will be sent before session_start();.
Was This Post Helpful? 0
  • +
  • -

#6 RamonRobben   User is offline

  • D.I.C Addict
  • member icon

Reputation: 90
  • View blog
  • Posts: 596
  • Joined: 19-May 14

Re: confusing error with php 7.2 windows 10

Posted 05 December 2018 - 06:15 AM

View PostCTphpnwb, on 05 December 2018 - 05:51 AM, said:

If there is anything (including spaces or line feeds) before the opening php tag it should not work, since headers will be sent before session_start();.


Then why does it work perfectly fine in a different version of PHP? It seems as if PHP 7.2 is the only version that doesn't work for OP.

This post has been edited by RamonRobben: 05 December 2018 - 06:15 AM

Was This Post Helpful? 0
  • +
  • -

#7 kernelgeek   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 30-November 18

Re: confusing error with php 7.2 windows 10

Posted 05 December 2018 - 08:49 AM

View PostRamonRobben, on 05 December 2018 - 06:15 AM, said:

View PostCTphpnwb, on 05 December 2018 - 05:51 AM, said:

If there is anything (including spaces or line feeds) before the opening php tag it should not work, since headers will be sent before session_start();.


Then why does it work perfectly fine in a different version of PHP? It seems as if PHP 7.2 is the only version that doesn't work for OP.



I've had so many of the exact same issues with other PHP code I've thrown together. i'm going to keep trying code on PHP 7.2 and switch it over to PHP version: 7.1.1 it's such a pondering issues it really bothers me.. this works good on both versions
<code> <?php echo("hello php");?> </code> hehe.

View PostCTphpnwb, on 05 December 2018 - 05:51 AM, said:

If there is anything (including spaces or line feeds) before the opening php tag it should not work, since headers will be sent before session_start();.


i will give that a try and see what i find. thank you
Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2241
  • View blog
  • Posts: 6,796
  • Joined: 15-January 14

Re: confusing error with php 7.2 windows 10

Posted 05 December 2018 - 11:08 AM

Quote

Then why does it work perfectly fine in a different version of PHP?

The answer to that question is in the error log. Saying that there is a 500 error is no more meaningful than just saying there's an error. The actual error message is what matters, and that error message will be a log or wherever else it's configured in php.ini. There's not much point in guessing what the error is when the error message is just waiting to tell you.
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3811
  • View blog
  • Posts: 13,851
  • Joined: 08-August 08

Re: confusing error with php 7.2 windows 10

Posted 05 December 2018 - 07:03 PM

View PostRamonRobben, on 05 December 2018 - 08:15 AM, said:

Then why does it work perfectly fine in a different version of PHP? It seems as if PHP 7.2 is the only version that doesn't work for OP.

I wouldn't assume that both sets of files are identical. If the OP copy/pasted code it might appear to be identical without actually being so.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1