简体   繁体   中英

Can I connect() without session_start()?

I have found no clear explanation if it is possible to allow someone to visit a page that requires a connection to a database without any need for a session to start.

I cleared the session_start etc from some pages and the pages died

EXAMPLE CASE

If I click on a url that has been created with $_GET...

www.site.xxx/cat.php/?cat=hitlermoustachefunnyhaha

will that page require a session_start etc to be able to fetch data from the database?

POSTSCRIPT Error indeed found to be Human. As suggested by answerers if you simply convert a page written with one logic sequence it means all code logic had to be refollowed and ALL validation processes need to be skipped. DOH!

Strange question. answer is: depends on your code.

you need session_start() to start the session, and be able to get information from the session. If you do not use information from the session, you'll be able to do what you want.

So while technically the answer is "no", the session was there for a reason, and together with "the pages died" the answer is probably yes.

It looks like you do not know your codebase that well, so you need to look around. Go look for LOC with $_SESSION in them. IF they are used for building queries or stuff, then you obviously need the session.

No, you don't need sessions to use a database connection. Those are completely independent.

Nope. You do not need a session in order to fetch data from a database. But, the PHP code can also check for a session and die if it doesn't find one. Do you have any code to give? If so, I could better answer your question and possibly give you a reason why the page dies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM