Page 2 of 4 FirstFirst 1234 LastLast
Results 11 to 20 of 37

Thread: URLS like: index.php?page=page1 ???

  1. #11
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I have this on my index.php, and it won't work?

    Code:
    <?php
    $page = $_GET[q];
    $queries = array("home","scripts","resources","ie","guestbook","about","projects");
    $results = array("index.php","scripts.php","resources.php","get_firefox.php","guestbook.php","about.php","projects.php");
    for ($i = 0;$i < count($queries);$i++) {
    	if ($page == $queries[$i]) {
    		header("Location: $results[$i]");
    		}
    }
    ?>
    and on my menu.php (which is embedded into my index.php using file_get_contents):
    Code:
    <ul>
    <li><a href="?q=home" id="index">Home</a></li>
    <li><a href="?q=scripts" id="scripts">Scripts</a></li>
    <li><a href="?q=resources" id="resources">Resources</a></li>
    <li><a href="?q=ie" id="get_firefox">Switch From IE</a></li>
    <li><a href="?q=guestbook" id="contact">Guestbook</a></li>
    <li><a href="?q=about" id="about">About</a></li>
    <li><a href="?q=projects">Upcoming Projects</a></li>
    </ul>
    <div class="mheader" id="resources">Top 3 Resources</div>
    <ul>
    <li><a href="http://www.dynamicdrive.com/" target="_blank" title="Dynamic Drive">Dynamic Drive</a></li>
    <li><a href="http://www.javascriptsource.com/" target="_blank" title="JavaScript Source">JavaScript Source</a></li>
    <li><a href="http://www.scriptsearch.com/" target="_blank" title="Script Search">Script Search</a></li>
    </ul>
    <div class="mheader">Funpic</div>
    <ul>
    <li><a href="http://www.funpic.org/">Funpic.org</a></li>
    <li><a href="http://www.funpic.org/forum/webhosting">Funpic Board</a></li>
    </ul>
    - Mike

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    On first glance, looks good.
    Give it a test.

    Also, you fail to specify an else.

    A good php script should always have a default value if someone is trying to hack around your settings, or if an old link points to something that is now invalid, or if the user makes a typo. Otherwise, weird things can happen.

    I would suggest removing "index.php" from the arrary, and using:
    else {header=index.php} (format properly, of course)

    That way, anything that doesn't match will default to the home setting... be it "home", nothing (important as if you just type the page filename, it won't have a value for the get variable), or another non-matching string.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #13
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Try it. It's exactly what I put there:
    http://mburt.mb.funpic.org/
    Once you go to another page, it doesn't work...
    - Mike

  4. #14
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    That's nothing complex.

    In your a tags, you use href="?q=....", and that is simply added to the current URL.

    So... if you're on scripts.php, then... you get script.php?q=...

    Just use <a href="index.php?q=...">

    Or, perhaps, <a href="./?q=..."> which I think (but am not sure) would work the same way.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #15
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I just thought of that *knocks self on head. But still one problem. The "index.php?q=scripts" doesn't appear in the address bar.
    - Mike

  6. #16
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    huh?
    how's that related?
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #17
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Look at Twey's site or blm126's site. I'm pretty sure they use the same method, but when I do it, the page address appears in the address bar. Not the query
    - Mike

  8. #18
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Actually, there's an easier way. If you specify a get variable without a value, it exists within PHP as an empty string, so you can do:
    Code:
    if(isset($_GET['guestbook']))
    However, an URL like /guestbook is still better.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #19
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Quote Originally Posted by Twey
    However, and URL like /guestbook is still better.
    How would I be able to use such a URL?
    - Mike

  10. #20
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Index page in /guestbook directory.
    (Not php)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •