Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

[Idiot Mistake] Need Help

Name: Anonymous 2010-06-02 2:02

Ok, So I am using a $_GET function as a main navigation tool. Yes, I am using PHP, I did not come here to get ridiculed, I came here for assistance.

So I have the script something like:

<?php
$page = $_GET['p'];

if ($page == ""){
require 'index.htm';
};

if ($page == "about"){
require 'aboutme.htm';
};

if ($page == "links"){
require 'links.htm';
};
?>

And I have seen this work before, However I am running this off a different server on my own IP address instead of on a host. Basically the error I keep getting is that "p" is not defined. So, simply "page.php" will not load, however "page.php?p" will load. I have never had this happen before. Usually if the $_GET is set to '', then running page.php by itself will just cause the index page to show up instead.

I really don't understand what I did wrong. Please help /prog/.

Name: Anonymous 2010-06-02 2:15

Name: Anonymous 2010-06-02 2:26

if (isset($_GET['p']))
    $page = $_GET['p'];
else
    $page = 'index';


// your shit (which you should make a switch instead)

Name: Anonymous 2010-06-02 2:27

>>1
I am using PHP, I did not come here to get ridiculed
That's a contradiction.

I really don't understand what I did wrong.
If this is too hard for you, you have no business being a programmer.

Name: Anonymous 2010-06-02 2:30

I really don't understand what I did wrong.
Perhaps it's because you use a screen real estate-saving font.

Name: Anonymous 2010-06-02 2:32

>>3
Alternatively, if you like this syntactic sugar such as:
$page = (isset($_GET['p')) ? $_GET['p'] : 'index';

As for the ifs, you could try something like this instead:
switch ($page)
{
    case 'index':
    case 'about':
    case 'links':
        $page .= '.html';
        break;
    default:
        $page = '404.html';
        break;
}
require($page);

etc...

Name: Anonymous 2010-06-02 2:34

>>6
Oh wow. I guess I shouldn't be surprised the PHP designers didn't understand the reasoning behind switch and ended up fucking it up.

Name: Anonymous 2010-06-02 2:36

>>7
I'd have been surprised if it had been any other way.

Name: Anonymous 2010-06-02 2:37

How about you make the actual pages 'index.php', 'aboutme.php', 'links.php'?

I doubt you're going to need a more complicated set-up for a basic, personal 'site' (aka a few pages).

Name: Anonymous 2010-06-02 3:17

[spolier]GAYNIGGER[/spolier] solution

$pages = array('about','links');
$require = (in_array($_GET['p'], $pages)) ? $_GET['p'].'html' : 'indicks.html';
require_once($require);

Name: Anonymous 2010-06-02 3:21

GAYNIGGER

Name: Anonymous 2010-06-02 5:04

>>10-11
* Homosexual African American

Name: Anonymous 2010-06-02 6:45

>>12
Thanks!

Name: Anonymous 2010-06-02 7:48


my $page = url_param('p');
if (-e "$page.$extension") {
        print "Location: /$page.$extension\n\n";
} else {
        error_404();
}

Name: Anonymous 2010-06-02 15:01

<?php
if (isset($_GET['p']))
  $page = $_GET['p'];
else
  $page = "index.htm";

require($page);
?>

Name: Anonymous 2010-06-02 17:03

>>15
page.php?p=/etc/passwd

Name: Anonymous 2010-06-02 17:36

>>16
I believe the OP is running Windows so this is not an issue

Name: Anonymous 2010-06-02 18:40

Just use static pages, please.  Ones which will result in useful headers (modified dates, sizes, etc) being returned to clients; not shitty dynamically-generated pages that serve no purpose other than PHP bragging rights.  And ones which don't use the shitty ?p=whatever added on to the end of the URL.

Name: Anonymous 2010-06-02 18:44

>>18
Static pages are not as flexible. What if you need to change the header or footer? You'd have to do a copy/paste

Name: Anonymous 2010-06-02 18:47

>>19
include('../shared/header.php');

// ...

include('../shared/footer.php');

Name: Anonymous 2010-06-02 19:12

>>20
This is not static. PHP has to fetch header.php and footer.php every time the page is requested. It still has all the problems that >>18 pointed out.

Name: Anonymous 2010-06-02 19:13

>>19
Use a program to generate the static pages.  Save on bandwidth.

>>20
Then the pages aren't static anymore.

Name: Anonymous 2010-06-02 19:14

>>19
Use SSI.

Name: Anonymous 2010-06-02 22:47

>>21
How could dynamically including a common template to a page that is otherwise "static" (in the sense that it is its own file within the server folder structure and not accessed through a RESTful controller) possibly harm the HTTP headers?

Name: Anonymous 2010-06-02 23:38

>>24
the correct timestamp and file sizes probably aren't being sent.

Name: Anonymous 2010-06-02 23:57

Not to mention that dynamically generating output using CPU-hungry PHP code wastes lots of energy and is bad for the environment.

Name: Anonymous 2010-06-03 0:06

The most effective way to handle this would be store a cached version of each PHP page in a database entry, keyed by p= value. Then each page would first check to see if a cache entry for itself exists, and if so, serve that and exit rather than generating the page again. The cache entries would have to be refreshed whenever you made a change to the page, but considering that reads are much more frequent than updates, that would not be a big hardship.

Name: Anonymous 2010-06-03 7:41

Just use <frame>s

Name: Anonymous 2010-06-03 9:17

>>27
You want to keep entire copies of pages in a database? Why not just p= keys and "source" (raw content) and file (static, generated with >>20) locations? If a source is unmodified, just print a Location: /generated-file.php header, otherwise regenerate it beforehand.

Name: Anonymous 2010-06-03 11:57

Make separate files for index.php, links.php, and aboutme.php.

Write them each independently until you find that there are resources you can share. Put that in a file called Template.php, preferably in a folder out of reach from browser clients, but it doesn't really matter.

Inside Template.php, you might have something like this:

<?php

class Template
{
    static function header($title, $stylesheet)
    {
?>

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>My website : <?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" media="screen" href="./../css/main.css">
<link rel="stylesheet" type="text/css" media="screen" href="./../css/<?php echo $stylesheet; ?>">
</head>
<body>
<div id="container">
<h1><?php echo $title; ?></h1>

<?php
    }

    static function footer()
    {
?>

</div>
</body>
</html>

<?php
    }
}


/* EOF */



Then require('./../wherever/Template.php'); at the top of your index.php, aboutme.php, etc. -- anywhere this code is shared:


<?php

require('./../wherever/Template.php');

Template::header('About me', 'aboutme.css');

?>

<div id="hi">Here is my glorious About Me content</div>

<?php

Template::footer();

/* EOF */



And there you have it: a simple, fast, and organized system using php the way it was meant to be used, while continuing to distributing http requests.

Name: Anonymous 2010-06-03 16:03

Name: Anonymous 2010-06-03 18:11

We should think about this PHP templating system some more, I think /prog/ could have a marketable product on its hands.

Name: Anonymous 2010-06-03 19:08

     __                        __
    / / __  _ __ ___   __ _   / /
   / / '_ \| '__/ _ \ / _` | / /
  / /| |_) | | | (_) | (_| |/ /
 /_/ | .__/|_|  \___/ \__, /_/    _                       _____ ___  ___ _____
     |_|              |___/      | |                     /  __ \|  \/  |/  ___|
                  _ __ ___   __ _| | _____  ___    __ _  | /  \/| .  . |\ `--.
                 | '_ ` _ \ / _` | |/ / _ \/ __|  / _` | | |    | |\/| | `--. \
                 | | | | | | (_| |   <  __/\__ \ | (_| | | \__/\| |  | |/\__/ /
                 |_| |_| |_|\__,_|_|\_\___||___/  \__,_|  \____/\_|  |_/\____/

Name: Anonymous 2010-06-03 20:14

CMS MY ANUS

Name: Anonymous 2010-06-03 20:18

THE MOST EFFICIENT WAY TO DO THIS IS TO USE STATIC FILES, NO INCLUDES.

USE SHELL SCRIPTS TO GENERATE THEM IF YOU WANT TO USE SEPARATE HEADERS AND FOOTERS
OR YOU COULD EVEN USE PHP FROM SHELL SCRIPTS IF YOU LIKE.

Name: Anonymous 2010-06-03 20:26

>>35
Why stop there? Why not just write your website in C?

Name: Anonymous 2010-06-03 20:57

>>36
C is too bloated, write it in assembly

Name: Anonymous 2010-06-03 21:53

>>37
Doesn't make sense. The generation process is likely to be disk-bound: the bottleneck will be the speed at which you can fetch files off disk, concatenate them and write them to the output directory. Choosing Assembly over C will not give you any significant gains there.

Name: Anonymous 2010-06-03 23:53

>>38
It's just a stock answer for whenever someone suggests writing a website in C, you weren't supposed to take it seriously.

Name: Anonymous 2010-06-04 2:54

>>38
YHB seriously T

Name: Anonymous 2010-06-04 5:20

>>40
Is this where we go wooosh and you delete your comment before the downvotes begin?

Name: Anonymous 2010-06-04 7:36

What is this shit? PerlHP?

<html>
  <body>
    <h1>[=$title=]</h1>
    <table>
<?pl my $i = 0; ?>
<?pl for my $item (@$items) { ?>
<?pl     my $color = ++$i % 2 == 0 ? '#FFCCCC' : '#CCCCFF'; ?>
      <tr bgcolor="[==$color=]">
        <td>[==$i=]</td>
        <td>[=$item=]</td>
      </tr>
<?pl } ?>
    </table>
  </body>
</html>

Name: Anonymous 2010-06-04 9:06

>>42
use Markup::Perl;

Name: Anonymous 2010-06-04 18:13

>>39-40
    

Name: Anonymous 2010-06-04 19:01

>>42
PerlHP actually uses <% %>[1]

[1]http://wakaba.c3.cx/perlhp/

Name: Anonymous 2010-06-04 19:04

PerlHPython

Name: Anonymous 2010-06-04 19:27

PerlHaskellPython

Name: Anonymous 2010-06-04 19:31

<?perlhaskellpython
  main =
    do
      num <- <>
      print(fix . sub { \f,x -> if x<=1 then 1 else x*f(x-1)} $ num)
        ?>

Name: Anonymous 2010-06-04 19:32

>>48
Also, it must be rendered in a proportional font, since that is the correct way to program PHP

Name: Anonymous 2010-06-04 21:35

>>49
False.  There is no correct way to program PHP.

Name: Anonymous 2010-06-04 22:07

Jesus Christ, IHBT by all of you.

The first response should have been:

Yes, I am using PHP, I did not come here to get ridiculed, I came here for assistance.
Now you have three problems.

Name: Anonymous 2010-06-04 23:38

>>51
I'm sorry we could not conform strictly to your memetic standards.  Perhaps you would be more comfortable on one of 4chan's many friendly and predictable imageboards.

Name: Anonymous 2010-06-04 23:53

>>52
It seem's that >>51-san some how predicte'd you're troll post much before you create'd it. Intriguing!

Name: Anonymous 2010-06-05 4:26

Here is some simple code I use. Pages go in /data/page/

/data/page.php:

<?php
    chdir('data/page');
    include($_GET['page'].'.html');
?>


/index.php:

<?php
    if ($_GET[act] != "") {
        include('data/'.$_GET['act'].'.php');
    }
    else {
        $_GET[page] = 'home';
        include('data/page.php');
    }
?>

Name: Anonymous 2010-06-05 9:51

>>54
You, sir, are a faggot.  Just use normal HTML!

Name: Anonymous 2010-06-05 14:36

Meh, actualy thats stripped down from what I use. What I use adds in headers and footers.

Name: Anonymous 2010-06-05 14:40

>>54
Unsanitized used of $_GET
{b.i.o.u QUINTESSENTIAL PHP USER}

Name: ​​​​​​​​​​ 2010-09-09 13:41

Name: Anonymous 2011-02-03 6:16

Don't change these.
Name: Email:
Entire Thread Thread List