Jump to content

PHP/MySQL questions EDIT: Fixed, thanks.


adthegreat-

Recommended Posts

Hey guys,

 

I'm designing a website based on php and mysql, and part of this website, is the restriction of certain pages with a time limit. I first thought about setting this time limit with cookies, then i thought people would just delete their cookies.

 

 

 

That led me to sessions, but after thinking about that, you could just close the browser and reopen it to get around the time limits.

 

 

 

So lastly, a failsafe (i hope) method i am going to implement is a table in my MySQL db, that contains a field for last time you viewed that page. Then take todays date and time and compare it to see if the required amount of seconds has passed.

 

 

 

However i am unsure of how to do this, the only way i thought of doing that would be by something like taking the last time the page was viewed, away from the time now. But this would leave an undesired and very inversatile figure that i can't do much with.

 

 

 

I would imagine there is a very simple solution, but, I'm having trouble finding it at the moment, so any help is welcome!

 

 

 

Thanks in advance.

 

 

 

--------------------------------------------------------------------------------

 

 

 

EDIT: Now that that was sorted out, i've run into some more difficulties with sending emails using PHP...

 

 

 

The code i am using is...

 

 

 

  $to = $email;

      $subject = "Welcome to  ...";

      $body = "Hello, and thank you for registering for my game, ...
, just go                back to the                          website to login and start playing!
I look forward to seeing you.
Regards, The ..                           team

      $headers = "From: [email protected]\n";

        mail($to,$subject,$body,$headers);

        header("Location: member.php");

 

 

 

It doesnt show any error messages, but it doesnt send any emails out. I have tried sending it to two emails, a hotmail and googlemail, and i have looked in the spam section of both accounts, with no luck.

 

 

 

What the script is supposed to do, is once the user's have registered, basically thank them.

 

 

 

And i have made this work before, and I'm sure it was with the same code, but obviously there is some negligence that is causing it to malfunction.

 

 

 

Lastly, to try and solve the problem, i made member.php echo $_SESSION['email'] which was defined as $email and it shows the correct email it should be sending to. I'm guessing this means that there is an error in the mail() funtion i am using.

manipofsarahs1gg5.png
Link to comment
Share on other sites

You'd probably want a table in your MySQL database with a schema somewhat like this:

 

 

 

visited(ip_address, page_id, visit_time);

 

(with (ip_address, page_id) being the primary key, and page_id being something you set on the page itself - could be a name, but if you have lots of index.php things, or one php file which can turn into various kinds of pages depending on GET/POST vars, you might want something else, eg. a unique numeric id for each page)

 

 

 

Then you run a select query on the database, somewhat like this:

 

 

 

SELECT visit_time FROM visited WHERE ip_address = 'some.numeric.ip-address' AND page_id = 'myPageId';

 

(you might want to limit it to one result for sanity)

 

 

 

Anyway, you use the date value you get, which should be represented as a unix timestamp (that is, you store numeric values in the visit_time field - a UNIX timestamp is the number of seconds that have passed since January 1st, 1970. The unix timestamp at the time of writing is 1143401453). So then you get the current UNIX timestamp, using php's time() function (no arguments, returns the current UNIX timestamp).

 

You substract those and check for the difference you want. If it is not sufficient, you die() with an error message, if it is, you store the new timestamp with an UPDATE query or similar, and get on with generating the page data.

Link to comment
Share on other sites

Thanks for the reply, but it's still not working.

 

 

 


  //send email to new member            #153

      $to = $email;

      $subject = "Welcome to ...";

      $body = "Hello, and thank you for registering for my game, 


just go  back to the website to login and start playing!
I look forward to seeing you.
Regards, The ... Team." ;

      $headers = "From: [email protected]\n";

        mail($to,$subject,$body,$headers) ;

  header("Location: home.php") ; 

 

 

 

Thats the current code, and its still not working.

manipofsarahs1gg5.png
Link to comment
Share on other sites

Is the code online, or on your private server? I'd tend to think you're right, but to figure that out you'll have to look at logs, check if sendmail is configured correctly and such... :)

Link to comment
Share on other sites

Code is online, and unfortunately, its a webhosting companies server, so i wouldn't think i would be able to check stuff like that. Or am i wrong, how would you check if checkmail is configured correctly?

 

 

 

And as i mentioned before, i have made this work before, the only difference is that i am now on a windows server, as opposed to a linux one. Could that make a difference?

manipofsarahs1gg5.png
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...

Important Information

By using this site, you agree to our Terms of Use.