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:
  #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: 159 ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 8 h 7 m 6 sec
Reputation Power: 16
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
Comp. Sci. version of Dr House
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2006
Location: Was lost, then found, now lost again.
Posts: 3,744 ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)ryon420 User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 1496 Folding Title: Novice Folder
Time spent in forums: 7 Months 3 Weeks 4 Days 9 h 55 m 38 sec
Reputation Power: 1908
Send a message via MSN to ryon420 Send a message via Google Talk to ryon420
__________________
"And what, Socrates, is the food of the soul?

Surely, I said, knowledge is the food of the soul." -- Plato

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: 159 ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 8 h 7 m 6 sec
Reputation Power: 16
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,225 Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level)Hammer65 User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 3 Weeks 3 Days 12 h 13 m 8 sec
Reputation Power: 764
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
No strings attached
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 4,627 requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 20 h 51 m 36 sec
Reputation Power: 1898
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!
__________________
How to ask a question

Reply With Quote
  #6  
Old May 11th, 2008, 09:37 PM
lnxgeek lnxgeek is offline
I AM A GOLDEN GOD
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Apr 2003
Location: Ventura, California
Posts: 5,885 lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level)lnxgeek User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 21 h 44 m 44 sec
Reputation Power: 1033
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)
__________________
"Seriously, we're not a search engine, we're actual people." ~ ManiacDan

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: 159 ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 8 h 7 m 6 sec
Reputation Power: 16
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: 159 ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 8 h 7 m 6 sec
Reputation Power: 16
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: 454 thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 h 44 m 55 sec
Reputation Power: 55
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
No strings attached
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 4,627 requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 20 h 51 m 36 sec
Reputation Power: 1898
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: 159 ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level)ford2008 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 8 h 7 m 6 sec
Reputation Power: 16
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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT