Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

login problem in Version 4.2.1?

Status
Not open for further replies.

hisham

IS-IT--Management
Nov 6, 2000
194
In my local server I use PHP Version 4.2.1, when I try to run the following code, just refresh the page when the submit button is clicked:

-------------------------------------------------------
<?php
//here goes connections

function Form_action($sAction)
{
global $db;
global $sFormErr;


switch($sAction)
{
case &quot;login&quot;:


$sLogin = get_param(&quot;Login&quot;, adText);
$sPassword = get_param(&quot;Password&quot;, adText);
$db->query(&quot;SELECT user_id,user_level FROM users WHERE user_login =&quot; . tosql($sLogin,&quot;Text&quot;) . &quot; AND user_password=&quot; . tosql($sPassword,&quot;Text&quot;) );

if($db->next_record())
{
set_session(&quot;UserID&quot;, $db->f(&quot;user_id&quot;));
set_session(&quot;UserRights&quot;, $db->f(&quot;user_level&quot;));
$sQueryString = get_param(&quot;querystring&quot;);
$sPage = get_param(&quot;ret_page&quot;);
if (strlen($sPage))
header(&quot;Location: &quot; . $sPage);
else
header(&quot;Location: AdminMenu.php&quot;);
}
else
$sFormErr = &quot;Login or Password is incorrect.&quot;;



break;
case &quot;logout&quot;:


session_unregister(&quot;UserID&quot;);
session_unregister(&quot;UserRights&quot;);

break;
}
}

function Form_Show()
{
global $sFormErr;

global $db;
global $sFileName;
global $styles;




$sQueryString = get_param(&quot;querystring&quot;);
$sPage = get_param(&quot;ret_page&quot;);
$sLogin = get_param(&quot;Login&quot;, adText);


//-- table header
?>
<table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot;>
<form action=&quot;<?= $sFileName ?>&quot; method=&quot;POST&quot;>
<input type=&quot;hidden&quot; name=&quot;FormName&quot; value=&quot;Form&quot;>

<tr><td>Login</td></tr>
<? if ($sFormErr) { ?>
<tr><td><?= $sFormErr ?></td></tr>
<? } ?>

<?

if(get_session(&quot;UserID&quot;) == &quot;&quot;) //-- user isn't logged in yet
{
?>
<tr><td>Login</td><td bgcolor=&quot;#F5F5F5&quot;><input type=&quot;text&quot; name=&quot;Login&quot; value=&quot;<?= $sLogin ?>&quot; maxlength=&quot;20&quot;></td></tr>
<tr><td>Password</td><td><input type=&quot;password&quot; name=&quot;Password&quot; maxlength=&quot;20&quot;></td></tr>
<tr><td colspan=&quot;2&quot;>
<input type=&quot;hidden&quot; name=&quot;FormAction&quot; value=&quot;login&quot;>
<input type=&quot;submit&quot; value=&quot;Login&quot;>
</td></tr>
<?
}
else //-- user already logged in
{
$db->query(&quot;SELECT user_login FROM users WHERE user_id=&quot;. get_session(&quot;UserID&quot;));
$db->next_record();
?>
<tr><td> <?= $db->f(&quot;user_login&quot;) ?>
<input type=&quot;hidden&quot; name=&quot;FormAction&quot; value=&quot;logout&quot;>
<input type=&quot;submit&quot; value=&quot;Logout&quot;>
</td></tr>
<?
}
?><input type=&quot;hidden&quot; name=&quot;ret_page&quot; value=&quot;<?= $sPage ?>&quot;><input type=&quot;hidden&quot; name=&quot;querystring&quot; value=&quot;<?= $sQueryString ?>&quot;></td></tr>
</form></table>
<?


}

?>


But it runs well when I use it in my internet server that has an older version of php
Thanks in advance for any help..

 
Register Globals is set to off by default in php 4.2.x+

set it to on for this script to work or more secure, use $_GET[] and $_POST[] and $_SERVER[] arrays , there are others but you'll need to RTFM for that :) ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
I changed the configuration of the directive register_globals to on in my linux box by modifying the php.ini in /usr/local/lib and now it looks like:
-------------------------------
; You should do your best to write your scripts so that they do not require
; register_globals to be on; Using form variables as globals can easily lead
; to possible security problems, if the code is not very well thought of.
register_globals = On

; This directive tells PHP whether to declare the argv&argc variables (that
; would contain the GET information). If you don't use these variables, you
; should turn it off for increased performance.
register_argc_argv = On
------------------------------
when I run:
<?
phpinfo();
?>
to verify, I found the register_globals is still set to Off, while in the php.ini is set to On.
how to set it to on?
 
I'm assuming you're using Apache and running PHP as a module.
Have you restarted Apache since you changed php.ini? //Daniel
 
Thank you Daniel, it works now after restarting Apache
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top