PHP Page

Discussion in 'PHP' started by Jekis, May 21, 2010.

  1. #1
    Hello people! Help me understand how to create pages with names: ww.site/?page_id=20 ,www.site/?page_id=18 , www.site/?page_id=16 , www.site/?p=1 and www.site/?cat=1. Thank!
     
    Jekis, May 21, 2010 IP
  2. Christian Little

    Christian Little Peon

    Messages:
    1,753
    Likes Received:
    80
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's just passing variables into a php script. The actual page is /index.php most likely.

    What they're doing is passing some important information onto that page so it can be used. You usually see this when you submit a form, but you also see it on forums and various other places.

    page_id is the variable name, and the number after the = sign tells you what value it's assigning to that variable.

    Then inside index.php the code has a line like this:

    
    $pageid = $_GET["page_id"];
    
    PHP:
    It then uses that to (most likely), pull the page content from some kind of database.
     
    Christian Little, May 21, 2010 IP
  3. Trikun3

    Trikun3 Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    When you use the superglobals GET/POST/COOKIE, always, always, always be sure to filter the input of any harmful data. This can be done by accepting only specific characters, using a regex match, php's filter_input, or type-casting.
     
    Trikun3, May 22, 2010 IP
  4. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I'm sorry but could you explain in more detail on what some example. The screenshot shows the example that I needed to do. Thank you very much.[​IMG]
     
    Jekis, May 22, 2010 IP
  5. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Thats a good effort!

    But you can able to create such pages with PHP with Switch Function +DB's
    And when user click the link with number its Switched using
    $pageid = $_GET["page_id"]; and the relative page is displayed using this :)
     
    roopajyothi, May 22, 2010 IP
  6. Trikun3

    Trikun3 Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    
    # Switch between the index.php?page=XXX with $_GET['page']
    switch($_GET['page'])
    {
    	# If the ?page=XXX is home
    	case 'home':
    		home_page();
    		break;
    	
    	# If the ?page=XXX is other
    	case 'other':
    		other_page();
    		break;
    	
    	# If the ?page=XXX is help
    	case 'help':
    		help_page();
    		break;
    	
    	# If the ?page=XXX is home
    	case default:
    		home_page();
    		break;
    }
    
    # Homepage function.
    function home_page()
    {
    	echo 'Welcome to the homepage.<br />';
    	
    	# Show the other pages.
    	echo '<a href="index.php?page=other">Other Page</a><br />';
    	echo '<a href="index.php?page=help">Help Page</a><br />';
    }
    
    # Otherpage function.
    function other_page()
    {
    	echo 'Welcome to the other page.<br />';
    	
    	# Show the other pages.
    	echo '<a href="index.php?page=home">Home Page</a><br />';
    	echo '<a href="index.php?page=help">Help Page</a><br />';
    }
    
    # Helppage function.
    function help_page()
    {
    	echo 'Welcome to the help page.<br />';
    	
    	# Show the other pages.
    	echo '<a href="index.php?page=home">Home Page</a><br />';
    	echo '<a href="index.php?page=other">Other Page</a><br />';
    }
    Code (markup):
    I hope this helps.
     
    Trikun3, May 22, 2010 IP
  7. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi....I can not put in the name of the page _ index.php? page_other, how do I do?
     
    Jekis, May 24, 2010 IP
  8. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Trikun3: As in your example how to make the page name instead of _ = index.php? Page_other ??? I would be very grateful for the help!
     
    Jekis, May 24, 2010 IP
  9. Trikun3

    Trikun3 Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    It works the same with any page. You just need to make sure you link it properly.

    So for the line:
    echo '<a href="index.php?page=help">Help Page</a><br />';
    Code (markup):
    It would change to:
    echo '<a href="pagename.php?page=help">Help Page</a><br />';
    Code (markup):
    You could also use $_SERVER['PHP_SELF'] or basename(__FILE__) so you don't have to change the pagename manually.
     
    Trikun3, May 24, 2010 IP
  10. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    I need that information was different on each page, if I'm stationed information in index.php it on other pages.
     
    Jekis, May 24, 2010 IP
  11. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    how to make the information on the pages changed?
     
    Jekis, May 24, 2010 IP
  12. Trikun3

    Trikun3 Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    You change the contents of the functions. You could make html pages for it to use, then replace the functions like so:

    <?php
    
    # Switch between the index.php?page=XXX with $_GET['page']
    switch($_GET['page'])
    {
    	# If the ?page=XXX is home
    	case 'home':
    		include 'home.html';
    		break;
    	
    	# If the ?page=XXX is other
    	case 'other':
    		include 'other_page.html';
    		break;
    	
    	# If the ?page=XXX is help
    	case 'help':
    		include 'help.html';
    		break;
    	
    	# If the ?page=XXX is home
    	case default:
    		include 'home.html';
    		break;
    }
    Code (markup):
     
    Trikun3, May 24, 2010 IP
  13. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13

    <?php include ("connect/connect.php");
    ?>
    <?php      
    $num = 1;  
    $result = mysql_query("SELECT COUNT(*) FROM bd");  
    $posts = mysql_result($result, 0, 0);
    $total = intval(($posts - 1) / $num) + 1;
    if(empty($page) or $page < 0) $page = 1;  
      if($page > $total) $page = $total;  
    $start = $page * $num - $num;  
    $result = mysql_query("SELECT * FROM bd LIMIT $start, $num");  
    while ( $postrow[] = mysql_fetch_array($result))  
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="" />
    </head>
    <?php
    
    switch($_GET["page_id"])
    {
    case"20":
    break;
    }
    
    
    ?>
    <?php
    
    switch($_GET["page_id"])
    {
    case"18":
    break;
    }
    
    
    ?>
    
    
    <body><table width="900" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table>
    <table width="900" height="136" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td background="head.jpg">    <p><br />
        </p></td>
      </tr>
    </table>
    <table width="900" border="1" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td><a href="index.php?page_id=20 ">PAGE1</a> |  <a href="index.php?page_id=18 ">PAGE2</a></td>
      </tr>
    </table>
    
     <table width='900' border='1' align='center' cellpadding='5' cellspacing='0' bgcolor='#FFFFFF'>
    
                       <tr>
    		 <td align='left' valign='top' class='cont'> <?php  
    for($i = 0; $i < $num; $i++) 
    echo "".$postrow[$i]['info']."";
    ?><br/></p>
    
                        </td>
                  </table>
    <table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
    Code (markup):
     
    Last edited: May 24, 2010
    Jekis, May 24, 2010 IP
  14. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Trikun3: I'll try your example a database is not necessarily important that the information on every page was different.
     
    Jekis, May 24, 2010 IP
  15. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="keywords" content="" />
    </head>
    
    <body><table width="900" border="0" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
          <tr>
            <td>&nbsp;</td>
          </tr>
        </table>
    <table width="900" height="136" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td background="head.jpg">    <p><br />
        </p></td>
      </tr>
    </table>
    <table width="900" border="1" align="center" cellpadding="5" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td><a href="index.php?page_id=18">PAGE1</a> |  <a href="index.php?page_id=20 ">PAGE2</a></td>
      </tr>
    </table>
    
     <table width='900' border='1' align='center' cellpadding='5' cellspacing='0' bgcolor='#FFFFFF'>
    
                       <tr>
    		 <td align='left' valign='top' class='cont'>
             <?php
    
    switch($_GET["page_id"])
    {
    case"18":
    include '18.html';
    break;
    }
    
    
    ?>
    		 <?php
    
    switch($_GET["page_id"])
    {
    case"20":
    include '20.html';
    break;
    }
    
    
    ?><br/>
    		 </p>
    
                        </td>
                  </table>
    <table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
    Code (markup):
     
    Last edited: May 24, 2010
    Jekis, May 24, 2010 IP
  16. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #16
    Here's an Example for you!
    Note that its coded by Swashata

    
    
    <?php
    /****************************************
     *Different page through Same PHP script using URL Variables by GET method
     *@author: Swashata Ghosh
     *@copyright: inTechgrity.com
     *@license: Use wherever you want however you can.
    *****************************************/
    
    //Main funciton for the Page layout
    function layout($page_id) {
        switch($page_id) {
            default:
                echo '<p class="red">The page was not found. Showing Home page instead</p>';
            case '':
            case 'home':
                echo '<h2>Welcome to the home page</h2>';
                echo '<p>This is the home page...</p>';
                break;
            case 'about':
                echo '<h2>Welcome to the about page</h2>';
                echo '<p>This is the about page</p>';
                break;
            case 'contact':
                echo '<h2>Welcome to Contact page</h2>';
                echo '<p>This is contact page</p>';
        }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Single index.php PHP script to load different page using URL Variable</title>
        <link rel="stylesheet" type="text/css" href="css/style.css"/>
        <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js' type='text/javascript'></script>
        <script type="text/javascript">
        $(document).ready(function(){
            $('form').css({"display":"none"});
            $('form').fadeIn(600);
        $('input[type="text"], textarea').addClass("idleField");
        $('input[type="text"], textarea').focus(function() {
            $(this).removeClass("idleField").addClass("focusField");
            if (this.value == this.defaultValue){ 
            this.value = '';
        }
            if(this.value != this.defaultValue){
            this.select();
        }
        });
        $('input[type="text"], textarea').blur(function() {
            $(this).removeClass("focusField").addClass("idleField");
            if ($.trim(this.value) == ''){
                    this.value = (this.defaultValue ? this.defaultValue : '');
            }
        });
    
        })
        </script>
    </head>
    <body>
        <h1><a href="http://www.intechgrity.com"><img src="images/logo.png"/>Single index.php PHP script to load different page using URL Variable</a></h1>
        <h2>By Swashata &amp; Pyrotechnicpixie - <a href="http://www.intechgrity.com">InTechgrity</a></h2>
        <div id="swashata">
            <p style="text-align: center; text-decoration: underline;">Pages</p>
            <p style="text-align: center;"><a href="index.php?page=home">Home Page</a> | <a href="index.php?page=about">About Page</a> | <a href="index.php?page=contact">Contact Page</a></p>
            <?php
            $page_id = $_GET['page'];
            layout($page_id);
            ?>
        </div>
        <div id="footer_wrapper">
            <div id="footer">
                <div class="footer_logo"><a href="http://www.intechgrity.com">InTechgrity.com</a></div>
                <div class="menu">
    <a href="http://www.intechgrity.com/">Home</a> | 
    <a href="http://www.intechgrity.com/search/label/%28X%29HTML%20n%20CSS%20Designing">Web Designing</a> | 
    <a href="http://www.intechgrity.com/search/label/PHP%20JS%20n%20Programming">Web Programming</a> | 
    <a href="http://www.intechgrity.com/search/label/SEO%20n%20Adsense">SEO</a> | 
    <a href="http://www.intechgrity.com/2009/03/contact-us-form.html">Contact</a>
                    </ul>
                </div>
                <div class="tutorial">Go Back to <a href="">Tutorial</a></div>
            </div>
        </div>
    </body>
    </html>
    
    
    
    
    PHP:
     
    roopajyothi, May 25, 2010 IP
  17. Jekis

    Jekis Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    All turned out. Thanks a lot for your help. Topic can be closed.!!!!
     
    Jekis, May 25, 2010 IP