...

View Full Version : Please help me to change my PHP4 Code to PHP5



shubho
01-20-2010, 11:02 AM
Hallo
I have code written php4,but my server supports php5.I need to change the code from php4 to php5.Please help me,what should i change to my code to convert my code



<?php
require_once('config/config.php');
require_once('config/func.php');

$PageTitle='User \'' . $_SESSION['login'] . '\'';
if(!user_auth())
header("Location: users.php");
$opis=stripslashes($_POST['opis']);
if(($_POST['a']=='check' || $_POST['a']=='add') && $_GET['f']=='add')
{
$name=stripslashes($_POST['name']);
$name=str_replace("'", '&acute;', $name);
$url=$_POST['url'];
$mail=$_POST['mail'];
$forum=$_POST['forum'];
$feedback=$_POST['feedback'];
$icq=$_POST['icq'];
$phone=$_POST['phone'];
$min_payout=$_POST['min_payout'];
$min_deposit=$_POST['min_deposit'];
$referral=str_replace('"', '&quot;', $_POST['referral']);
$time_payout=$_POST['time_payout'];
$payements=$_POST['payements'];
if(!empty($name) && (strlen($name)>1) && !empty($url) && !empty($mail) && !empty($min_payout) && !empty($time_payout) && !empty($payements) && (count($payements)>=1))
{
if(preg_match("/^http[s]*:\/\/.+\..+$/i", $url))
{
if(preg_match("/.+@.+\..+/", $mail))
{
if(strlen($opis)<350)
{
if(count($payements)<=count($PayoutMethods))
{
if($r=mysql_query("SELECT `id_program` FROM `programs` WHERE `nazwa`='$name'"))
{
if(mysql_num_rows($r)==0)
{
if($_POST['a']=='add')
{
foreach($payements as $method=>$value)
${$method}=($value=='on') ? '*' : '';
$id=$_SESSION['id_user'];
$data=date("Y-m-d");
$sql="INSERT INTO `programs` VALUES(
' ',
'$id',
'$name',
'$url',
'$opis',
'$mail',
'$forum',
'$feedback',
'$phone',
'$icq',
'$data',
'0',
'0',
'$min_payout',
'$min_deposit',
'$time_payout',
'$referral',
'0',
'',
'',
'',
'',
";
foreach($PayoutMethods as $n=>$method)
$sql.="'". ${$n} ."',";
$sql.="'')";

if(mysql_query($sql))
{
$added=true;
$new_id=mysql_insert_id();
}
else
$error='Error in SQL query. Cannot add program. Please contact with administrator. MySQL: ' . mysql_error();
}
else
{
if(($forum=='http://') || (strlen($forum)<5))
$forum='';
if(($feedback=='http://') || (strlen($feedback)<5))
$feedback='';
}
$go=true;
session_register('go');
}
else
$error='This name of program is in database, select other.';
}
else
$error='Error in SQL query. Cannot add program. Please contact with administrator. MySQL: ' . mysql_error();
}
else
$error='To math selected payements!';
}
else
$error='Too long description!';
}
else
$error='Incorrect e-mail address!';
}
else
$error='Wrong site url!';
}
else
$error='Fill all required fields!';
}
elseif($_POST['a']=='edit' && $_GET['f']=='edit')
{
$opis=$_POST['opis'];
$forum=$_POST['forum'];
$feedback=$_POST['feedback'];
$icq=$_POST['icq'];
$phone=$_POST['phone'];
$min_payout=$_POST['min_payout'];
$time_payout=$_POST['time_payout'];
$referral=$_POST['referral'];
$payements=$_POST['payements'];

$no=$_POST['no'];
$id=$_SESSION['id_user'];

if(!empty($min_payout) && !empty($time_payout) && (count($payements)>0))
{
foreach($payements as $method=>$value)
${$method}=($value=='on') ? '*' : '';

$sql="UPDATE `programs` SET
`opis`='$opis',
`forum`='$forum',
`feedback`='$feedback',
`icq`='$icq',
`telefon`='$phone',
`min_payout`='$min_payout',
`time_payout`='$time_payout',
`referral`='$referral',";

foreach($PayoutMethods as $n=>$method)
$sql.="`". $n ."`='". ${$n} ."',";

$sql=substr($sql, 0, strlen($sql)-1) . " WHERE `id_program`='$no' AND `id_user`='$id'";

if(mysql_query($sql))
{
$edited=true;
}
else
$error='Error in SQL query! Cannot edit program. Please contact with administrator. MySQL: ' . mysql_error();
}
else
$error='Fill required fields!';
}
elseif($_GET['f']=='profil' && $_POST['a']=='edit')
{
$id=$_SESSION['id_user'];
$password_c=$_POST['password_text'];
$repassword=$_POST['repassword'];
$mail=$_POST['mail'];
$name=str_replace('"', '&quot;', $_POST['name']);
$country=$_POST['country'];
$region=str_replace('"', '&quot;', $_POST['region']);
$year=$_POST['year'];

if(strlen($password_c) && strlen($mail) && strlen($name)
&& strlen($country) && strlen($year) && (strlen($password_c)<16))
{
$error=NULL;
$added=false;

if(CheckPass($password_c))
{
if(preg_match("/.+@.+\..+/", $mail))
{
if(!empty($repassword))
{
if($password_c==$repassword)
$newpass=true;
else
$error='Repeat password is wrong!';
}
else
{
if(decode($_SESSION['password'])==$password_c)
$newpass=false;
else
$error='Wrong Password';
}

if($r=mysql_query("SELECT `mail` FROM `users` WHERE `id_user`='$id'"))
{
if(mysql_num_rows($r)==1)
{
$m=mysql_result($r, 0, 0);
$newmail=$m!=$mail;
if($newmail)
{
$t=explode(' ', microtime());
$ui=uniqid($t[1]);
$msg="Please confirm new e-mail adress on the ". PageTitle ." of user '" . $_SESSION['login'] . "'.<br><br> <a href=\"http://". PageAddress ."/users.php?a=activate&u=$id&m=mail&ui=$ui\">http://". PageAddress ."/users.php?a=activate&u=$id&m=mail&ui=$ui</a> \n\nIf you don't accept this adress ignore this message.<br><br>Administrator<br>". PageTitle;
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: ". PageTitle ." <>\n";
if(!mail($mail, 'Confirm new e-mail address', $msg, $headers))
$error='Error when trying editing mail';
}
}
else
$error='Error! No information about your e-mail!';
}
else
$error='Error in SQL query. Cannot edit information';

if(!strlen($error))
{
$password_c=encode($password_c);
$sql="UPDATE `users` SET `name`='$name', `kraj`='$country', `region`='$region', `rok_urodzenia`='$year'";
$sql.=($newpass===true) ? ', `haslo`=\'' . $password_c . '\'' : '';
$sql.=($newmail) ? ', `new_mail`=\'' . $mail . ';' . $ui . '\'' : '';
$sql.=" WHERE `id_user`='$id'";

if(mysql_query($sql))
{
$edited=true;
$password=$password_c;
session_register('password');
}
else
$error='Error in SQL query. Cannot edit information about user! MySQL: ' . mysql_error();
}
}
else
$error='Incorrect e-mail address!!';
}
else
$error='You have forbidden characters in password!';
}
else
$error='Fill all fields!';
}

