Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Index.php?id=
Bladeq123
post
Post #1





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.12.2008

Ostrzeżenie: (0%)
-----


Witam, mam pytanie jak zrobić że jak wejdę na stronę to żeby czytało od razu np. index.php?id=news
a nie sam index.php

Ten post edytował Bladeq123 8.01.2009, 21:06:56
Go to the top of the page
+Quote Post
Rafal Filipek
post
Post #2





Grupa: Zarejestrowani
Postów: 274
Pomógł: 54
Dołączył: 2.05.2006
Skąd: Nadarzyn

Ostrzeżenie: (0%)
-----


omg, a mozna jasniej ? bo tak z tego co piszesz to moge ci tylko skrobnąc
  1. <?php
  2. $dzial = isset($_GET['id']) ? $_GET['id'] : 'news';
  3. ?>

czyli jak nie ma ustawionego id to zmienna $dzial rowna jest news a jak jes id to normalnie.
Go to the top of the page
+Quote Post
Bladeq123
post
Post #3





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.12.2008

Ostrzeżenie: (0%)
-----


Wklejam to gdzie chce zeby mi czytało zakładki

  1. <?php
  2.    if($_GET['id']=="galeria"){
  3.    include("dane/galeria.html");
  4.    }
  5.  
  6.    if($_GET['id']=="programy"){
  7.    include("dane/programy.html");
  8.    }
  9.  
  10.    if($_GET['id']=="ksiazki"){
  11.    include("dane/ksiazki.html");
  12.    }
  13.  
  14.  
  15.    ?>


i chce zeby jak wejde na strone czytało odrazu index.php?id=news a nie index.php bo tam jest pusto wtedy
Powód edycji: Proszę używać tagu [PHP] do umieszczania kodu PHP.
Go to the top of the page
+Quote Post
Rafal Filipek
post
Post #4





Grupa: Zarejestrowani
Postów: 274
Pomógł: 54
Dołączył: 2.05.2006
Skąd: Nadarzyn

Ostrzeżenie: (0%)
-----


pobaw sie switchem bedzie lepiej
Go to the top of the page
+Quote Post
Strarus
post
Post #5





Grupa: Zarejestrowani
Postów: 339
Pomógł: 12
Dołączył: 22.11.2008

Ostrzeżenie: (20%)
X----


  1. <?php
  2. if(isset($_GET[ 'site' ])){
  3. $site = htmlspecialchars($_GET['site']) .'.inc.php';
  4. if(file_exists($site )){
  5. include( $site );
  6. }else{
  7. echo 'Strona o podanym adresie nie istnieje.';  // jeśli nie ma strony inaczej 404
  8. }
  9. }else{
  10. echo 'Strona główna'; //Domyślnie nie jest index.php?as=asd ale pokazuje sie coś
  11. }
  12. ?>


