Hi Everyone, I'm a little confused by sessions. This is my goal. In the below URL If someone clicks on "contact us" and they aren't logged in I want that user to be re-directed to a login page. I know I can do this with php sessions but I'm a confused as to how. Does the session have to be on the car-display-contact2.php or the car-display-contact-update.php? or both pages? How would you attack this problem? http://whatsmyowncarworth.com/auto-members/car-display/car-display-contact2.php Thanks everyone!
I am a PHP newbie myself, and hoping someone will give you a better response. I would like to inform you first: PHP sessions do not exist on files independently, the are stored in the server so, you can no chose of which files will have sessions because, all of your PHP files will have sessions once you start session. Anyway, if you want to make sure people are redirected to log-in page when they click ' Contact Us ' Then you should create a function called sessions: something like this: function session_holder(){ if(isset($_SESSION['user_logedin']) $$ !empty($_SESSION['user_loggedin'])){ return true; }else{ return false; } } Code (markup): Now on the ' Contact Us ' page, you can check if user is logged in or nor and redirect them while they press the submit button for the contact if(isset($_POST['SUBMIT']) && empty($_SESSION['user_logedin'])){ header('Location:login_page.php') } else { // Put what you want php to do after 'Contcs Us' is pressed; } Code (markup): Like I said, I am very new to PHP and haven't tested this script, but you can get the logic behind your solution.. i hope. Good luck
Oh, I see Well, test it did it work for you? If not, let me know I will try to create the script, test it and then post it here.
Hey Everyone, I made a little progress today. I added the below syntax and a login URL link is presented. Now I'm trying to figure out after a user logs in how would I get that user back to the car-display-contact-update.php? page? What variables would I need to carry from page to page? How would I get the visitor back to the below page after they login? http://whatsmyowncarworth.com/auto-...=57&make=Toyota&model=Camry&submit=Contact+Us This is the syntax I added on my car-display-contact-update.php page if (!isset($_SESSION['id'])) { echo 'Please <a href="http://whatsmyowncarworth.com/auto-members/login.php">log in</a> to access your account'; } PHP:
The only thing you need for transferring people from any page to any page is by using the header function. Which is: header('Location:[COLOR=#0000FF][FONT=monospace]http://whatsmyowncarworth.com/[/FONT][/COLOR][COLOR=#111111]car-display-contact-update.php[/COLOR] ') Code (markup): This is after your client has logged in: I assume, you have already created the login script