Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2008-07-16, 02:20 PM
Junior Member
 
Join Date: May 2008
Posts: 3
xited1@cox.net is on a distinguished road
Default Explain please...in plain english

So I'm guilty of copying and pasting or writing code that I don't fully understand, I just know it's supposed to do something from all the books and tutorials and forum posts. I have this one snippet of code that I would like someone to explain to me what all the characters are for and what exactly the code is supposed to do. Can someone help me out here? (I do know the session start part of it...imagine that!)

Code:
<?
session_start();  
if (@$_SESSION['auth'] != "yes")

{
	header("Location: register.php");
	exit();
}  
  
?>
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2008-07-21, 05:11 AM
Junior Member
 
Join Date: Apr 2008
Location: Cheltenham, UK
Posts: 12
hoopyfrood is on a distinguished road
Default

Quote:
Originally Posted by xited1@cox.net View Post
So I'm guilty of copying and pasting or writing code that I don't fully understand, I just know it's supposed to do something from all the books and tutorials and forum posts. I have this one snippet of code that I would like someone to explain to me what all the characters are for and what exactly the code is supposed to do. Can someone help me out here? (I do know the session start part of it...imagine that!)

Code:
<?
session_start();  
if (@$_SESSION['auth'] != "yes")

{
    header("Location: register.php");
    exit();
}  
  
?>
Hiya,

basically line-by-line:
1) start the session
2) check if session variable "auth" is set - the "at - @" is there to surpress any warning messages in case the session variable is not set yet
3) if the session variable does not exist redirect to the register page (if you want it to redirect elsewhere you could try: header('Location: ./inc/register.php') or header('Location: ' . $_SERVER['PHP_SELF'] . '?page=register')...
4) exit() is there to make sure none of the code below redirection to another page gets executed, personally I believe it is a blast from the past when PHP use to do that but you can't do any harm leaving it there - I do...

Good luck,
hoopyfrood
__________________
Love your documents!

DocuView - The best Web 2.0 document management system (DMS) - utilising the latest technology to help your company achieve ISO 9001 certification.
Reply With Quote
  #3 (permalink)  
Old 2008-07-21, 09:30 PM
Junior Member
 
Join Date: May 2008
Posts: 3
xited1@cox.net is on a distinguished road
Default Yay! I got a reply!

Thank you so much for answering!

Just so I'm clear on this.....
the 'auth' means that the user has registered and is now "authorized"?? to view this page, and if the user is not registered it redirects them to the registration page?

I know some people are laughing and shaking their heads at me. But, when you're a novice it is really hard to find answers to these questions, I took an online class to learn PHP, which is now over, so no help there, and I bought some books, but they are sometimes too technical and I can't ask the book questions on how to apply what they are demonstrating for my own uses. So I search these sites to find my answers and useful code snippets to use.

Thanks again!
Reply With Quote
  #4 (permalink)  
Old 2008-08-26, 11:12 AM
Junior Member
 
Join Date: Aug 2008
Posts: 2
vbplusme is on a distinguished road
Send a message via Yahoo to vbplusme Send a message via Skype™ to vbplusme
Default

Not quite. The conditional is checking if the value of $_session['auth'] is set to "yes". Generally, and in this case when the user logs into their account the $_SESSION['auth'] flag gets set to "yes" as part of the login procedure. If the flag is not set to "yes" the script send the user to the registration page.

HTH,

vbplusme
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:37 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.