Upgrading php4 to php5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
esmarts
Forum Newbie
Posts: 14
Joined: Fri Aug 08, 2008 10:05 pm

Upgrading php4 to php5

Post by esmarts »

Ok I did alittle bit of research on the incompatabilities of php4 and 5.

I have a login script that for some reason loops and returns to the login screen when a good user and Pw is used.

Here is a sample of the login form

Code: Select all

$redirect = isset($ilance->GPC['redirect']) ? $ilance->GPC['redirect'] : '';
if (isset($ilance->GPC['login_process']) AND $ilance->GPC['login_process'] == 1)
{
    $area_title = $phrase['_submitting_login_information'].' . .';
    $page_title = SITE_NAME.' - '.$phrase['_submitting_login_information'];
    $badusername = 1;
    $badpassword = 1;
    if (empty($ilance->GPC['username']))
    {
        $sqluser = $ilance->db->query("SELECT * FROM ".DB_PREFIX."users
        WHERE username = '".mysql_real_escape_string($ilance->GPC['username'])."'
        LIMIT 1");
        if ($ilance->db->num_rows($sqluser) > 0)
        {
            $user_result = $ilance->db->fetch_array($sqluser);
            $badusername = 0;
            $badpassword = 0;
            if ($user_result['password'] != iif($ilance->GPC['password'] AND !$ilance->GPC['md5pass'], md5(md5($ilance->GPC['password']) . $user_result['salt']), '') AND $user_result['password'] != md5($ilance->GPC['md5pass'] . $user_result['salt']) AND $user_result['password'] != iif($ilance->GPC['md5pass_utf'], md5($ilance->GPC['md5pass_utf'] . $user_result['salt']), ''))
            {
                $badpassword = 1;
            }
        }
        if ($badusername == 0 AND $badpassword == 0)
        {
            // update last seen for this member
            $ilance->db->query("UPDATE ".DB_PREFIX."users
            SET lastseen = '".DATETIME24H."'
            WHERE user_id = '".$user_result['user_id']."'
            LIMIT 1");
            
            // default subscription params
            $subscription_result['subscriptionid'] = 0;
            $subscription_result['active'] = 'no';
            $subscription_plan_result['cost'] = 0;
            
            // fetch user subscription infos
            $sql_subscription_user = $ilance->db->query("SELECT * FROM ".DB_PREFIX."subscription_user
            WHERE user_id = '".$user_result['user_id']."'
            LIMIT 1");
            if ($ilance->db->num_rows($sql_subscription_user) > 0)
            {
                $subscription_result = $ilance->db->fetch_array($sql_subscription_user);
                $sql_subscription_plan = $ilance->db->query("SELECT * FROM ".DB_PREFIX."subscription
                WHERE subscriptionid = '".$subscription_result['subscriptionid']."'
                LIMIT 1");
                if ($ilance->db->num_rows($sql_subscription_plan) > 0)
                {
                    $subscription_plan_result = $ilance->db->fetch_array($sql_subscription_plan);
                }
            }
            if ($user_result['status'] == 'active')
            {
                $sql_prefs = $ilance->db->query("SELECT * FROM ".DB_PREFIX."preferences
                WHERE user_id = '".$user_result['user_id']."'
                LIMIT 1");
                $pref_result = $ilance->db->fetch_array($sql_prefs);
                                    
                $sel_currencies = $ilance->db->query("SELECT * FROM ".DB_PREFIX."currency
                WHERE currency_id = '".$pref_result['currencyid']."'
                LIMIT 1");
                $res_currencies = $ilance->db->fetch_array($sel_currencies);
                                
                // are we still logged in as admin?
                if (empty($_SESSION['ilancedata']['admin']) AND is_array($_SESSION['ilancedata']['admin']))
I read that php5 does not support !empty..

How can I rewrite this to work in php5

This mat sound like a noob question and thats becuase it is. lol

I am just learning php4.

but anyways thanks in advance if you can help me out!
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Upgrading php4 to php5

Post by omniuni »

Just out of curiosity, what is the error you get when you run it as php5?
esmarts
Forum Newbie
Posts: 14
Joined: Fri Aug 08, 2008 10:05 pm

Re: Upgrading php4 to php5

Post by esmarts »

There is no error just a redirect..

I am now thinking that is has to do with the sessions not passing now.

The script redirects to the user panel like it is suppose to. Then it redirects back to the login as if the sessions did not match up or something..

Here you can visit the site and see for yourself

http://www.smartstartservers.com..


I will turn all errors to E_ALL
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Upgrading php4 to php5

Post by requinix »

esmarts wrote:I read that php5 does not support !empty.
If that's your only concern then don't worry: whoever wrote that is totally wrong.

50% of all upgrade problems are about register_globals. Seems that's not the case here with that $ilance::GPC thing.
(By the way, did you know about $_REQUEST? Contains everything from GET, POST, and COOKIE in one place.)
30% are about different configurations. Your PHP 4 installation had a setting that's not the same in the PHP 5 installation. Probably regarding sessions. Compare the two php.ini files and see what's different.

The remaining 20% is genuine incompatibility. Didn't post much code so it's hard to say "Oh, that's the problem right there". Good news is that PHP will often throw an error about bad parts: just remember to turn on display_errors too.
esmarts
Forum Newbie
Posts: 14
Joined: Fri Aug 08, 2008 10:05 pm

Re: Upgrading php4 to php5

Post by esmarts »

Thanks for the advice.. "As of PHP 5, objects with no properties are no longer considered empty. "

That is what I was reading.. I just mis-interpreted it sry :crazy: But what i don't get is, If a var is empty and I can't use

if (empty($var)) anymore to determine if it is empty

How do I determine if a $var is empty in php5?
would I use integers instead ?

if ($var==0){
echo "You have a empty Var";

I just found out about the $request not to long ago.
I am half way descent for starting to learn php to to long ago. So all's I can do right now is study the code and look up what I don't understand. (alot lol)


LOL I know I am pry getting off track so i am going to leave it at that for tigh now.
Thanks for any and all help so far.
I know these are kinda of

I am going to search
Post Reply