My question may be very simple question. I am new in php. I searched but I couldn't find the best answer. My main page is index.php. When the page is loaded I want to run the main page with parameters. For example index.php?simple=1.
            Asked
            
        
        
            Active
            
        
            Viewed 97 times
        
    0
            
            
        - 
                    `$_REQUEST`is your friend. But since you are learning PHP from scratch, do yourself a favour and [learn about routing](https://www.google.de/search?q=php+routing&oq=php+routing), instead of messing with files. – moonwave99 Jun 07 '16 at 20:38
- 
                    "$_REQUEST or not $_REQUEST, that is the question" - Shakespeare- – Jose Manuel Abarca Rodríguez Jun 07 '16 at 20:59
- 
                    1@JoseManuelAbarcaRodríguez, had you added the link: [What's wrong with using $_REQUEST?](http://stackoverflow.com/questions/2142497/whats-wrong-with-using-request) then your comment would be fun and very appropriate :) – Ryan Vincent Jun 07 '16 at 21:02
- 
                    1I feel that there is more to this question than meets the eye. – Funk Forty Niner Jun 07 '16 at 21:04
3 Answers
1
            You need two files :
index.php
<?php
header( "Location: main_page.php?simple=111" );
?>
main_page.php
<?php
echo $_GET[ "simple" ];
?>
index.php will call main_page.php with the parameter you want.
@Fred-ii- is right, this is the fix for main_page.php :
main_page.php
<?php
if ( isset( $_GET[ "simple" ] ) )
   echo $_GET[ "simple" ];
?>
 
    
    
        Jose Manuel Abarca Rodríguez
        
- 10,206
- 3
- 31
- 38
- 
                    1accessing main_page.php directly will throw an error, should someone fool around with the parameters. – Funk Forty Niner Jun 07 '16 at 21:05
- 
                    @Fred-ii-, fixed! (thanks). More should be handled about parameters, but that's for another question. – Jose Manuel Abarca Rodríguez Jun 07 '16 at 21:09
0
            
            
        Use the $_GET superglobal.
if ($_GET['simple'] == '1')
{
  // your code here
}
 
    
    
        RamenChef
        
- 5,557
- 11
- 31
- 43
- 
                    Thanks for answer. I want to run index.php?simple=1 directly. For example I am working on localhost. When I run my project. it is working localhost/index.php. I can't send any parameter. I want to run localhost/index.php?simple=1. İs it possible or what should I do? – Hermes Jun 07 '16 at 20:48
- 
                    I don't understand why it wouldn't let you do that, encoding it into the URL should work. – RamenChef Jun 07 '16 at 20:53
0
            
            
        you must check if the variable is set first, then get the value (do you can display the page without parameters.. like that:
    if(isset($_GET['simple'])){
        $simple=$_GET['simple'];
        //now simple is the value of parameter 'simple';
        }
 
    
    
        Obadah Hammoud
        
- 572
- 2
- 13
