Downpour Posted September 8, 2008 Share Posted September 8, 2008 I am trying to make a download page only accessible after the person fills out a form. I was told that the best way to do this was with sessions variables, but I have no ideal how to go about it. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/ Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 Have you reviewed session tutorials? Also, you can also do it by checking if the form was submitted as well and you won't need a session. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636789 Share on other sites More sharing options...
james g Posted September 8, 2008 Share Posted September 8, 2008 Something like this would go before the form: session_start(); $_Session['formread'] = 0; Then, after the from has been submitted, change the session variable, like: $_Session['formread'] = 1; Then, you can have an if statement to do display the download page IF the user has submitted the form. if ($_Session['formread'] = 1) { //display download page Or redirect header to download page } Does this help? Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636792 Share on other sites More sharing options...
Downpour Posted September 8, 2008 Author Share Posted September 8, 2008 Thank you!! Will the people still be able to connect to my download page directly? I want them to go through the form first before they can get to the download page. Some people may just copy the url and skip the form all together!! Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636797 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 Not if you check either submit or the session first. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636798 Share on other sites More sharing options...
Downpour Posted September 8, 2008 Author Share Posted September 8, 2008 I'm sorry I'm a real newbie at this. I've never worked with sessions before!! How do I check if submit was entered? Right now I have formail, so when they click submit and enter the information it brings them to my download page. But if I place the page directly in the url, I can go straight to the page. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636816 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 Post your code for your form. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636820 Share on other sites More sharing options...
Downpour Posted September 8, 2008 Author Share Posted September 8, 2008 <form method="post" action="phorme.php" name="SampleForm"> <input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER"> <input type="hidden" name="recipients" value="myemail" /> <input type="hidden" name="required" value="email:Your email address,realname:Your name" /> <input type="hidden" name="subject" value="Subcription" /> <input type="hidden" name="good_url" value="http://mywebsite/download.html" /> <input name="realname" type="text" size="12" ></p> <input name="email" type="text" size="12"></p> <input name="Submit" type="image" src="index_files/Squeeze2_27.jpg" border="0" alt="" width="148" height="40" value="Submit"/></td> </form> Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636824 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 On your download page, you can add this to the top. Change the yourform.php to your actual form page or where you want them to go if they try to go directly to it. <?php if(!isset($_POST['Submit'])) { Header ("Location: yourform.php"); exit; } ?> Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636831 Share on other sites More sharing options...
Downpour Posted September 8, 2008 Author Share Posted September 8, 2008 Ok, I placed it above < html > at the top of my download page. But I can still access the page!! I cleared my cookies and cleaned the cache, just to make sure. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636837 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 Did you close the browser? Post the code how you have it now. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636842 Share on other sites More sharing options...
Downpour Posted September 8, 2008 Author Share Posted September 8, 2008 No I didn't close my browser! Should I have? this is how I have it: <?php if(!isset($_POST['Submit'])) { Header ("Location: index.php"); exit; } ?> <html> <head> <title>Inside the Minds of Winners -- Successful People Really Are Luckier!</title> <meta name="MSSmartTagsPreventParsing" content="TRUE"> </head> Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636847 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 And that is phorme.php right? Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636854 Share on other sites More sharing options...
Downpour Posted September 8, 2008 Author Share Posted September 8, 2008 No that is on my download page. download.html Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636907 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 A html page can't parse PHP (well not without telling your webserver to). Your form points to phorme.php after it's processed. So what does that page do? Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-636991 Share on other sites More sharing options...
Downpour Posted September 8, 2008 Author Share Posted September 8, 2008 A html page can't parse PHP (well not without telling your webserver to). Your form points to phorme.php after it's processed. So what does that page do? The phorme.php is the formail.php It sends the info of the form to me in an e-mail! I also tried putting phorme.php in the location but it didn't work either!! Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637045 Share on other sites More sharing options...
revraz Posted September 8, 2008 Share Posted September 8, 2008 So how do you get to the download page? Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637058 Share on other sites More sharing options...
Downpour Posted September 9, 2008 Author Share Posted September 9, 2008 When you hit submit the page goes here, it's in my form code <input type="hidden" name="good_url" value="mywebsite/download.html" /> Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637120 Share on other sites More sharing options...
revraz Posted September 9, 2008 Share Posted September 9, 2008 When you hit Submit, it goes to your action page <form method="post" action="phorme.php" name="SampleForm"> Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637433 Share on other sites More sharing options...
Downpour Posted September 9, 2008 Author Share Posted September 9, 2008 Yes, but then it gets redirected to my download page. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637449 Share on other sites More sharing options...
revraz Posted September 9, 2008 Share Posted September 9, 2008 You'll need to set a session then on your form page, change your download page to a .php page instead of .html, add the session check on that page. What is the purpose of phorme.php if all it does is redirect away? Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637452 Share on other sites More sharing options...
Downpour Posted September 9, 2008 Author Share Posted September 9, 2008 No it sends me an e-mail with the data on my form. Then re-directs the visitor to the download page after they submit it. So if I change my download page to .php and then how do I go putting a session in it. That's what I don't understand!! Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637466 Share on other sites More sharing options...
revraz Posted September 9, 2008 Share Posted September 9, 2008 Post the phorme.php code. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637469 Share on other sites More sharing options...
Downpour Posted September 9, 2008 Author Share Posted September 9, 2008 I'll attach it, because it is very long. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637482 Share on other sites More sharing options...
revraz Posted September 9, 2008 Share Posted September 9, 2008 Rename download.html to download.php Change <input type="hidden" name="good_url" value="mywebsite/download.html" /> to <input type="hidden" name="good_url" value="mywebsite/download.php" /> Add the code from page 1 to your download.php page (if you didn't already). If that doesn't work, you'll have to incorporate sessions. Link to comment https://forums.phpfreaks.com/topic/123303-session-variable-help-please/#findComment-637527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.