Jump to content

PHP Cookies


peter_sanders2

Recommended Posts

<p>Hello, all.<br>

I am creating a social network (freehand) as a sort of proof of concept. One thing I want to do is make it so that they (the user) will automatically be re-logged in using a PHP cookie when they return to the index page.<br>

I do not care about the security, because I am not allowing this onto the internet at large. Only my friends will be able to access the site (unless someone runs across it typing something random into the address bar).<br>

The site is structured:<br>

/index.php<br>

/user.php<br>

/verify.php<br>

/register.php<br>

/refister2.php<br>

/NoAccess.php<br>

I will later restructure it into domains, but that is irrelevant.</p>

<p>I want them to go to "../" such that it will default to index.php, and be redirected to "/verify.php" with their login info as the variables for username and password. This will cause them to be reverified and logged in. An alternative would be (and I need to know this anyway) how do you make variables carry to the next page?<br>

Also, how do I load the user page so that it will have those variables already in place when they are redirected from "../index.php"? (I had to put the "?" on the outside to indicate that it did not indicate a variable).</p>

<p>Also, it would be helpful if you could tell me how to run PHP documents from my PC, so that I can test it in real time.</p>

Link to comment
Share on other sites

<p>You need to install the LAMP stack on your local computer (or, ideally, a virtual machine running on that computer) so that you can see this stuff actually working.<br /><br />Maintain state (the value of variables) by storing those values in the database that retains the user data. That database will also know when they logged in, from which IP address, and can decide if that information is consistent enough and fresh enough to consider a session as current. At the top of every page, include a file/script that looks up the current session's user profile data from the DB, and use that to in turn control the pages that are rendered or the pages to which you're redirecting the visitor under different circumstances.<br /><br />For some pointers on how this works, just look at the source code from any of the hundreds of existing social network style CMS platforms out there, all of which have it handled very nicely. You'll see how all of this is managed using a database, rather than chains of passed page-to-page variables that may not be reliable.</p>
Link to comment
Share on other sites

<p>You could do that, or you could run a virtual machine (using VMware, etc - there are plenty of free options, including MS's Virtual PC) so that you can actually run what you're developing on what appears to be the actual operating system you'll eventually be using it on for real.</p>
Link to comment
Share on other sites

<p>Run the LAMP stack in a virtual machine. That machine will have its own internal, non-routable IP address. From your normal desktop web browser, you just surf to that internal IP address, and the services running on the LAMP machine will respond just they would if they were on a server running somewhere across the internet a thousand miles away.</p>
Link to comment
Share on other sites

<p>When someone signs in, you write a record to the database. That record can contain a field with the user ID, and a field with a date/time value that is updated each time they hit a page. If you don't mind the database growing fairly large, create a new record on every page view. That way you only have to query that table for the most recent record that has that user ID as a foreign key. Once you fetch that record, just look at the current date/time on the sytem and compare it to the date/time on the record ... and whatever passage of time you consider to be "fresh enough" just has to be greater than the difference.<br /><br />Again: this has been solved, and built, ten thousand times. There are some very elegant, open-source packages that have all of that logic (and pre-built database tables) right there for you to look at and either use or learn from. Drupal, for example. Re-inventing this sort of mechanism is indeed like teaching yourself how to be a locksmith before you allow yourself to build the house that is your actual project (when you could just get yourself a pre-made door knob with keys that already work).</p>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...