Jump to content

[SOLVED] session help


adv

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.