5 Replies - 450 Views - Last Post: 13 February 2011 - 01:09 AM Rate Topic: -----

#1 mdmartiny  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 28-May 10

A question about Sessions

Posted 12 February 2011 - 11:36 AM

After reading about sessions and cookies.
I have some knowledge of cookies and no knowledge of sessions

I have decided to go with session for a script that I am writing. I know to start a session you use session_start(). I would like to give that session to have a name.

Something like
$_Session['name'] = authorized


So every page that people go to the script calls for the authorized session name to make sure that it is valid. If it is not valid they are then routed back to the login page.

I have searched on Google for a tutorial or something that would show me with no success.

Is This A Good Question/Topic? 0
  • +

Replies To: A question about Sessions

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6032
  • View blog
  • Posts: 23,414
  • Joined: 23-August 08

Re: A question about Sessions

Posted 12 February 2011 - 11:40 AM

So you obviously read the docs, right?
Was This Post Helpful? 0
  • +
  • -

#3 mdmartiny  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 85
  • Joined: 28-May 10

Re: A question about Sessions

Posted 12 February 2011 - 11:51 AM

View PostJackOfAllTrades, on 12 February 2011 - 06:40 PM, said:

So you obviously read the docs, right?


I did read them and I tried setting one on my own. When I set the name to authorized and then try to

 if ($_SESSION['authorized'] != "yes" {
        header(Location: "login.php")
        $_SESSION['error'] = "PLEASE LOGIN!!!"
}



Nothing happens.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3476
  • View blog
  • Posts: 10,013
  • Joined: 08-June 10

Re: A question about Sessions

Posted 12 February 2011 - 12:33 PM

syntax error or typo on lines 1 - 3.

a session variable usually is not displayed in the output.

This post has been edited by Dormilich: 12 February 2011 - 12:34 PM

Was This Post Helpful? 0
  • +
  • -

#5 creativecoding  Icon User is offline

  • Hash != Encryption
  • member icon


Reputation: 926
  • View blog
  • Posts: 3,204
  • Joined: 19-January 10

Re: A question about Sessions

Posted 12 February 2011 - 03:57 PM

What is going on here?

 if ($_SESSION['authorized'] != "yes" {
        header(Location: "login.php")
        $_SESSION['error'] = "PLEASE LOGIN!!!"
}



should be

 if ($_SESSION['authorized'] != "yes") {
        header("Location: login.php");
        $_SESSION['error'] = "PLEASE LOGIN!!!";
}




Have you read a simple tutorial on PHP?

This post has been edited by Dormilich: 12 February 2011 - 03:58 PM
Reason for edit:: fixing typo

Was This Post Helpful? 1
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10364
  • View blog
  • Posts: 38,361
  • Joined: 27-December 08

Re: A question about Sessions

Posted 13 February 2011 - 01:09 AM

You should also change your variable's value before using the header() function, which redirects you to another page.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1