Jump to content

post variable


fortnox007

Recommended Posts

Hi guys, I pretty new to php, and was writing a small script after a I read a chapter (4) about if-statements of a book. But it seems I am doing something wrong. Maybe someone could help me in the right direction.

 

In a nutshell: I have a small form, and when someone presses submit it should go to another page and include the variables of the previous page. So far I am only been able to include html form variables which I recover on the next page with $_POST['xxxx'];

 

here under ill Put a part of my script which is not of any use, but its more for me to understand how to get php variables on the next page. I am using a self referencing script and i have some comments added to read along.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>bla bla bla</title>
    </head>
    <body>
        <?php  
        //code to be executed when monkey button pressed
        if (isset($_POST['monkey'])){        
                echo $_POST[$number1];
                echo 'monkey pressed';
        }
        //code to be executed when snakes button pressed
        if (isset($_POST['snakes'])){        
                echo $_POST[$number1];
                echo 'snakes pressed';
        }
        ?>
        <h1>bla bla bla</h1>
        <h3>
            <?php
            $number1 = $number1.mt_rand(1,100000);
            echo $number1;
            ?>
        </h3>
        <form action="<?php echo $_PHP['PHP_SELF']; ?>" method="post">
            <input type="submit" value="monkey" name="monkey" />
            <input type="submit" value="snakes" name="snakes" />
        </form>

    </body>
</html>


Link to comment
Share on other sites

So in a nut-nutshell. How to retrieve php variables on the next page.

I am pretty sure i can use hidden fields for it, but if there is another way, I would love to hear it, because I am also pretty sure that people can edit hidden fields ;) 

Link to comment
Share on other sites

Wow thanks a lot for your swift response.

Would you mind explain a little why not to use <?php echo $_PHP['PHP_SELF']; ?>

I am just starting with php and in the book I bought they say i should use it to let the page self reference.

Is there maybe a security risk when i use it?

If you happen to have time for it i would be extremely pleased. Ill search for session variables

(just 3 chapters away ;-)

 

Thanks man!

 

John

Link to comment
Share on other sites

Holy crap, I just googled my ass of for don't use  <?php $_SERVER['PHP_SELF']; ?>

and i found loads and loads of blogs about it.

Thanks Alot for pointing me to this. I really apreciate it The only thing i realy hate is that the book i have doesn't say 1 word about it and above all a so called security dude  was one of the authors.  :wtf:

Well if someone knows a good book to write proper and secure php I am all ears! (eyes in this case  ;D )

 

And again thanks m8 for the quick help

 

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.