Jump to content

Recommended Posts

<php
$id = strip_tags($_GET['id']);

if ($id) {
echo "No assigned verable or entry verable";
} elseif ($id = "Test") {
echo "This is a Test Page";
}
?>

 

Now would a if ($id) take the user to the no assigned verable if the verable in the url is empty on not asigned a verable of Test?

 

so if index.php?id=Test takes them to this is a test page

but index.php or index.php?id=gobledegoop take them to no assigned verable or entry.

You'd preferrably use the isset function. Here is a (shouldbe) working example:

<?php 
if (isset($_GET['id'])) {
    $id = htmlentities(strip_tags($_GET['id'])); //Should really be this..
    if ($id == "test") {
        echo "Welcome to the test page! ID = test";
    } else {
        echo "ID is not valid, please re-enter"; //If ID = blahwhatever
    }
} else {
    echo 'ID is not defined.';
}
?>

<php
$id = strip_tags($_GET['id']);

if ($id) {
echo "No assigned verable or entry verable";
} elseif ($id = "Test") {
echo "This is a Test Page";
}
?>

 

Now would a if ($id) take the user to the no assigned verable if the verable in the url is empty on not asigned a verable of Test?

 

so if index.php?id=Test takes them to this is a test page

but index.php or index.php?id=gobledegoop take them to no assigned verable or entry.

 

try this one:

 

<?php

$id = strip_tags($_GET['id']);

 

if($id="test1"){

    $id="test1.php";

}else{

  $id="test2.php";

}

?>

<div ><a href="?id=test1">menu test 1</a></div>

<div ><a href="?id=test2">menu test 2</a></div>

 

//include what page will be appear

<?php require_once($id); ?>

 

 

Hope it helps...

try this one:

 

<?php

$id = strip_tags($_GET['id']);

 

if($id="test1"){

    $id="test1.php";

}else{

  $id="test2.php";

}

?>

<div ><a href="?id=test1">menu test 1</a></div>

<div ><a href="?id=test2">menu test 2</a></div>

 

//include what page will be appear

<?php require_once($id); ?>

 

 

Hope it helps...

 

I'd highly unrecommend using this code, as it is a direct entry into a mass amount of problems.

try this one:

 

<?php

$id = strip_tags($_GET['id']);

 

if($id="test1"){

    $id="test1.php";

}else{

  $id="test2.php";

}

?>

<div ><a href="?id=test1">menu test 1</a></div>

<div ><a href="?id=test2">menu test 2</a></div>

 

//include what page will be appear

<?php require_once($id); ?>

 

 

Hope it helps...

 

I'd highly unrecommend using this code, as it is a direct entry into a mass amount of problems.

 

Well the codes of bombsquad and oni-kun is correct, but unnecessary. Well with the code of oni-kun, it used a long method, while with bombsquad's code he's missing one function the isset().

 

Let's analyze the problem:

 

[*] Is the $_GET["id"] set?

[*] If set, is the $_GET["id"] equal to Test?

 

Now, if we make it into coding this would be the solution...

 



if(isset($_GET["id"]) && ($id = htmlentities(strip_tags($_GET['id']))) == "Test") {
echo "This is a Test Page";
} else {
echo "No assigned verable or entry verable";
}

 

Explanation:

- If $_GET["id"] is not set, result would be "No assigned verable or entry verable".

- If we've got set $_GET["id"] but not equal to Test, result would still be "No assigned verable or entry verable".

to make it simplier.

 

- $_GET["id"] should be set and equal to "Test". Which is equal to this condition..

if(isset($_GET["id"]) && ($id = htmlentities(strip_tags($_GET['id']))) == "Test")

- any other situation that does not fall into this condition will have a result "No assigned verable or entry verable".

And at the same time, we set and clean/validate the variable $id.

Well with the code of oni-kun, it used a long method

 

I'd have to say your explanation of code is hardly worth noting, as you're taking my code and compressing it into something E_STRICT would throw an warning on. Shorter = better?

:D I am not taking your code, but I am giving a help. I was a long method type programmer before, but i've learned a lot. Doing such long method could make the next programmer hard to understand the logic of your codes. And that is my, "The way of my programming."

Doing such long method could make the next programmer hard to understand the logic of your codes. And that is my, "The way of my programming."

 

I posted a simple, commented and proper practise of programming that is taught by the manual, you posted a compressed, shortcutted code that returns a PHP warning.  How is that helpful to the OP?

 

..but i've learned a lot

Clearly not from a good source.

I before I posted my code, i've tested it first. And when i tested it above it i place a

ini_set("display_errors", "1");
error_reporting(E_ALL);

to make sure and to check if any of my codes has an error. And it didn't gave me any warnings or errors.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.