Jump to content

$HTTP_POST_VARS depreciated problem


skoobi

Recommended Posts

Hi im sort of teaching myself how to code in php. even though i can do it there's still a few things im getting stuck on so im hoping someone will be able to help...

Im currently going through a cms tutorial on the net (yes i know there's pre-made ones like joomla but i want to learn how they work) and ive got to the end of it but im getting this error...

 

Notice: Undefined variable: HTTP_GET_VARS in C:\wamp\www\CustomCMS\cmsadmin\login.php on line 9

 

I know this is depreciated and you need to use the $_POST method now but as soon as i do that i get another error...

 

Notice: Undefined index: user in C:\wamp\www\CustomCMS\cmsadmin\login.php on line 5

 

Heres the code for the login script..

<?php
require_once("../includes/Sentry.php");

$sentry = new Sentry();
if ($HTTP_POST_VARS['user'] != ''){
$sentry->checkLogin($HTTP_POST_VARS['user'],$HTTP_POST_VARS['pass'],4,'welcome.php','failed.php');
}

if ($HTTP_GET_VARS['action'] == 'logout'){
if ($sentry->logout()){
	echo '<center>You have been logged out</center><br>';
}
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="25%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000066">
  <tr>
    <td align="center" bgcolor="#000066"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Login</strong></font></td>
  </tr>
  <tr>
    <td bordercolor="#FFFFFF"><form name="form1" method="post" action="login.php">
        <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
 User:
          <input type="text" name="user">
        </font></p>
        <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> Pass:
              <input type="password" name="pass">
        </font></p>
        <p align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
          <input type="submit" name="Submit2" value="Submit">
        </font></p>
      </form>
        <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="login.php?action=logout">Logout</a> </font></div>
    </td>
  </tr>
</table>
</body>
</html>

 

Ive gone through the net trying to find a solution but i cannot find anything on this one... I dont mind going through every page sorting this out as its just a learning curve for me...

If anyone could shed some light on this for me i would be most grateful...

 

Thank you

chris

Link to comment
Share on other sites

just need to check for the existence of the $_POST variable.

 

isset()

<?php
require_once("../includes/Sentry.php");

$sentry = new Sentry();
if (isset($_POST['user']) && isset($_POST['pass'])){
$sentry->checkLogin($_POST['user'],$_POST['pass'],4,'welcome.php','failed.php');
}

if (isset($_GET['action']) && $_GET['action'] == 'logout'){
if ($sentry->logout()){
	echo '<center>You have been logged out</center><br>';
}
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table width="25%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000066">
  <tr>
    <td align="center" bgcolor="#000066"><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Login</strong></font></td>
  </tr>
  <tr>
    <td bordercolor="#FFFFFF"><form name="form1" method="post" action="login.php">
        <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><br>
 User:
          <input type="text" name="user">
        </font></p>
        <p><font size="2" face="Verdana, Arial, Helvetica, sans-serif"> Pass:
              <input type="password" name="pass">
        </font></p>
        <p align="center"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">
          <input type="submit" name="Submit2" value="Submit">
        </font></p>
      </form>
        <div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><a href="login.php?action=logout">Logout</a> </font></div>
    </td>
  </tr>
</table>
</body>
</html>

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.