PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old May 11th, 2008, 05:58 PM
ford2008 ford2008 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 87 ford2008 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 7 sec
Reputation Power: 1
Thumbs up How would you do this?

how would you create a link in php from one page to another, im guessing the

header ('Location http://www.etc.com');

as im building an index file - i want when the user clicks on a button hyperlink they will be redirected to that other page from within the index.php file

Any thoughts?

thanks everybody

Reply With Quote
  #2  
Old May 11th, 2008, 06:06 PM
ryon420's Avatar
ryon420 ryon420 is offline
Oscar Wilde addict
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2006
Location: Was lost, then found, now lost again.
Posts: 2,820 ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)ryon420 User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 1496 Folding Title: Novice Folder
Time spent in forums: 5 Months 1 Week 2 Days 17 h 54 m
Reputation Power: 879
Send a message via MSN to ryon420 Send a message via Google Talk to ryon420
__________________

Warning, the post above may contain extreme sarcasm, crude language, and code that may confuse amateurs and professionals.


Helpful stuff: Google your question first | Read the rules | How to ask a question | Read the [PHP] manual, it is good for you
Proud supporter of: Philosophorum - "where even the trolls are smart" | Chikyu Hakken - digging for trolls
"Children begin by loving their parents; as they grow older they judge them; sometimes, they forgive them" -- Oscar Wilde.


Reply With Quote
  #3  
Old May 11th, 2008, 06:19 PM
ford2008 ford2008 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 87 ford2008 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 7 sec
Reputation Power: 1
Talking

lol, nah i mean i am including files, how could i create a variable so when the user clicks on the hyperlink and only then the information from the other script will be included within the index file.

as i will have numerous of these below making it easier for my template


condition here??

include("sdadasd.php");


cheers

Reply With Quote
  #4  
Old May 11th, 2008, 09:09 PM
Hammer65's Avatar
Hammer65 Hammer65 is offline
Web Developer/Musician
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Nov 2004
Location: Lincoln Nebraska
Posts: 2,038 Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level)Hammer65 User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 1 Day 22 h 58 m 11 sec
Reputation Power: 578
Send a message via AIM to Hammer65
User interaction is done client side, PHP is run server side. You would have to do this with AJAX which if I understand what you want correctly, would probably be overkill. You can use Javascript and CSS to hide or show content that is written into the HTML document to start with. PHP can write that document, but it's up to Javascript/CSS from there to do anything in response to what the user does.
__________________
"Strange women lying in ponds distributing swords is no basis for a system of government. Supreme executive power derives from a mandate from the masses, not from some farcical aquatic ceremony! Well, but you can't expect to wield supreme executive power just 'cause some watery tart threw a sword at you! I mean, if I went 'round saying I was an emperor just because some moistened bint had lobbed a scimitar at me, they'd put me away!"

Reply With Quote
  #5  
Old May 11th, 2008, 09:21 PM
requinix's Avatar
requinix requinix is offline
requinix|on hiatus
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2007
Location: Here
Posts: 2,459 requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 12398 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 6 Days 3 h 11 m 25 sec
Reputation Power: 386
Send a message via MSN to requinix
If you mean something like index.php?page=one shows one page and index.php?page=two shows another, then it's simple.

$_GET["page"] is the "one" or "two" from above. Just check whether it matches a certain string, and include() the right file if it does.
PHP Code:
<?php

if (!isset($_GET["page"])) $_GET["page"]="index"// default

// the {}s are *required* for the code below, even
// though it's only one statement in each IF
if ($_GET["page"]=="one") {
    include 
"asdf.php";
} else if (
$_GET["page"]=="two") {
    include 
"qwerty.php";
} else { 
// default
    
include "index.php";
}

?>
Comments on this post
lnxgeek agrees!
__________________
Oyashiro-sama...
If something "isn't working" then EXPLAIN WHY. Tell us what it should do, and then what it does do.

PHP Manual (cURL - PCRE regex - references) error_reporting() SQL injection: and mysql_real_escape_string() PHP and cron
Negative0

Reply With Quote
  #6  
Old May 11th, 2008, 09:37 PM
lnxgeek lnxgeek is offline
I AM A GOLDEN GOD
Dev Shed God (5000 - 5499 posts)
 
Join Date: Apr 2003
Location: cannot find symbol: method showLocation()
Posts: 5,401 lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level)lnxgeek User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 11 h 54 m 39 sec
Reputation Power: 685
You're referring to what is commonly known as the front controller pattern. The example requinix provided illustrates this nicely; you can take this one step further and create some rewrite rules in a .htaccess file (if your host serves PHP via Apache) that direct the user to this script via separate URLs, e.g.
Code:
RewriteEngine On
RewriteRule ^one\/?$ index.php?page=one [L]
RewriteRule ^two\/?$ index.php?page=two [L]


So the users access these via
yourdomain.com/ (default action)
yourdomain.com/one (index.php?page=one)
etc

As a fallback, if the user tries to access anything else, they will be shown the default page, e.g.
yourdomain.com/foo (still shows the default index)
__________________
BookMooch.com : Give books away. Get books you want.

Reply With Quote
  #7  
Old May 12th, 2008, 12:41 PM
ford2008 ford2008 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 87 ford2008 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 7 sec
Reputation Power: 1
cheers thanks a lot everybody for your help, managed to do it sucessfully first go, no errors which is a first!!!

Reply With Quote
  #8  
Old May 12th, 2008, 02:03 PM
ford2008 ford2008 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 87 ford2008 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 7 sec
Reputation Power: 1
heya, im havin a few problems with the code..

Heya this code is included from another file into the indexadp.php file


Code:
<li><a href="<?php echo WEB_ROOT; ?>indexadp.php">
Home</a></li> 

<li><a href="<?php echo WEB_ROOT;  ?>indexadp.php?page=one" >Category</a></li>

<li><a href="<?php echo WEB_ROOT; ?>indexadp.php?page=two" >Product</a></li> 	  

<li><a href="<?php echo WEB_ROOT; ?>indexadp.php?page=three" >Order</a></li> 	 

<li><a href="<?php echo WEB_ROOT; ?>indexadp.php?page=four" >Shop Config</a></li>

<li><a href="<?php echo WEB_ROOT; ?>indexadp.php?page=six" >User</a></li> 	  

<li><a href="<?php echo $self; ?>?logout" >Logout</a></li>

this is my code as it stands, it comes up with the error:

Parse error: syntax error, unexpected T_LNUMBER


PHP Code:
<?php
if(!isset($_GET["page"]))$_GET["page"]="indexadp";


if(
$_GET["page"]=="one"){ 
include
"\category\list.php"; }

elseif(
$_GET["page"]=="two"){
 include
"\user\list.php"; }

elseif(
$_GET["page"]=="three"){
include
"\config\list.php";
}

include(
"2half.php");
exit();
?>

Last edited by ford2008 : May 12th, 2008 at 03:11 PM. Reason: error occuring

Reply With Quote
  #9  
Old May 12th, 2008, 02:50 PM
thedude2010 thedude2010 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 380 thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level)thedude2010 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 6 Days 1 h 34 sec
Reputation Power: 39
What's this line supposed to do?
PHP Code:
if(!isset($_GET["page"]))$_GET["page"]"indexadp"

is it supposed to be
PHP Code:
if(!isset($_GET["page"]))$_GET["page"]="indexadp"



Quote:
Originally Posted by ford2008
Heya this code is included from another file into the indexadp.php file


Code:
<li><a href="<?php echo WEB_ROOT; ?>indexadp.php">
Home</a></li> 

<li><a href="<?php echo WEB_ROOT;  ?>indexadp.php?page=one" >Category</a></li>

<li><a href="<?php echo WEB_ROOT; ?>indexadp.php?page=two" >Product</a></li> 	  

<li><a href="<?php echo WEB_ROOT; ?>admin/order.php?page=three" >Order</a></li> 	 

<li><a href="<?php echo WEB_ROOT; ?>admin/configidx.php?page=four" >Shop Config</a></li>

<li><a href="<?php echo WEB_ROOT; ?>admin/user.php?page=six" >User</a></li> 	  

<li><a href="<?php echo $self; ?>?logout" >Logout</a></li>

this is my code as it stands, it comes up with the error:

Parse error: syntax error, unexpected T_LNUMBER


PHP Code:
<?php
if(!isset($_GET["page"]))$_GET["page"]"indexadp";


if(
$_GET["page"]=="one"){ 
include
"\category\list.php"; }

elseif(
$_GET["page"]=="two"){
 include
"\user\list.php"; }

elseif(
$_GET["page"]=="three"){
include
"\config\list.php";
}

include(
"2half.php");
exit();
?>

Reply With Quote
  #10  
Old May 12th, 2008, 03:52 PM
requinix's Avatar
requinix requinix is offline
requinix|on hiatus
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2007
Location: Here
Posts: 2,459 requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)requinix User rank is Major (30000 - 40000 Reputation Level)  Folding Points: 12398 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 6 Days 3 h 11 m 25 sec
Reputation Power: 386
Send a message via MSN to requinix
First, don't use backslashes (\) for the include()d files. Use forward slashes (/) instead.

Second: Are you posting all the code? What line number is the error occurring on?

Reply With Quote
  #11  
Old May 12th, 2008, 04:10 PM
ford2008 ford2008 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 87 ford2008 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 43 m 7 sec
Reputation Power: 1
o yea

cool iv changed the slashes and now it comes up with that i cant find include files, guess the addresses are wrong for the include files?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > How would you do this?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off