NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page what does this code mean?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 12-30-2006, 08:37 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes

what does this code mean?


Hey
i m reading a tutorial and they dont really explain what this line means:
PHP Code:
$username = (@$_SESSION['username']) ? @$_SESSION['username'] : @$_COOKIE['username']; 
unknowngiver is offline  
Old 12-30-2006, 11:19 PM   #2 (permalink)
NamePros Regular
 
Noobie's Avatar
Join Date: Feb 2006
Location: Montreal, Quebec, Canada
Posts: 324
Noobie is on a distinguished road
 



DUnno why they use the @ but it means

PHP Code:
if($_SESSION['username']){
????: NamePros.com http://www.namepros.com/programming/275047-what-does-this-code-mean.html
 
$username $_SESSION['username'];
}else{
$username $_COOKIE['username'];

I guess if the session variable 'username' isn't empty, assign it to variable username, else assign the cookie 'username' to the variable 'username'
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline  
Old 12-31-2006, 06:53 AM   #3 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
They have put the @ there I believe in case the session is not initialized. If it is not you would get a warning (an @ sign suppresses warnings).
Peter is offline  
Old 12-31-2006, 07:21 AM   #4 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
To add to what has been said, the line is what is called a ternary operator. I wrote a tutorial about them here:

http://www.zoomcities.com/forum/showthread.php?tid=2362

I do not know why they have used the @ sign to suppress a potential warning either as there will not be one. That line i actually better written as:

PHP Code:
$username = (strlen($_SESSION['username']) > 0) ? $_SESSION['username'] : $_COOKIE['username']; 
????: NamePros.com http://www.namepros.com/showthread.php?t=275047
Matthew. is offline  
Old 12-31-2006, 10:33 AM   #5 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by Matthew.
I do not know why they have used the @ sign to suppress a potential warning either as there will not be one. That line i actually better written as:
Actually that depends on what error level you have php set as. If you have it set as E_ALL then the following errors will be encountered:-

Quote:
Notice: Undefined variable: _SESSION in PHPDocument1 on line 3
????: NamePros.com http://www.namepros.com/showthread.php?t=275047

Notice: Undefined index: username in PHPDocument1 on line 3
The reason you do not get errors will be because you have it set to a lower level .
Peter is offline  
Old 12-31-2006, 10:48 AM   #6 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
True, i tend to advise most people to ignore notices unless they want to spend 90% of their time on endless pursuits of perfection.

PHP Code:
error_reporting(E_ALL E_NOTICE); 
????: NamePros.com http://www.namepros.com/showthread.php?t=275047
FTW lol.
Matthew. is offline  
Old 12-31-2006, 11:39 AM   #7 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by Matthew.
True, i tend to advise most people to ignore notices unless they want to spend 90% of their time on endless pursuits of perfection.
????: NamePros.com http://www.namepros.com/showthread.php?t=275047

PHP Code:
error_reporting(E_ALL E_NOTICE); 
FTW lol.
I agree that you should use E_ALL ^ E_NOTICE on a production server but I always prefer to run E_ALL when testing. Any script you write SHOULD be able to be run without the need to suppress the notices.
Peter is offline  
Old 01-01-2007, 03:05 AM   #8 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 584
jerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to all
 



Originally Posted by filth@flexiwebhost
Originally Posted by Matthew.
True, i tend to advise most people to ignore notices unless they want to spend 90% of their time on endless pursuits of perfection.

PHP Code:
error_reporting(E_ALL E_NOTICE); 
FTW lol.
I agree that you should use E_ALL ^ E_NOTICE on a production server but I always prefer to run E_ALL when testing. Any script you write SHOULD be able to be run without the need to suppress the notices.
It is sometimes tedious to remove all notices, especially when using libraries.
????: NamePros.com http://www.namepros.com/showthread.php?t=275047
A suggestion would be to use php.ini or htaccess to change display_errors to off.
Errors may reveal information to aid a hacking attempt.
jerometan is offline  
Old 01-01-2007, 03:14 AM   #9 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Showing all notices can be very annoying, for example if i did:
PHP Code:
if($_GET[code'] == 21) { 
????: NamePros.com http://www.namepros.com/showthread.php?t=275047
And code wasn't active, it would mean that i would have to put in more code above that to check, and to be honest in my opinion its just a waste of time and space.
beaver6813 is offline  
Old 01-01-2007, 05:41 AM   #10 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
Originally Posted by beaver6813
Showing all notices can be very annoying, for example if i did:
PHP Code:
if($_GET[code'] == 21) { 
And code wasn't active, it would mean that i would have to put in more code above that to check, and to be honest in my opinion its just a waste of time and space.
If you did that you would get one whopping parser error lol
Matthew. is offline  
Old 01-01-2007, 05:59 AM   #11 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Originally Posted by beaver6813
Showing all notices can be very annoying, for example if i did:
PHP Code:
if($_GET[code'] == 21) { 
????: NamePros.com http://www.namepros.com/showthread.php?t=275047
And code wasn't active, it would mean that i would have to put in more code above that to check, and to be honest in my opinion its just a waste of time and space.

all it would take to fix that notice is using the isset function on $_GET['code'] so the code would end up:-

PHP Code:
if(isset($_GET['code']) && $_GET['code'] == 21) { 
(also helps to put the right amount of quotes in)
Peter is offline  
Old 01-01-2007, 07:45 AM   #12 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




Originally Posted by filth@flexiwebhost
all it would take to fix that notice is using the isset function on $_GET['code'] so the code would end up:-

PHP Code:
if(isset($_GET['code']) && $_GET['code'] == 21) { 
????: NamePros.com http://www.namepros.com/showthread.php?t=275047
(also helps to put the right amount of quotes in)
Gimme a break
beaver6813 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:08 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger