how to get request parameter from one php page to another page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • naja
    New Member
    • Sep 2006
    • 3

    how to get request parameter from one php page to another page

    hello everyone...
    myself Nawaz from Mangalore...

    I've created a web page using jsp.. now i want to convert it to php.... so please help me out... i want to know how to pass parameter to another page and get request from the previous page... u can give with example.... like i want to create a login page... now user will enter his/her id and password... i want to check whether its a valid one or not.. if its a valid one then it should go to another page.. else stay in current page... so please help me in solving this problem...

    Nawaz
  • skim
    New Member
    • Sep 2006
    • 9

    #2
    Using "SESSIONS"
    For example,
    test1.php
    <?php
    session_start() ;
    $_SESSION['logPass']="whatever";
    .
    .
    .
    Your Code
    .
    .
    .
    ?>
    test2.php
    <?php
    session_start() ;
    $pass = $_SESSION['logPass'];
    echo $pass;
    ?>
    Output
    whatever

    Please read session part.
    I hope this is what you want.

    Comment

    • naja
      New Member
      • Sep 2006
      • 3

      #3
      Hi skim,,
      I'll provide u the 2 pages i've created using jsp javascript for login page... check it out... and let me know how can i do it in php....check only the code which is bold..so it'll be easy for u...ok

      page 1......

      <html>
      <head>
      <title>MRPL management Staff Association</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <style type="text/css">
      <!--
      @import url("images/css.css");
      @import url("images/styles.css");
      body {
      background-color: #999999;
      }
      .style1 {color: #FFFFFF}
      .style2 {font-size: 9px}
      .style6 {font-size: 12px}
      .style7 { font-size: 14px;
      font-weight: bold;
      }
      -->
      </style>
      </head>
      <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0 ">
      <!-- ImageReady Slices (template2.psd) -->
      <table width="778" height="629" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
      <tr>
      <td width="265"><ob ject classid="clsid: D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macrom edia.com/pub/shockwave/cabs/flash/swflash.cab#ver sion=7,0,19,0" width="264" height="118">
      <param name="movie" value="images/logo1.swf">
      <param name="quality" value="high">
      <embed src="images/logo1.swf" quality="high" pluginspage="ht tp://www.macromedia. com/go/getflashplayer" type="applicati on/x-shockwave-flash" width="264" height="118"></embed>
      </object></td>
      <td>
      <img src="images/index1_02.gif" width="514" height="118" alt=""></td>
      </tr>
      <tr>
      <td height="57" colspan="2" background="ima ges/index_03.jpg">& nbsp;</td>
      </tr>
      <tr>
      <td height="153" colspan="2" valign="middle" style="border-bottom:bd2827 solid 1px;"><script type="text/javascript">


      //Specify the slider's width (in pixels)
      var sliderwidth="77 8px"
      //Specify the slider's height
      var sliderheight="1 53px"
      //Specify the slider's slide speed (larger is faster 1-10)
      var slidespeed=3
      //configure background color:
      slidebgcolor="# EAEAEA"

      //Specify the slider's images
      var leftrightslide= new Array()
      var finalslide=''
      leftrightslide[0]='<img src="images/image1.jpg" border=1>'
      leftrightslide[1]='<img src="images/image2.jpg" border=1>'
      leftrightslide[2]='<img src="images/image3.jpg" border=1>'
      leftrightslide[3]='<img src="images/image4.jpg" border=1>'
      leftrightslide[4]='<img src="images/image5.jpg" border=1>'

      //Specify gap between each image (use HTML):
      var imagegap=" "

      //Specify pixels gap between each slideshow rotation (use integer):
      var slideshowgap=5


      ////NO NEED TO EDIT BELOW THIS LINE////////////

      var copyspeed=slide speed
      leftrightslide= '<nobr>'+leftri ghtslide.join(i magegap)+'</nobr>'
      var iedom=document. all||document.g etElementById
      if (iedom)
      document.write( '<span id="temp" style="visibili ty:hidden;posit ion:absolute;to p:-100px;left:-9000px">'+leftr ightslide+'</span>')
      var actualwidth=''
      var cross_slide, ns_slide

      function fillup(){
      if (iedom){
      cross_slide=doc ument.getElemen tById? document.getEle mentById("test2 ") : document.all.te st2
      cross_slide2=do cument.getEleme ntById? document.getEle mentById("test3 ") : document.all.te st3
      cross_slide.inn erHTML=cross_sl ide2.innerHTML= leftrightslide
      actualwidth=doc ument.all? cross_slide.off setWidth : document.getEle mentById("temp" ).offsetWidth
      cross_slide2.st yle.left=actual width+slideshow gap+"px"
      }
      else if (document.layer s){
      ns_slide=docume nt.ns_slidemenu .document.ns_sl idemenu2
      ns_slide2=docum ent.ns_slidemen u.document.ns_s lidemenu3
      ns_slide.docume nt.write(leftri ghtslide)
      ns_slide.docume nt.close()
      actualwidth=ns_ slide.document. width
      ns_slide2.left= actualwidth+sli deshowgap
      ns_slide2.docum ent.write(leftr ightslide)
      ns_slide2.docum ent.close()
      }
      lefttime=setInt erval("slidelef t()",30)
      }
      window.onload=f illup

      function slideleft(){
      if (iedom){
      if (parseInt(cross _slide.style.le ft)>(actualwidt h*(-1)+8))
      cross_slide.sty le.left=parseIn t(cross_slide.s tyle.left)-copyspeed+"px"
      else
      cross_slide.sty le.left=parseIn t(cross_slide2. style.left)+act ualwidth+slides howgap+"px"

      if (parseInt(cross _slide2.style.l eft)>(actualwid th*(-1)+8))
      cross_slide2.st yle.left=parseI nt(cross_slide2 .style.left)-copyspeed+"px"
      else
      cross_slide2.st yle.left=parseI nt(cross_slide. style.left)+act ualwidth+slides howgap+"px"

      }
      else if (document.layer s){
      if (ns_slide.left> (actualwidth*(-1)+8))
      ns_slide.left-=copyspeed
      else
      ns_slide.left=n s_slide2.left+a ctualwidth+slid eshowgap

      if (ns_slide2.left >(actualwidth *(-1)+8))
      ns_slide2.left-=copyspeed
      else
      ns_slide2.left= ns_slide.left+a ctualwidth+slid eshowgap
      }
      }


      if (iedom||documen t.layers){
      with (document){
      document.write( '<table border="0" cellspacing="0" cellpadding="0" ><td>')
      if (iedom){
      write('<div style="position :relative;width :'+sliderwidth+ ';height:'+slid erheight+';over flow:hidden">')
      write('<div style="position :absolute;width :'+sliderwidth+ ';height:'+slid erheight+';back ground-color:'+slidebg color+'" onMouseover="co pyspeed=0" onMouseout="cop yspeed=slidespe ed">')
      write('<div id="test2" style="position :absolute;left: 0px;top:0px"></div>')
      write('<div id="test3" style="position :absolute;left:-1000px;top:0px" ></div>')
      write('</div></div>')
      }
      else if (document.layer s){
      write('<ilayer width='+sliderw idth+' height='+slider height+' name="ns_slidem enu" bgColor='+slide bgcolor+'>')
      write('<layer name="ns_slidem enu2" left=0 top=0 onMouseover="co pyspeed=0" onMouseout="cop yspeed=slidespe ed"></layer>')
      write('<layer name="ns_slidem enu3" left=0 top=0 onMouseover="co pyspeed=0" onMouseout="cop yspeed=slidespe ed"></layer>')
      write('</ilayer>')
      }
      document.write( '</td></table>')
      }
      }
      </script></td>
      </tr>
      <tr>
      <td height="277" align="center" valign="top" bgcolor="0c5386 " class="date"><t able width="90%" border="0">
      <tr>
      <td align="center" valign="middle" class="text"><p align="center" class="title style1">Members Login</p>
      <form name="form3" method="post" action="http://localhost:8080/mrpl/login.jsp" onSubmit = "return validate(this.f orm)">
      <p class="style1">
      <label>Login_Id &nbsp;
      <input type="text" name="login_id" tabindex="1">
      </label>
      </p>
      <p class="style1">
      <label>Passwo rd
      <input type="password" name="password" tabindex="2">
      </label>
      </p>
      <p>
      <span class="style1">
      <LABEL></LABEL>
      </span> <span class="style1">
      <center>
      <input type="submit" value="Submit" tabindex="3" name="Submit">
      </center>
      &nbsp;&nbsp; </span></p>
      </FORM>
      </td>
      </tr>
      </table>
      <p><span class="style7"> MRPL <br>
      Management </span><span class="style7"> Staff Association</span><br>
      (Registration No. TUA 484: 2005)</p>
      <p class="style6"> Room No.4, <br>
      1st Floor, MRPL Employees Club, <br>
      Kuthethoor
      P.O., Mangalore 575 030.<br>
      Karnataka India</p>
      <p class="style6"> Contact Nos.: <br>
      0824 2236649 (Dir) <br>
      2270400 Extn 4649 </p></td>
      <td width="517" height="277" align="center" valign="top" bgcolor="006cb0 " class="text style1"><TABLE width="90%" align="center">
      <TBODY>
      <TR>
      <TD align="center" valign="middle" class="text style1"><p align="left" class="title style1">About Us</p>
      <p align="center"> <em>Real strength never impairs beauty or harmony, but it often bestows it; and in everything imposingly beautiful, strength has much to do with the magic.</em></p>
      <p align="right">< em>- Herman Melville</em></p>
      <p align="justify" > MRPL management staff association is a body comprising of management staff of Mangalore Refinery and Petrochemicals Ltd. At present there are more than 270 management staff personnel who are members of this August body. It is mutual trust, even more than mutual interest that binds the members of our association<br>
      The main objectives of the association are</p>
      <ul>
      <li>
      <div align="justify" > To have direct and effective channel of communication with the Management and there by improve the efficiency, profitability and development of the Company.</div>
      </li>
      <li>
      <div align="justify" >
      To discuss, debate and ensure improvement of welfare and service conditions of the members of the Association.</div>
      </li>
      <li>
      <div align="justify" >
      To foster unity, goodwill, understanding and harmony among the<br>
      members and promote mutual help and appreciation.</div>
      </li>
      <li>
      <div align="justify" >
      To promote harmonious relation between management and non- management staff.</div>
      </li>
      <li>
      <div align="justify" >
      To seek affiliation with All India Organization/Association of the management staff in the Oil industry having similar objectives.</div>
      </li>
      </ul></TD>
      </TR>
      <TR>
      <TD align="center" valign="middle" class="text style1">&nbsp;</TD>
      </TR>
      </TBODY>
      </TABLE></td>
      </tr>
      <tr>
      <td height="24" colspan="2" background="ima ges/index_07.jpg" class="text style1"><div align="center" class="style2"> Copyright @ MRPL Management Staff Association, all rights reserved designed by : Jyothi Software Solutions </div></td>
      </tr>
      </table>
      </body>
      </html>

      Comment

      • naja
        New Member
        • Sep 2006
        • 3

        #4
        thi is the second page.....

        page 2......

        <%@ page import="java.sq l.*" %>
        <%

        String log_id = request.getPara meter("login_id ");
        String pwrd = request.getPara meter("password ");
        //out.println(log inname)
        String uname;
        String upwd;

        try
        {

        Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
        Connection con = DriverManager.g etConnection("j dbc:odbc:mrplka na","tiger","ma nager");
        Statement st = con.createState ment();
        ResultSet rs = st.executeQuery ("select * from logintbl");

        while(rs.next() )
        {
        uname=rs.getStr ing(1);
        upwd=rs.getStri ng(2);


        if(log_id.equal s(uname) && pwrd.equals(upw d))
        {
        response.sendRe direct("http://localhost:8080/mrpl/news.html");
        }
        else
        {%>
        <script language="javas cript">
        alert("WRONG USER NAME OR PASSWORD.");

        document.locati on.href="http://localhost:8080/mrpl/index.html";
        </script>
        <% }

        }


        }




        catch(Exception e)
        {
        out.println(e.g etMessage());
        }
        %>

        Comment

        • skim
          New Member
          • Sep 2006
          • 9

          #5
          I think you need to read a session document.
          W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.



          In PHP, you need containers to send parameters to next pages.
          So, you want to send "login_id" and "password" on 'POST' method to the next page, then do this.

          session_start() ; // Start Session. It's required.
          $_SESSION['login_id'] = $_POST['login_id']; //Put 'login_id' text from the form into the session container
          $_SESSION['password'] = $_POST['password']; //Put 'password' into the another container as the 'login_id'
          Done!!!

          The session will remember values in everywhere on your script.
          Now, how to open the session variables
          Any next pages.
          session_start() ; // Start Session. It's required.
          $login_id = $_SESSION['login_id']; // indicate what 'login_id' value is
          $password = $_SESSION['password']; // indicate what "password' value is
          Done!!!

          P.S: You do not need 2 pages to check the legal user. Try to use this way.
          session_start() ;
          if(isset($_POST['Submit']))
          {
          //check user here and if the user is legal
          if(user is legal)
          {
          //if you still want to send user id to next page
          $_SESSION['login_id'] = $_POST['login_id'];
          $_SESSION['password'] = $_POST['password'];
          // do whatever or go to next page
          }
          else
          {
          print "Sorry you are not legal user";
          }

          }

          I hope this helps you.

          Comment

          Working...