Jump to content

php suddenly doesn't work


psyqosis

Recommended Posts

Hi. My web host just updated their servers, and since then, part of my code allowing access control into a database back-end doesn't work. I've talked with the host and they claim nothing should have changed, though I haven't changed anything either.

 

The database connect string is fine & the database has the correct MySQL user account setup in my admin panel. Below is the code in question (simple login screen shown; if access is passed, more code displays the actual page). The issue is that whether correct or incorrect credentials are entered & submitted, the page simply reloads itself.

 

 

<?php session_start(); ?>

 

$database = "statz07_default" or die(mysql_error());

 

$db = mysql_connect("localhost", "statz07_statz07", "Q9e6LNY") or die(mysql_error());

 

mysql_select_db($database, $db) or die(mysql_error());

 

<head>

<link rel="stylesheet" type="text/css" href="site.css">

</head>

 

<body>

 

<?php

if (!isset($name)) { ?>

<table width=740 cellpadding=0 border=0 cellspacing=0>

  <tr>

    <td bgcolor=#ffffff>

      <table width=735 cellpadding=10 border=0 cellspacing=1>

        <tr>

          <td bgcolor=#ff3300 width=100%><b>Sign-In</b></td>

</tr>

<tr>

  <form method="post" action="<?php echo $PHP_SELF?>">

  <td width=100% bgcolor="#ccffcc" valign=top>

    <h3>Please Sign In</h3>

    <center>

    <table width=400 cellpadding=0 cellspacing=0 border=0>

      <tr><td align=right nowrap>Name &nbsp</td><td><input type="text" name="name"></td></tr>

      <tr><td align=right nowrap>Password &nbsp</td><td><input type="password" name="pswd"></td></tr>

      <tr><td colspan=2 align=right height=5><img src="images/clearpix.gif" width=400 height=5></td></tr>

      <tr><td colspan=2 align=right height=1 bgcolor=black><img src="images/clearpix.gif" width=400 height=1></td></tr>

      <tr><td colspan=2 align=right height=5><img src="images/clearpix.gif" width=400 height=5></td></tr>

      <tr><td colspan=2 align=right><input type=hidden name="new_acc" value="1"><input type="submit" value="sign-in"></td></tr>

 

    </table>

            </center>

          </form>

  </td>

</tr>

      </table>

    </td>

  </tr>

</table>

 

<?php

exit;

}

 

session_register("name");

session_register("pswd");

session_register("uid");

 

 

$sql="SELECT * FROM users WHERE un='$name' AND pw='$pswd';";

$result = mysql_query($sql, $db);

if (mysql_num_rows($result)>0) {

$uid = mysql_result($result, 0, 'id');

}

 

if (mysql_num_rows($result) == 0) {

session_unregister("name");

session_unregister("pswd");

session_unregister("uid");

?>

<table width=740 cellpadding=0 border=0 cellspacing=0>

  <tr>

    <td bgcolor=#ffffff>

    <table width=735 cellpadding=10 border=0 cellspacing=1>

      <tr>

        <td bgcolor=ff3300 width=100%><b>Sign-In</b></td>

      </tr>

      <tr>

      <tr>

        <form method="post" action="<?php echo $PHP_SELF?>">

        <td width=100% bgcolor=#ccffcc valign=top>

          <h5 class="error">Your login details have not been recognised.</h5>

  <h5>Please try again by <a href="<?php echo $PHP_SELF; ?>">clicking here</a>.</h5>

</td>

      </tr>

    </table>

    </td>

  </tr>

</table>

 

<?php

exit;

}

?>

Link to comment
Share on other sites

Also, there is no way this code worked as is.  This is your first line:

 

<?php session_start(); ?>

 

$database = "statz07_default" or die(mysql_error());

 

$db = mysql_connect("localhost", "statz07_statz07", "Q9e6LNY") or die(mysql_error());

 

mysql_select_db($database, $db) or die(mysql_error());

 

So you close PHP but then assign variables right after.  Move the ?> to after the mysql_select_db statement.

Link to comment
Share on other sites

Here

 

<tr><td align=right nowrap>Name &nbsp</td><td><input type="text" name="name"></td></tr>

session_register("name");

 

needs to change to

 



<tr><td align=right nowrap>Name &nbsp</td><td><input type="text" name="name"></td></tr>

$_SESSION['name']=$_POST['name'];

 

All of those have to be redone.

Link to comment
Share on other sites

There is also at least one $PHP_SELF that needs to be changed to $_SERVER['PHP_SELF']

 

Checking your web server log file or turning on full php error reporting will help in finding the places in the code that need to be changed.

 

The .htaccess temporary work around will only work on Apache web servers where php is running as an apache module. Where php is running as a CGI wrapper, you should have the ability to use a local php.ini file.

Link to comment
Share on other sites

Okay, I changed the syntax for variable registration to:

 

$_SESSION['name']=$_POST['name'];

$_SESSION['pswd']=$_POST['pswd'];

$_SESSION['uid']=$_POST['uid'];

 

...and all the $PHP_SELF references to $_SERVER['PHP_SELF'], but there's still no change.

 

the page is at www.statzbarandgrill.com/admin if anyone wants to see what happens. no matter if the credentials are correct or not, the page still simply resets.

 

Link to comment
Share on other sites

Sounds like you need to chop it up and start bughunting bit by bit. Verify values from the submitted form.

 

Verify they are evaluating as expected

Create and verify the session data exists and evaluates.

 

So on and so forth.

Link to comment
Share on other sites

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.