Sam korzystam (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Bladeq123
post
Post #6





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.12.2008

Ostrzeżenie: (0%)
-----


starsus a wiesz jak zrobic zeby strona wchodzila odrazu na lalala.pl/index.php?id=news
a nie na lalala.pl/index.php

?
Go to the top of the page
+Quote Post
Strarus
post
Post #7





Grupa: Zarejestrowani
Postów: 339
Pomógł: 12
Dołączył: 22.11.2008

Ostrzeżenie: (20%)
X----


dajesz
  1. <?php
  2. header("Location: index.php?site=news");
  3. ?>


Wtedy to dajesz do index.php czy tam htm i on automatycznie przekieruje Cię na ?site=news ja bym to tak zrobił (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Bladeq123
post
Post #8





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.12.2008

Ostrzeżenie: (0%)
-----


a gdzie to mam wkleić?
Go to the top of the page
+Quote Post
Strarus
post
Post #9





Grupa: Zarejestrowani
Postów: 339
Pomógł: 12
Dołączył: 22.11.2008

Ostrzeżenie: (20%)
X----


W head na index.php, a tamto tam gdzie mają się includować strony (1.inc.php 2.inc.php itd.)

index.php
Kod
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
      <meta name="robots" content="index" />
      <meta name="description" content="Tytuł strony" />
      <meta name="keywords" content="Słowa kluczowe" />
      <link rel="shortcut icon" href="favicon.ico" />
      <link rel="stylesheet" type="text/css" href="style.css" />
      <title>Untitled</title>
      <?php
header("Location: index.php?site=news");
?>
</head>

<body>
<p>


</p>
</body>
</html>


indeks.inc.php
Kod
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
      <meta name="robots" content="index" />
      <meta name="description" content="Tytuł strony" />
      <meta name="keywords" content="Słowa kluczowe" />
      <link rel="shortcut icon" href="favicon.ico" />
      <link rel="stylesheet" type="text/css" href="style.css" />
      <title>Untitled</title>
</head>

<body>
<?php
if(isset($_GET[ 'site' ])){
$site = htmlspecialchars($_GET['site']) .'.inc.php';
if(file_exists($site )){
include( $site );
}else{
echo 'Strona o podanym adresie nie istnieje.';  // jeśli nie ma strony inaczej 404
}
}else{
echo 'Strona główna'; //Domyślnie nie jest index.php?as=asd ale pokazuje sie coś
}
?>
</body>
</html>


U mnie to jest tak rozwiązane (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

pozdro

Ten post edytował Strarus 8.01.2009, 21:31:03
Go to the top of the page
+Quote Post
Bladeq123
post
Post #10





Grupa: Zarejestrowani
Postów: 17
Pomógł: 0
Dołączył: 25.12.2008

Ostrzeżenie: (0%)
-----


Dzieki można zamknąć

Masz Piwko :*
Go to the top of the page
+Quote Post
Rafal Filipek
post
Post #11





Grupa: Zarejestrowani
Postów: 274
Pomógł: 54
Dołączył: 2.05.2006
Skąd: Nadarzyn

Ostrzeżenie: (0%)
-----


pomijam bezsensowność tego rozwiązania. dodanie takiej linijki kodu gdziekolwiek bez zadnego warunku czy czegos takiego spowoduje zapetlenie.
Go to the top of the page
+Quote Post
Strarus
post
Post #12





Grupa: Zarejestrowani
Postów: 339
Pomógł: 12
Dołączył: 22.11.2008

Ostrzeżenie: (20%)
X----


a no tak (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) sorki @Bladeq123

  1. <?php
  2. if($_SERVER[PHP_SELF] == index.php) { header("Location: index.php?site=news"); }
  3. ?>


nie jestem za dobry w php ale to chyba zadziała (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
Rafal Filipek
post
Post #13





Grupa: Zarejestrowani
Postów: 274
Pomógł: 54
Dołączył: 2.05.2006
Skąd: Nadarzyn

Ostrzeżenie: (0%)
-----


Boże, widzisz i nie grzmisz. Powiedzcie mi PO CO ROBIC DODATKOWY REQUEST (IMG:http://forum.php.pl/style_emoticons/default/questionmark.gif) dlaczego nie chcecie nauczyć się jak wykorzystywać switcha (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)
Go to the top of the page
+Quote Post
Strarus
post
Post #14





Grupa: Zarejestrowani
Postów: 339
Pomógł: 12
Dołączył: 22.11.2008

Ostrzeżenie: (20%)
X----


w sumie... (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
bartg
post
Post #15





Grupa: Zarejestrowani
Postów: 226
Pomógł: 25
Dołączył: 4.07.2007
Skąd: Berlin

Ostrzeżenie: (0%)
-----


Bez obrazy, ale jak widze ludzi którzy w PHP może znają podstawy (podstaw) ale nie potrafią myśleć...

  1. <?php
  2. $_GET['id'] = isset($_GET['id'])?$_GET['id']:'news';
  3. ?>

Daj na samą górę swojego kodu i będzie śmigać.

PS. SWITCH" title="Zobacz w manualu PHP" target="_manual (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 24.12.2025 - 16:12