PHP URL variables and if statement

Reply

Join Date: Jul 2005
Posts: 3
Reputation: i love my vans is an unknown quantity at this point 
Solved Threads: 0
i love my vans i love my vans is offline Offline
Newbie Poster

PHP URL variables and if statement

 
0
  #1
Jul 5th, 2005
Hey Everyone! ( <-- First Post, Wow)

Well i want use a URL variable like this...

[PHP]www.site.co.uk/index.php?page="about"[/PHP]

With me so far? Ok.

Now when the user enters the index.php page, i want specific content loaded into a preset table, in the case above it would be the about page, but if the link were to be www.site.co.uk/index.php?page="download" the download page would load.

I already have this code snippet to display and external PHP file...

[PHP]<?php include ("http://www.site.co.uk/content/about.php"); ?>[/PHP]

But i want to be able to change the end bit from /about.php, so it would be like this....

www.site.co.uk/content + insert url variable here + .PHP

See what i mean.
Any help would be greatly appreciated.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: PHP URL variables and if statement

 
0
  #2
Jul 5th, 2005
http://somedomain.com/index.php?page=download

index.php:
[PHP]
<?php

if (!isset($_GET['page']) {
$page = "about"; // Default page
} else {
$page = $_GET['page'];
}

include ("/content/".$page.".php");

?>
[/PHP]
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: i love my vans is an unknown quantity at this point 
Solved Threads: 0
i love my vans i love my vans is offline Offline
Newbie Poster

Re: PHP URL variables and if statement

 
0
  #3
Jul 5th, 2005
Cheers buddy, looks good, am about to go out so will test as soon as i get back in.

Cheers, ILMV
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 10
Reputation: val542 is an unknown quantity at this point 
Solved Threads: 0
val542 val542 is offline Offline
Newbie Poster

Re: PHP URL variables and if statement

 
0
  #4
Jul 5th, 2005
You should put:
[PHP]
<?php

if (!isset($_GET['page']) {
$page = "about"; // Default page
} else {
$page = $_GET['page'];
}

include ("content/".$page.".php");

?>
[/PHP]

remove the slash '/' before content!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: PHP URL variables and if statement

 
0
  #5
Jul 5th, 2005
val542 is correct in that most likely, your webroot is not the root of the server, so in the example code I posted, I should have left the beginning slash off. However, the code I posted is not inaccurate--it is legal code. That is, you could make the root of your server be your DocumentRoot--in which case "/content/" may be a valid path.

val542, a little more thorough reply would be more helpful.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: i love my vans is an unknown quantity at this point 
Solved Threads: 0
i love my vans i love my vans is offline Offline
Newbie Poster

Re: PHP URL variables and if statement

 
0
  #6
Jul 5th, 2005
Um, error....

Parse error: parse error, unexpected '{' in e:\domains\m\meltdownsoftware.co.uk\user\htdocs\test web\about\index.php on line 63

Line 63 of my code is arrowed below

[PHP]<?php

if (!isset($_GET['page']) { <---------------
$page = "download"; // Default page
} else {
$page = $_GET['page'];
}

include ("content/".$page.".php");

?>[/PHP]

Any ideas?
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: PHP URL variables and if statement

 
0
  #7
Jul 5th, 2005
If the error in that line is not obvious to you, I have to ask how long you've been programming. I'm not trying to be rude, but seriously, it's simply a case of unbalanced parenthesis. Change the line to this:
[php]if (!isset($_GET['page'])) {[/php]
Sorry I posted code that was not error-free, though.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 20
Reputation: Narayan15 is an unknown quantity at this point 
Solved Threads: 0
Narayan15 Narayan15 is offline Offline
Newbie Poster

Re: PHP URL variables

 
0
  #8
Nov 23rd, 2008
i need help in php
<?php
$num=2;
?>
<a href="action.php?id='.$num.'">Text to be displayed</a>

Here i m not getting $num value when i print echo $_GET['id'];
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 20
Reputation: Narayan15 is an unknown quantity at this point 
Solved Threads: 0
Narayan15 Narayan15 is offline Offline
Newbie Poster

Re: PHP URL variables and if statement

 
0
  #9
Nov 23rd, 2008
Please help me
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: PHP URL variables

 
0
  #10
Nov 23rd, 2008
Originally Posted by Narayan15 View Post
i need help in php
<?php
$num=2;
?>
<a href="action.php?id='.$num.'">Text to be displayed</a>

Here i m not getting $num value when i print echo $_GET['id'];
Here is a tiny bit of PHP that will better demonstrate the logic. Instead of a link, I used a textbox in a form so you could actually change the ID to see that the code works. Create a page named test.php like this:
  1. <?php
  2. $id = (isset($_GET['id']) ? $_GET['id'] : 2);
  3. ?>
  4.  
  5. ID: <?= $id ?>
  6. <br />
  7. <form method="GET" action="test.php">
  8. <input type="text" name="id" size="3" value="<?= $id ?>" />
  9. <input type="submit" />

For a short time, you can see this code in action here:
http://www.troywolf.com/tmp/test.php
Last edited by Troy; Nov 23rd, 2008 at 10:58 am.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC