Web Analytics Made Easy -
StatCounter send variables to another page - CodingForum

Announcement

Collapse
No announcement yet.

send variables to another page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • send variables to another page

    Hi,

    I'm stuck on sending variables to another page and then printing them can someone have a look at the code for me please.

    This is on page 1:
    the form goes like this

    <input name="user" type="text" id="user" value=<?php $user?>>

    This then runs a script that checks if the user is registered and then he/she is verified.

    $user=$_POST['user'];

    I want to post the to the 2nd page via

    header("location:secondpage.php") and also the other pages in the members area. The user name should be printed out and posted.

    I have tried header("location:secondpage.php?".$Post['user']:"");

    Tried echo to print the user in the second page but doesn't seem to work any ideas.

    thanks in advance

  • #2
    Code:
    <input name="user" type="text" id="user" value=<?php $user?>>
    should be
    PHP Code:
    <input name="user" type="text" id="user" value=<?php echo  $user ;?>>
    .

    However, you'd need to use sessions to effectively pass such informations. See http://php.net/session_start
    Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

    Comment


    • #3
      Thanks for the reply

      I have a session created but I thought that if I wanted send variables I would send them through the header.

      session_start();
      $_SESSION["logged"]=1;

      I'm sorry I'm a newbie I still don't see how to send the user name

      I have tried but no joy any idea what i'm doing wrong.

      if(!isset($_SESSION['user']));

      thanks in advance

      Comment


      • #4
        Have you tried the example given in the above manual page?
        Digitalocean Cloud Hosting (Referral link - get $10 free credit) Fameco

        Comment


        • #5
          Yes I've tried the above manual but I think the way I am verifiying the user might be the problem. As I'm starting the session and the creating a session id I don't name it anything just give it a value of 1.

          What do you think?

          <?php
          if($count==1){
          //Register $user, $password and redirect to file "login_success.php"
          session_register("user");
          session_register("password");
          session_start();
          $_SESSION["logged"]=1;

          header("location:login_success.php");
          }
          else {
          $_SESSION["logged"]=0;
          //echo "Wrong User ID or Password";
          }

          thanks in advance

          Comment


          • #6
            Originally posted by tau9 View Post
            Yes I've tried the above manual but I think the way I am verifiying the user might be the problem. As I'm starting the session and the creating a session id I don't name it anything just give it a value of 1.

            What do you think?

            <?php
            if($count==1){
            //Register $user, $password and redirect to file "login_success.php"
            session_register("user");
            session_register("password");
            session_start();
            $_SESSION["logged"]=1;

            header("location:login_success.php");
            }
            else {
            $_SESSION["logged"]=0;
            //echo "Wrong User ID or Password";
            }

            thanks in advance
            As quoted on php.net

            Caution

            If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered(), and session_unregister().
            You don't need those session_register functions. you should remove them and then set the session vars after session_start like so

            PHP Code:
            session_start();
            $_SESSION["logged"]=1;
            $_SESSION["username"] = $user;
            $_SESSION["password"] = $password
            Just out of curiosity is it necessary to store the user password?
            You can not say you know how to do something, until you can teach it to someone else.

            Comment


            • #7
              no I dont need to store the password so I am going to leave it out
              thanks


              I have used the code below and found that the session remains open and the number is incremented but how can the user name be posted on the page.

              I am trying to get something like this: User: Dave viewed:20 times

              I have tried the manual above but no luck any ideas.

              <?php
              if(isset($_SESSION['user'])) $_SESSION['user']=$_SESSION['user']+1;
              else $_SESSION['user']=1;echo "=". $_SESSION['user'];

              ?>


              Sorry thats wrong I need to post the username to the nextpage the counter allows me to keep track of the viewed pages.
              thanks in advance.
              Last edited by tau9; Apr 15, 2009, 06:25 AM. Reason: error

              Comment


              • #8
                I guess you will need two session variables. However if i was keeping count of how many views a person has done I would store it more permanently. Probably with a MySQL database or something. Anyway. Here is the code for the sessions.

                PHP Code:
                <?php
                session_start
                ();
                if(isset(
                $_SESSION['user'])) $_SESSION['counter']++;
                else 
                {
                $_SESSION['counter']=1;
                $_SESSION['user']=$user;
                }
                echo 
                "="$_SESSION['user'] . "viwed: " $_SESSION['counter'] . " times";
                ?>
                You can not say you know how to do something, until you can teach it to someone else.

                Comment

                Working...
                X