require('config/begin.php');

$titles=array('programs'=>'Your programs', 'add'=>'Add program', 'profil'=>'Profil', 'del'=>'Delete Program', 'edit'=>'Edit program', 'code'=>'Banner code');
if(empty($_GET['f']) || !array_key_exists($_GET['f'], $titles))
$_GET['f']='programs';
?>
<SCRIPT LANGUAGE="JAVASCRIPT">
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
countfield.value = maxlimit - field.value.length;
}
</SCRIPT>
<table width="600" border="0" align="center">
<tr>
<td>
<h1><?php echo $titles[$_GET['f']]; ?></h1>
</td>
</tr>
<tr>
<td>
<?php
if($_GET['f']=='add')
{
if(($_POST['a']=='check' || $_POST['a']=='add') && $_SESSION['go']===true)
{
if($added===true)
{
echo'<div class="msg">Congratulations!<br><br>You are added new program. Program is waiting for adminitrator accept.<br><br></div>';
echo'<div style="text-align:center;font-weight:bold">Paste this code in your page:</div>
<div style="font-family:Courier New;text-align:center">
&lt;a href="http://'. PageAddress .'/programs.php?m=details&amp;id='. $new_id .'" target="_blank"&gt;&lt;img src="http://' . PageAddress .'/img.php?id='. $new_id .'" width="110" height="120"&gt;&lt;/a&gt;
</div><br><br>';
}

if(strlen($error))
error($error . ' <a href="javascript:history.go(-1)">return</a>');

echo "<form action=\"edit.php?f=add\" method=\"post\" style=\"margin-top:0px\">
<input type=\"hidden\" name=\"a\" value=\"add\">

<input type=\"hidden\" name=\"name\" value=\"$name\">
<input type=\"hidden\" name=\"url\" value=\"$url\">
<input type=\"hidden\" name=\"mail\" value=\"$mail\">
<input type=\"hidden\" name=\"opis\" value=\"$opis\">
<input type=\"hidden\" name=\"forum\" value=\"$forum\">
<input type=\"hidden\" name=\"feedback\" value=\"$feedback\">
<input type=\"hidden\" name=\"icq\" value=\"$icq\">
<input type=\"hidden\" name=\"phone\" value=\"$phone\">
<input type=\"hidden\" name=\"min_payout\" value=\"$min_payout\">
<input type=\"hidden\" name=\"min_deposit\" value=\"$min_deposit\">
<input type=\"hidden\" name=\"referral\" value=\"$referral\">
<input type=\"hidden\" name=\"time_payout\" value=\"$time_payout\">";

foreach($PayoutMethods as $n=>$method)
echo '<input type="hidden" name="payements['. $n .']" value="'. $payements[$n] .'">';

echo "<table style=\"width:350px; background-color:#eeeeee\" align=\"center\">
<tr><td style=\"width:90px\">Program name:</td><td><b>$name</b></td></tr>
<tr><td>Site url:</td><td><b>$url</b></td></tr>
<tr><td>E-mail:</td><td><b>$mail</b></td></tr>
<tr><td valign=\"top\">Description:</td><td><b>$opis</b></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Forum url:</td><td><b>". ((!empty($forum)) ? $forum : ' - ') ."</b></td></tr>
<tr><td>Feedback:</td><td><b>". ((!empty($feedback)) ? $feedback : ' - ') ."</b></td></tr>
<tr><td>ICQ:</td><td><b>". ((!empty($icq)) ? $icq : ' - ') ."</b></td></tr>
<tr><td>Phone:</td><td><b>". ((!empty($phone)) ? $phone : ' - ') ."</b></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Minimum deposit:</td><td><b>". ((!empty($min_payout)) ? $min_payout . ' USD' : ' - ') ."</b></td></tr>
<tr><td>Maximum deposit:</td><td><b>". ((!empty($min_deposit)) ? $min_deposit : ' - ') ."</b></td></tr>
<tr><td>referral bonus:</td><td><b>". ((!empty($referral)) ? $referral : ' - ') ."</b></td></tr>
<tr><td valign=\"top\">Payements:</td>
<td>";
foreach($payements as $method=>$on)
echo "<b>&middot; $method</b><br>";
echo ' </td>
</tr>';

if($added!=true)
{
echo '<tr>
<td colspan="2" style="text-align:center; border-top:1px solid #666666">
<input type="button" value=" RETURN " onClick="history.go(-1);" style="margin-top:5px">
&nbsp;&nbsp;<input type="button" value="ACCEPT" style="margin-top:5px" onClick="this.form.submit();this.disabled=true">
</td>
</tr>';
}
echo '</table>
</form>';

session_unregister('go');
}
else
{
if(strlen($error))
error($error . ' <a href="javascript:history.go(-1)">return</a>');
?>
<form action="edit.php?f=add" style="margin:0px" method="post">
<input type="hidden" name="a" value="check">
<table style="width:400px" align="center">
<tr>
<td colspan="2"><div class="form_header">General info</div></td>
</tr>
<tr>
<td style="width:90px">Program name:<b>*</b></td><td><input type="text" name="name" style="width:150px" value="<?php echo $_POST['name'] ?>"></td>
</tr>
<tr>
<td>Site url:<b>*</b></td><td><input type="text" name="url" style="width:150px" value="<?php echo ((!empty($_POST['url'])) ? $_POST['url'] : 'http://') ?>"></td>
</tr>
<tr>
<td>e-mail:<b>*</b></td><td><input type="text" name="mail" maxlength="40" style="width:150px" value="<?php echo $_POST['mail'] ?>"></td>
</tr>
<tr>
<td valign="top">Description:</td><td><textarea name="opis" cols="55" rows="5" onKeyPress="textCounter(this.form.opis,this.form.remLen,350);" onKeyUp="textCounter(this.form.opis,this.form.remLen,350);"><?php echo $_POST['opis'] ?></textarea>
<input type="text" readonly name="remLen" maxlength="3" size="3" value="350"> <span style="color:#666666">characters left</span>
</td>
</tr>
<tr>
<td colspan="2"><div class="form_header">Contact</div></td>
</tr>
<tr>
<td>Forum url:</td><td><input type="text" name="forum" style="width:150px" value="<?php echo ((!empty($_POST['forum'])) ? $_POST['forum'] : 'http://') ?>"></td>
</tr>
<tr>
<td>Feedback url:</td><td><input type="text" name="feedback" style="width:150px" value="<?php echo ((!empty($_POST['feedback'])) ? $_POST['feedback'] : 'http://') ?>"></td>
</tr>
<tr>
<td>Phone:</td><td><input type="text" name="phone" style="width:150px" value="<?php echo $_POST['phone'] ?>"></td>
</tr>
<tr>
<td>ICQ:</td><td><input type="text" name="icq" style="width:150px" value="<?php echo $_POST['icq'] ?>"></td>
</tr>
<tr>
<td colspan="2"><div class="form_header">Payements</div></td>
</tr>
<tr>
<td>Minimum deposit:<b>*</b></td><td><input type="text" name="min_payout" style="width:150px" value="<?php echo $_POST['min_payout'] ?>"> USD</td>
</tr>
<tr>
<td>Maximum deposit:</td><td><input type="text" name="min_deposit" style="width:150px" value="<?php echo $_POST['min_deposit'] ?>"></td>
</tr>
<tr>
<td valign="top">Interest Rate:<b>*</b></td><td><textarea name="time_payout" cols="30" rows="3"><?php echo $_POST['time_payout'] ?></textarea></td>
</tr>
<tr>
<td>Referral Bonus:</td><td><input type="text" name="referral" maxlength="40" style="width:150px" value="<?php echo $_POST['referral'] ?>"></td>
</tr>
<tr>
<td valign="top">Payements:<b>*</b></td>
<td>
<?php
foreach($PayoutMethods as $name=>$method)
{
if(empty($_POST['payements']) && $name=='egold')
echo '<input type="checkbox" name="payements['. $name .']" class="check" checked> E-gold<br>';
else
echo '<input type="checkbox" name="payements['. $name .']" class="check"'. (($_POST['payements'][$name]=='on') ? ' checked' : '') .'> '. $method .'<br>';
}
?>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center; border-top:1px solid #666666"><input type="reset" value=" RESET " style="margin-top:5px">&nbsp;&nbsp;<input type="submit" value="SUBMIT" style="margin-top:5px"></td>
</tr>
<tr>
<td colspan="2"><b>* Required field</b></td></tr>
</table>
</form>
<?php
}
}
elseif($_GET['f']=='profil')
{
$id=$_SESSION['id_user'];
if(strlen($error))
error($error);
if($edited===true)
{
switch_page('edit.php', '<br><br>User edited!<br><br>', 3000);
echo '<div class="msg"">In moment you be become relogged in.</div><br><br><br>';
}

if($edited!=true)
{
if($result=mysql_query("SELECT * FROM `users` WHERE `id_user`='$id'"))
{
if(mysql_num_rows($result))
{
$d=mysql_fetch_assoc($result);
?>
<form action="edit.php?f=profil" method="post">
<input type="hidden" name="a" value="edit">
<table align="center" border="0">
<tr><td width="110">Login: </td><td width="300"><div class="enabled"><?php echo $d['login'] ?></div></td></tr>
<tr><td>Password<b>**</b>: </td><td><input type="password" name="password_text" style="width: 150px" maxlength="15"></td></tr>
<tr><td>Repeat password<b>***</b>: </td><td><input type="password" name="repassword" style="width: 150px" maxlength="15"></td></tr>
<tr><td>E-mail: </td><td><input type="text" name="mail" style="width: 150px" maxlength="32" value="<?php echo (empty($_POST['mail'])) ? $d['mail'] : $_POST['mail'] ?>"></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Name and surname:

Scrumpy.Gums
01-20-2010, 12:01 PM
Are there any specific problems with the code? What do you expect to see and what actually happens? Do you get any error messages?

Fou-Lu
01-20-2010, 02:32 PM
Quick scan over here, the only thing you should change is session_unregister to unset($_SESSION['go']);. Thats not related to PHP5, so much as its related to the usage of register_globals.

Otherwise, this should run fine in PHP5 from the looks of it.

Len Whistler
01-20-2010, 09:47 PM
Are you getting "Notice: Undefined index: *************" errors? I'm getting those errors and assume that it has something to do with PHP5+.

These sort of lines create the error: $mail=$_POST['mail']; I solved it by putting error_reporting(0); into the header.php file, I can't figure out the correct syntax to fix this problem.



------------

JAY6390
01-20-2010, 10:21 PM
This is how to fix those errors
http://forum.phpvideotutorials.com/showthread.php?t=3713

Fou-Lu
01-20-2010, 10:49 PM
There is a really cheap trick to get around indexing problems, but I hate to tell people (since its kinda a bad way to do it).


$var = &$_POST['var'];


All done. By default, if a variable does not exist, it will be assigned as null. The only two problems with the above is 1: you don't know if it really exists, and 2: if you change the $var or $_POST['var'] it will of course change the referenced variable.

This is the kind of thing I'd use if I were to later check things so as to short cut them:


$s = &$_POST['mysuperlongstringthatIdontwanttotypeineverytime'];
if(!empty($s) && is_string($s) && $s == 'helloworld')
{
print 'all good.';
}

Len Whistler
01-20-2010, 10:52 PM
How about:


$id = isset($_GET['id']) ? $_GET['id'] : 1; //Defaults to 1

That's the solution in the link JAY6390 provided.




-------------------

JAY6390
01-20-2010, 11:16 PM
Yes that's fine Len

@ Fou-Lu - Can't say I've seen that before but it's pretty neat

Fou-Lu
01-20-2010, 11:18 PM
How about:


$id = isset($_GET['id']) ? $_GET['id'] : 1; //Defaults to 1

That's the solution in the link JAY6390 provided.




-------------------


Yep, thats the way I usually do it. Just if I have an obscenely large index name (like I had above) do I short cut it and perform validation after. The benefit is you don't need to check if isset anymore, since you know it will be :P

Len Whistler
01-20-2010, 11:20 PM
Yes that's fine Len

OK ..... i will have to give it a try. I got it copied into my code snippet file.




----------------------------------



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum