0

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.

Hermes
  • 452
  • 10
  • 24
  • `$_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
  • 1
    I feel that there is more to this question than meets the eye. – Funk Forty Niner Jun 07 '16 at 21:04

3 Answers3

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" ];
?>
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