Announcement

Collapse
No announcement yet.

index.php as "hub" if you will

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

  • index.php as "hub" if you will

    ok i am still kinda new to php im learning alot but i have always wondered how to make a page do this;

    if i wanted to goto for example test.php than my link would be

    index.php?page=test

    if anyone could help me please do .

  • #2
    PHP Code:
    <?php
    if (!isset($page)) {
    ?>

    Your index content here incase they didn't include a page var.
    <?php
    }
    if (
    $page == "1") {
    include(
    "page1.php");
    }
    if (
    $page == "2") {
    ?>

    Content for page two if you don't have a seperate doc for it.

    <?php
    }
    ?>

    Thats one of about three differnt ways to do it....


    [edit]
    WooHoo, 300th post...
    [/edit]
    Last edited by The Prohacker; Sat 22 Sep '01, 11:31am.

    Comment


    • #3
      But if you want to actually GO to that page, then you should use a header directive, such as:
      PHP Code:
      header ("Location: test.php"); 
      so it'll look like this:
      PHP Code:
      if ($page=="1") {
        
      header ("Location: page1.php");

      Chen Avinadav
      Better to remain silent and be thought a fool than to speak out and remove all doubt.

      גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

      Comment


      • #4
        thanks! firefly it does what i want it to do.. but how can i cloak the url to look like.. index.php?page=1 when it goes to test.php.. ?

        Comment


        • #5
          assuming you are using 1 page for your script you could
          use the switch function

          PHP Code:
          <?
          switch ($page)
          {
          case 
          1:
          print 
          "page1";
          break;
          case 
          2:
          print 
          "page2";
          break;
          default:
          print 
          "<a href=\"$PHP_SELF?page=1\">Page 1</a> | <a href=\"$PHP_SELF?page=2\">Page 2</a> ";
          break;
          }
          ?>
          Just a thought.

          Comment


          • #6
            In that case Goldfinger (just saw that movie yesterday, by the way ), use what The Prohacker suggested.
            Chen Avinadav
            Better to remain silent and be thought a fool than to speak out and remove all doubt.

            גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

            Comment


            • #7
              hehe goldfinger is one of my favorite movies . anyway.. i would i get it to recognize my index.php as the index when it loads... since it just includes the files.

              Comment


              • #8
                PHP Code:
                <?

                include($page ".php");

                ?>
                Simple or not?

                Comment


                • #9
                  Yeah, but will create a nasty error when someone enters a bad name.
                  Chen Avinadav
                  Better to remain silent and be thought a fool than to speak out and remove all doubt.

                  גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

                  Comment


                  • #10
                    I always get nasty errors in my code

                    Comment


                    • #11
                      Menators way was the correct way .

                      Comment

                      widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                      Working...
                      X