Page 1 of 1
variable declearation... "@$variable"
Posted: Thu May 22, 2008 11:53 am
by bwan37
I am new to PHP... very very dumb in it..
my file... "login.php" require a variable "$_REQUEST['username'] to check for login..
but I got an error...
Undefined index: username in D:\public_html...
after decleared my variable to "@$_REQUEST['username']"
the error is gone..
question:
what does "@" in front of the variable does?
Thank you so much!!
Sincerely,
Ben
Re: variable declearation... "@$variable"
Posted: Thu May 22, 2008 12:49 pm
by nowaydown1
Hi Ben,
The @ operator tells PHP to stop it's complaining. This prevents it from outputting any notice/warning stuff to the page if display_errors is on in your php.ini.
Re: variable declearation... "@$variable"
Posted: Thu May 22, 2008 12:53 pm
by aditya2071990
placing the symbol '@' before any statement supresses all error messages and doesn't allow php to output them.
It is generally used before mysql functions like mysql_query(), mysql_connect() and so on.
That is done so that if the mysql function fails to execute properly, then instead of displaying the ugly error message it outputs, we can display a more decent error message like "Sorry, the database is F***ed up at the moment!"
In your case, there is a script error and php is only complaining that it can't run the script properly unless you correct it. By placing '@', u r telling it to shut up, so it aint saying anything.
But your code still won't work. There is an error which needs to be corrected. Put the whole script outta here (remember to delete the username and password in mysql connect functions).
We'll try to help.
Good Luck.
Re: variable declearation... "@$variable"
Posted: Fri May 23, 2008 2:14 pm
by bwan37
wow.. I understand it la..
um.. here's the code I wrote...
---------login.php----------
//url: http://localhost/login.php?site=my-nude-pic.php
<?php
$_loginInfo['user'] = 'myname';
$_loginInfo['pass'] = 'mypass';
//if successfully login (username & password is correct)
if( (
@$_REQUEST['user']==$_loginInfo['user']) && (
$_REQUEST['pass']==$_loginInfo['pass']) ) {
// goto "my-nude-pic.php"
}
//otherwise ask for username & password
else {
echo login_form();
}
//** FUNCTION BEGINS **//
// here's the necessary login forum
function login_form() {
$form = "<p class=heading>Login Page!</p>\n";
if(
@$_GET['site']!=null) { $site = "?site=".
$_GET['site']; }
$form .= "<form action='login.php".
@$site."' method='post' name=login_form>\n";
$form .= " Username : <input type='text' name='user' value=\"\">\n";
$form .= " Password : <input type='password' name='pass' value=\"\">\n";
$form .= " <input class='button' type='submit' value='Submit'>";
$form .= "</form>\n";
return $form;
}
?>
-----------------
what do you think the correct syntax should be, (if I don't use the @ in front of $var)?
Thank you very much..
