ASPit - Totally ASP
 

Go Back   PHPit Forums > General PHP > Just Starting
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
Old 07-07-2006, 12:20 AM   #1
RobD
Junior Member
 
Join Date: Jul 2006
Posts: 16
Default PHP HREF Example needed

What's wrong with this code please:

if (DG_ACTION == 'details'){

echo '';

}

I just want to redirect to a new page when DG_ACTION = 'details'.

Thanks,
Rob
RobD is offline   Reply With Quote
Old 07-07-2006, 12:53 AM   #2
saintsr
Junior Member
 
Join Date: Jun 2006
Location: Atlanta GA USA
Posts: 23
Send a message via Yahoo to saintsr
Default

try the header function. http://us2.php.net/manual/en/function.header.php

something like:

header('Location: http://localhost/Talonhenge/birddetails.php');



.
saintsr is offline   Reply With Quote
Old 07-07-2006, 01:50 AM   #3
RobD
Junior Member
 
Join Date: Jul 2006
Posts: 16
Default

Tried that...I'm getting the following error when I do it

Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\Talonhenge\docs1.php:8) in C:\Program Files\xampp\htdocs\Talonhenge\docs1.php on line 111

This is what I originally used:

header( 'Location: http://localhost/Talonhenge/birddetails.php',true ) ;

This is what's at line 8:



Thanks.
RobD is offline   Reply With Quote
Old 07-07-2006, 02:33 AM   #4
saintsr
Junior Member
 
Join Date: Jun 2006
Location: Atlanta GA USA
Posts: 23
Send a message via Yahoo to saintsr
Default

Quote:
Originally Posted by RobD
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\Talonhenge\docs1.php:8) in C:\Program Files\xampp\htdocs\Talonhenge\docs1.php on line 111

yep, while I am far from an expert, I know that that means you've already started sending output to be displayed. even a simple ECHO that comes before header function will cause that error.

if there is no way to avoid the output (and PHP was designed to be embedded in the output), you could try something like:

PHP Code:
$url "birddetails.php"
echo 
"\n"
"document.location.href='".$url."';\n"
"\n"


.
saintsr is offline   Reply With Quote
Old 07-07-2006, 10:19 AM   #5
RobD
Junior Member
 
Join Date: Jul 2006
Posts: 16
Default

That did it!. Thanks alot!
RobD is offline   Reply With Quote
Old 07-07-2006, 12:00 PM   #6
rvdavid
Ambitious Member
 
rvdavid's Avatar
 
Join Date: Jun 2006
Location: Sydney, Australia
Posts: 26
Default

A sematic alternative (although it's a little bit of a hack) is to use ob_start() at the start of your page and ob_end_flush(); at the end of your page.

PHP Code:

// start buffering output
ob_start();
define('DG_ACTION','details');
echo 
'doing something to output to screen'

if (
DG_ACTION == 'details') { 
    
// set the header location to be a different page
    
header('Location: http://localhost/Talonhenge/birddetails.php');
    
// exit out of the script after setting the header
    
exit;
}

// display output
ob_end_flush();
?>

I say that it's a bit of a hack because you should have all page controlling functionality handled before anything is sent to be displayed to the browser.

HTH

Regards,
__________________
R. Villar David
Web Developer
http://rvdavid.blogspot.com/
rvdavid is offline   Reply With Quote
Old 07-07-2006, 03:21 PM   #7
RobD
Junior Member
 
Join Date: Jul 2006
Posts: 16
Default

R.Villar David
I figured I would need to control page and db access at the beginning. I'm somewhat new to web development. Would you happen to have some standard script available that shows some general guidelines on page security. If not, can you point me to a reference .

Thanks.
RobD is offline   Reply With Quote
Old 07-09-2006, 12:08 PM   #8
rvdavid
Ambitious Member
 
rvdavid's Avatar
 
Join Date: Jun 2006
Location: Sydney, Australia
Posts: 26
Default

I can't say that I have scripts that you can learn from, I write all PHP code in Classes and methods, programming more in the Object Oriented Paradigm rather than Procedural at this stage.

I do however have some tips for you

For starters - Google is your friend

Search results for "PHP Guidelines"

Another good link http://phpsec.org/php-security-guide.pdf from http://phpsec.org/

Now these below are not about security or anything like that, but, they are some guidelines that have helped me out when I was first starting out.

Thinking semantics - first rule would be to separate presentation (HTML/XHTML) and business(php code which acquires data from databases, coditional statements anything that isn't echoing out prepepared temporary variables) logic separate.

An acronymn that will get you started: DRY = Don't Repeat Yourself.

If you find that you are copying and pasting all the time, then you are doing something wrong. Either place repetitive code into functions (Procedural) or classes (Object Oriented).

Use Versioning Software (CVS or SubVersion/SVN). Why? because it helps you manage versions of your code. Especially now that you are trying to learn new things and experimenting.

Learn Unit Testing. This is more for OOP, but it does work for Procedural if this is the paradigm of your choice.

These are a few of the general guidelines that I've been given when I was starting out. If you have any specific questions feel free to ask.

How these help you out, good luck with it.

Regards,
__________________
R. Villar David
Web Developer
http://rvdavid.blogspot.com/
rvdavid is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Forum Jump


All times are GMT. The time now is 06:56 PM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2006, Jelsoft Enterprises Ltd.