- This topic is empty.
-
AuthorPosts
-
September 10, 2014 at 7:36 pm #182569chrisburtonParticipant
How many times do you have session_start() throughout your code?
September 10, 2014 at 9:09 pm #182577__ParticipantYou should only be calling
session_start
once per script execution. If you’re calling it multiple times, each subsequent call is generating an error (if you don’t see these errors, then you have your error reporting configured wrong).I’m sure I’ve asked you before, but I am absentminded and cannot bring myself to look through the two dozen pages of this discussion: what version of PHP are you running?
Since PHP 5.4, you can use
session_status
to check if a session has been started yet:if( session_status() === PHP_SESSION_NONE ){ session_start(); }
Otherwise, you’ll need to check whether
session_id
returns an empty string.Another solution would be to redesign your application with a “single point of entry,” so you have fuller control over the program flow. Not that I’m saying you have to do that at this point.
September 10, 2014 at 9:11 pm #182579chrisburtonParticipantI don’t think he was calling it where he’s receiving an error, just every time he initiates needing the data to be stored into a session, which is where I was going with your last paragraph.
September 10, 2014 at 9:25 pm #182585__ParticipantRight, it wouldn’t be stopping the script. It’s either a Notice or a Strict Standards warning (I forget). But it’s still something that should be fixed.
September 11, 2014 at 2:31 pm #182665chrisburtonParticipantRight, it wouldn’t be stopping the script. It’s either a Notice or a Strict Standards warning (I forget). But it’s still something that should be fixed.
Ah. I thought it would in fact throw an error. I wonder if he’s receiving a notice in his logs at all. I certainly agree on the single-point-of-entry method if you’re referring to one session overall. In the video series, this is what the programmer is doing.
September 11, 2014 at 4:34 pm #182680chrisburtonParticipant@drose379 Eh. Somewhat. I was periodically working on this comment system I’m building for Kirby CMS but as I learn more, I rethink how I’m applying the code. So I’ve taken a step back to focus on educating myself rather than my previous method.
September 11, 2014 at 4:38 pm #182682chrisburtonParticipantCan you elaborate?
September 11, 2014 at 4:46 pm #182684chrisburtonParticipantAh, yes. I like to do it that way too but I’m also a visual learner so I have see and hear the logic and context within tutorials.
September 11, 2014 at 5:00 pm #182686chrisburtonParticipantWell, I don’t know that much in regards to OOP with PHP. Still quite a novice but yes, this is the first.
September 11, 2014 at 7:16 pm #182691__ParticipantAh. I thought it would in fact throw an error.
Notices and Strict Standards are errors. Just not fatal. PHP is designed to keep going at all costs, which is good in some sense but not in others. You should pay attention to all errors, especially during development. Think of it this way: it’s doing something it shouldn’t be, so go fix it.
the single-point-of-entry method if you’re referring to one session overall…
“Single Point of Entry” means that there is only one script/ function/ whatever that all requests go through.
For example, a typical php project might have
index.php
,contact.php
,about.php
, etc.. Each is a point of entry: users visit these pages directly, and they do {whatever} without regard to the system as a whole. This design is easier to code, but creates more work keeping everything in sync, and in making sure that when scripts do interact, they do so smoothly.In contrast, another project might have all of those functions, but when you visit the
index
orcontact
orabout
url your request is actually handled by a single script (say,app.php
) which does common setup work, then manages doing the requested task, then cleans up, and so forth. None of the individual “task” scripts are actually accessible individually.September 12, 2014 at 3:18 pm #182806chrisburtonParticipant@drose379 Can you post your forum and comments table?
September 12, 2014 at 3:21 pm #182807__ParticipantFor some reason prepared statement 2 won’t run unless stmt 1 is closed.
One connection, two queries, that’s why. The database is waiting for you to finish with the first query, it can’t do a second query without abandoning that.
I cannot close the statement because I have to use it to echo out the forum posts.
You don’t have to. I recommend against generating output directly from fetching a query. If something goes wrong, it’s harder to fix. Some alternatives:
- Fetch the first set of results and store the info you need in a variable. Close the first query, and run the second.
-
multi_query
might be suitable for what you’re doing, if you already know everything you need to write both queries (i.e., the composition of the second query does not depend on the results of the first). So, something like this would work just fine:
$SQL = "select this from table1 where id=7;" ."select that from table2 where id=7;"
but something like this would not:
$SQL = "select this from table1 where id=7;" ."select that from table2 where this = query1.this;"
Have I ever used it? Yes. But it’s usually not necessary. And I don’t use it much anymore, in favor of stored procedures.
September 12, 2014 at 3:33 pm #182810chrisburtonParticipantHas anyone helped you set up your database?
September 12, 2014 at 3:50 pm #182813chrisburtonParticipantI was told to split up the comments from the actual forum posts
Right. Totally agree with that. Just curious as to how you set it up exactly. The only difference with your forum compared to my comment system is that you created custom login script where I use Opauth for social login (Twitter, Facebook, Instagram, Google and Yahoo accounts). That way people don’t have to waste time filling out a form.
September 12, 2014 at 3:56 pm #182817chrisburtonParticipantUse in what way? What is your output?
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.