Need help with $this issue
10-22-2007, 10:40 PM
|
Need help with $this issue
|
Posts: 8
|
I am getting the error like this:
Fatal error: Using $this when not in object context in /home/supeco/public_html/user.php on line 71
In user.php file's line#71, I see $this is used like this:
$hash = md5($this->secret.$HTTP_POST_VARS['username'])
It worked before my isp upgrade to php 5.
How should I change above $this usage so it will compatible with new php5??
Thanks.
|
|
|
|
10-23-2007, 01:45 AM
|
Re: Need help with $this issue
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Can you provide more code?
From the looks of it I think you are making a call to $this outside of the scope of an object.
Btw is this for a facebook app? Just wondering because the code looks familiar.
|
|
|
|
10-23-2007, 10:17 PM
|
Re: Need help with $this issue
|
Posts: 8
|
This is a part of php portal script from old days.
I did visit this thread (URL: http://www.webmaster-talk.com/php-fo...ot-object.html) too but still no idea how to fix mine
Here are a few lines.
$page_code = "user";
$page_name = LANG_USERDETAILS;
// Header file
include_once("$lib/themelib.php");
// Did the user filled the registration form?
if ((!$HTTP_POST_VARS['username']) || (!$HTTP_POST_VARS['password'])) {
// If not, go to registration form
header("Location: $root_url/register.php");
exit;
}
echo siteTheme ("header");
// If YES, start registration actions
// Hash code for confirmation mail
$hash = md5($this->secret.$HTTP_POST_VARS['username']);
// Connect database
dbconnect();
// Register user
$fullname = htmlspecialchars($FirstName)." ".htmlspecialchars($surname);
$sql = "INSERT INTO $t_users
(gender, name, surname, fullname, birthdate, country, address, state, city, zip, tel, job, email, list, hide_info, username,
password, hash, date, theme)
VALUES
('$gender', '".htmlspecialchars($FirstName)."', '".htmlspecialchars($surname)."', '$fullname', '$birthdate', '".htmlspecialchars($country)."', '".htmlspecialchars($address)."','".htmlspecialcha rs($state)."','".htmlspecialchars($city)."','".htm lspecialchars($zip)."','".htmlspecialchars($tel)." ', '".htmlspecialchars($job)."', '".htmlspecialchars($email)."', '$list','$hide_info',
'" . $HTTP_POST_VARS['username'] . "', '" . md5($HTTP_POST_VARS['password'])."', '$hash', now(), '$def_theme') ";
$result = @mysql_query($sql) or die ("Can not register user");
Thank you.
Last edited by thura; 10-24-2007 at 11:17 PM..
|
|
|
|
10-24-2007, 03:32 AM
|
Re: Need help with $this issue
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
I can't tell from the code if you are using $this within an object. If you are not then $this doesn't have any meaning. The object model has been overhauled since PHP4 but generally most code is backwards compatible.
Again. Like the error says, make sure that you are not using $this outside of an object. If you give me more code I can help you out. Good luck 
|
|
|
|
10-30-2007, 11:02 PM
|
Re: Need help with $this issue
|
Posts: 8
|
Can you send me message so I may be can reply it back to you with the script. This is very inconvenient. I can't still send message to anyone. I don't know if I need to do the pay membership. No way to contact the webmaster too. Can someone read my message above and help me, please?
|
|
|
|
11-08-2007, 12:19 AM
|
Re: Need help with $this issue
|
Posts: 8
|
I've just sent the pm. Thanks.
|
|
|
|
11-08-2007, 08:12 AM
|
Re: Need help with $this issue
|
Posts: 880
Location: Leeds UK
|
NOTE:
$HTTP_POST_VARS is old use $_POST instead.
Also try concatanating the two vars '$md5 = $this->secret.$_POST['username']'
$hash = md5($md5)
Ibbo
|
|
|
|
11-09-2007, 02:05 AM
|
Re: Need help with $this issue
|
Posts: 8
|
I modified the script as you advised but still giving me the same errors.
|
|
|
|
11-12-2007, 11:21 AM
|
Re: Need help with $this issue
|
Posts: 880
Location: Leeds UK
|
Does $this->secret hold any info. Try echo it out and see. Try same with $HTTP_POST_VARS['username'];
Also try adding error_reporting (E^ALL); at the top of your script.
Ibbo
|
|
|
|
11-12-2007, 10:46 PM
|
Re: Need help with $this issue
|
Posts: 8
|
Thank you for your help.
I followed your advice, I echo out $this->secret and just used $HTTP_POST_VARS['username'];
The script is now almost working for registration but when user log back in to the site, the new error is displayed as:
Warning: Cannot modify header information - headers already sent by (output started at /home/supeco/public_html/library/themelib.php:565) in /home/supeco/public_html/user.php on line 13
Is it http issue? Can you help me fix it, please?
Thank you.
|
|
|
|
11-13-2007, 03:38 PM
|
Re: Need help with $this issue
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Make sure you're not generating any output before you use the header function. If you echo or print anything you won't be able to forward to a new location. Most likely you've just left your echo $this->secret in your code, if you remove it that should fix your problem.
|
|
|
|
01-21-2008, 10:01 PM
|
Re: Need help with $this issue
|
Posts: 80
Name: Carlos
|
Maybe you out from an Object. $this refer to an object. If you out of an object or you dont sure, make:
print_r($this);
And watch what is $this 
__________________
-----------------------
Please login or register to view this content. Registration is FREE
|
|
|
|
|
« Reply to Need help with $this issue
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|