adv Posted April 17, 2008 Share Posted April 17, 2008 hello let me explain the problem : i have 2 pages : info.php anotherinfo.php some users may see the second page ( anotherinfo.php) and type it directly in the url so i`ve used session to forbid that.. i have info.php <?php session_start(); $comment = $_POST['comm']; if (isset($_POST['submit'])) { if ( !empty($comment) ) { $_SESSION['ok'] = 1 ; } } ?> i`ve set the value to 1 and in the anotherinfo.php has to push submit button too <?php session_start(); if ($_SESSION['ok'] != 1 ) {header("location:info.php"); } if (isset($_POST['submit1'])) { echo "good"; } ?> in the second page the form looks like this: <form method="post" action="anotherinfo.php?" name="test"> the problem is when i press the submit button at the anotherinfo.php it takes me back to the first page ... it doesnt show me the echo "good"; i dont wanna to act 2 times .. i just want to act only if the user tries to write directly the page .. hope u understand Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/ Share on other sites More sharing options...
psychowolvesbane Posted April 17, 2008 Share Posted April 17, 2008 It might help to see the forms you are using for each, or at least the submit button sections and <form> sections to see if you are overlooking something. Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-519990 Share on other sites More sharing options...
adv Posted April 17, 2008 Author Share Posted April 17, 2008 for first page i`m using : <form action="info.php?tst" method="post" enctype="application/x-www-form-urlencoded" name="form1" > and the second : <form method="post" action="anotherinfo.php?" name="test"> if i enter corectly and follow the 2 pages it works until when i press the last submit : if (isset($_POST['submit1'])) { echo "good"; } for first page <input name="submit" class="pulsant" value="continue" alt="nnn" type="submit"> for second page <input name="submit1" class="pulsant" type="submit" value="finish" /> Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-519995 Share on other sites More sharing options...
psychowolvesbane Posted April 17, 2008 Share Posted April 17, 2008 Okay for you're actions on both forms why do you have ?php referencing when they are not needed or used, especially the one on anotherinfo.php you have a loose ? at the end, and the ?tsk on the first. Okay that won't be the problem, just nitpicking. Anyway you could try disabling the link on the info.php temporarily and see if you can echo out the value of the $_session['ok'] once it has been set, or not set. So, echo"This is the session okay".$_SESSION['ok']; Then if that checks out okay try adding another = on the first if statement on the 2nd page, may help may not. if($_SESSION['ok'] !== 1 ) Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-520007 Share on other sites More sharing options...
adv Posted April 18, 2008 Author Share Posted April 18, 2008 ok .. the ?php is just for apearance .. i`ve tried how u said with another "= " and it does the same let me explain another time if i try to write directly in the url the name anotheinfo.php it does work and if i try to go corectly like visiting the first page and pressing submit it takes me to the second page but there is the thing ... when i click submit there it takes me to the first page instead of showing echo "good"; i `ve tried : if ($_SESSION['ok'] != 1 ) {header("location:info.php"); unset($_SESSION['ok']); } if ($_SESSION['ok'] !== 1 ) {header("location:info.php"); } but is still active :| no idea Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-520020 Share on other sites More sharing options...
adv Posted April 18, 2008 Author Share Posted April 18, 2008 pff someone Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-520149 Share on other sites More sharing options...
zenag Posted April 18, 2008 Share Posted April 18, 2008 u have shown only small bit of code its not not enough to solve ur problem... Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-520156 Share on other sites More sharing options...
psychowolvesbane Posted April 18, 2008 Share Posted April 18, 2008 For now disable the link back to info.php on the anotherinfo.php (and remove the ? and ?tsk as they are not needed if only for show as you said) and try and concentrate on getting the form to work and displaying the "good" message. Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-520158 Share on other sites More sharing options...
zenag Posted April 18, 2008 Share Posted April 18, 2008 IT SEEMS ONLY FAULT IS IN ..header("location:info.php"); IN anotherinfo.php comment that & run ... Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-520163 Share on other sites More sharing options...
adv Posted April 18, 2008 Author Share Posted April 18, 2008 uh i finally got it after hours of thinking and trying ... if (!isset($_POST['submit'])) { if ($_SESSION['logged'] != 1) { header("location:info.php"); } } if works fine like this .. if i try directly to type the second page in the url it redirects me good and i go corectly and follow the pages in the exact order ... this is the trick ... Link to comment https://forums.phpfreaks.com/topic/101625-solved-session-help/#findComment-520767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.