Link Problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

cooldownguy86
New php-forum User
New php-forum User
Posts: 4
Joined: Wed Nov 20, 2002 2:59 pm
Contact:

Link Problem

Postby cooldownguy86 » Fri Nov 22, 2002 3:41 pm

Hello all php pro
I am having some problem, when i type goto.php?id=home in my browser, the page that pops up uses the goto.php title which is GB' rather that the suppost home.php title which is home.Why?
Is there any better function than include to open a new page?
Below are my codes for goto.php.
//
<html>
<head>
<title>GB'</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php $id=$_GET['id']; if($id=="home") {include "home.php";}
$id=$_GET['id']; if($id=="story") {include "story.php";}
$id=$_GET['id']; if($id=="characters") {include "characters.php";}
$id=$_GET['id']; if($id=="manga") {include "manga.php";}
$id=$_GET['id']; if($id=="gallery") {include "gallery.php";}
$id=$_GET['id']; if($id=="downloads") {include "downloads.php";}
$id=$_GET['id']; if($id=="links") {include "links.php";}
$id=$_GET['id']; if($id=="contact") {include "contact.php";}
$id=$_GET['id']; if($id=="storyleft") {include "storyleft.php";}
$id=$_GET['id']; if($id=="storyright") {include "storyright.php";}
$id=$_GET['id']; if($id=="charactersleft") {include "charactersleft.php";}
$id=$_GET['id']; if($id=="charactersright1") {include "charactersright1.php";}
$id=$_GET['id']; if($id=="charactersright2") {include "charactersright2.php";}
$id=$_GET['id']; if($id=="banmido") {include "banmido.php";}
$id=$_GET['id']; if($id=="ginjiamano") {include "ginjiamano.php";}
$id=$_GET['id']; if($id=="hevn") {include "hevn.php";} ?>
</body>
</html>
//

nike
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Sep 06, 2002 7:59 am
Location: Ukraine
Contact:

Postby nike » Sat Nov 23, 2002 3:02 am

Hello!

This is absolotely ok to use Includes. I think this is a best way.
But (to my mind) you can change your script to look this way:


Code: Select all

......
<?php
$id=$_GET['id'];
if($id=='home') include 'home.php';
if($id=='story') include 'story.php';
if($id=='characters') include 'characters.php';
.......
if($id=='ginjiamano') include 'ginjiamano.php';
if($id=='hevn') include 'hevn.php';
?>
...........


I mean that there is no need to write $id=$_GET['id']; before every IF.
And it this case it is better to use ' than " bacause it takes more time to parse " than '.

Or better than if (in your case) it is better to use SWITCH

Code: Select all

switch ($id) {
    case 'ginjiamano':
        include 'ginjiamano.php';
        break;
    case 'hevn':
        include 'hevn.php';
        break;
    case ''characters'':
        include 'characters.php';
        break;
.......
}


Also if you must open pages from another site you can use CURL module:

Code: Select all


    $ch = curl_init ("$path/show.php");

// Receiving data from Script

    $data=curl_exec ($ch);
    if (!$data){
   echo curl_error($ch);
    }



Bereza Nikita
Rapid Internet Development Department
E-mail: nike@alarit.com
Alar Information Technologies,
URL: http://www.alarit.com

mjr
New php-forum User
New php-forum User
Posts: 18
Joined: Fri Sep 27, 2002 6:35 am
Contact:

Re: Link Problem

Postby mjr » Sat Nov 23, 2002 3:57 am

cooldownguy86 wrote:Hello all php pro
I am having some problem, when i type goto.php?id=home in my browser, the page that pops up uses the goto.php title which is GB' rather that the suppost home.php title which is home.Why?
Is there any better function than include to open a new page?
Below are my codes for goto.php.


the best way is

Code: Select all

<?php
 $id=$_GET['id']; 
  switch($id){
    case 'home':
      $fname='home.php';
      break;
    case 'story':
      $fname='story.php';
      break;
    default:
       $fname='index.php';
}
header("Location: $fname");
exit;
?>


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest