PDA

View Full Version : PHP Help



Trigs
02-01-2009, 01:29 AM
Is it possible to set a page to redirect but with code before it in PHP? The only way I know of is using header(); but I need to specify a variable first. I don't want the redirect to show up in source either so no JS or HTML redirects.

Edit by Robbie! (Forum Moderator) - Moved to Coding. Please post in the corerct section next time.

Trinity
02-01-2009, 01:48 AM
You can do whatever you want before the header(), as long as there's no output.
So specifying the variable shouldn't be affected.

Calon
02-01-2009, 01:53 AM
<?php
echo 'hi lawl!!!!!!!!2';
header( 'Location: http://www.ggg.com/' );

// The above won't work.

header( 'Location: http://www.ggg.com/' );
echo 'hi lawl!!!!!!!!!!2'; // Remember, this won't be shown anyway.

// Will work, you can escape outputs easily with if statements etc.

if( $variable !== 'null' )
{
echo 'hi lawl!!!!!!!!!!2';
}
else
{
header( 'Location: http://www.ggg.com/' );
}
?>

Trigs
02-01-2009, 03:20 AM
Ah, I didn't know that. Thanks and +rep

Calon
02-01-2009, 03:22 AM
Ah, I didn't know that. Thanks and +rep
Glad I could help. :)

Source
02-01-2009, 10:50 AM
<?php

echo "Single quotes are normally for 1 word strings";
header( "location:http://blah.com/" );

//the above won't work

header( "location:http://www.ggg.com/" );
echo "Single quotes are normally for 1 word strings";

// won't work as the page is terminated after the headers are sent
// you can however do it this way

if( $variable !== NULL ) {
echo "somethingbing";
} else {
header( "location:http://www.ggg.com/" );
}

?>


Welcome to the world of indentation calon, ref strings/variables I always think its better to use "" on strings with more than a single word etc, I may be mis-informed. Location though, does not have a capitol L and looks extremly messy.

Jackboy
02-01-2009, 12:35 PM
Na, I disagree Matt :)

Personal preference. I use two ' when It's plain text/html. I barely use "".

But yeh personal prefs :D

Source
02-01-2009, 01:09 PM
But surely in situations

echo "Hello there {$name}, how are you? Today is {$today}";

its better than

echo 'Hello there ' . $name . ' how are you? Today is ' . $today ;

Jxhn
02-01-2009, 01:31 PM
Na, I disagree Matt :)

Personal preference. I use two ' when It's plain text/html. I barely use "".

But yeh personal prefs :D

Could be a security risk. If you don't use ENT_QUOTES with htmlspecialchars then they remain the same, so if you have BBCode then users can add their own attributes, such as onMouseOver.

I've always put a capital L on Location, I thought that was normal.

Jackboy
02-01-2009, 02:00 PM
Could be a security risk. If you don't use ENT_QUOTES with htmlspecialchars then they remain the same, so if you have BBCode then users can add their own attributes, such as onMouseOver.

I've always put a capital L on Location, I thought that was normal.

Lol I was talking about html output as in the html I DO, not what the user does. Thanks though babes.

Trigs
02-01-2009, 05:07 PM
Uhh so who's right? Calon or Source?

Jackboy
02-01-2009, 05:13 PM
Uhh so who's right? Calon or Source?

Omgosh just use header("Location: url");

Jesus christ.

Source
02-01-2009, 05:25 PM
No use

header("location:http://google.com");

capitals don't go well in coding IMO unless its camelcase. Like fucntion

superCoolFunction

But its personal preference, I'm just fussy and been awkward.

Jackboy
02-01-2009, 05:41 PM
No use

header("location:http://google.com");

capitals don't go well in coding IMO unless its camelcase. Like fucntion

superCoolFunction

But its personal preference, I'm just fussy and been awkward.

Haha i use capital L :P

Trigs
02-01-2009, 05:42 PM
I'm not talking about capitalization, I'm talking about specifying a var before header output

Source
02-01-2009, 06:02 PM
Its nothing too complex




$var = "ANYTHING YOU WANT";

header("location{$var}");



You can do anything you want above the header thats not an output to a browser. This means no other headers, echoing things out etc...

Jackboy
03-01-2009, 10:40 PM
Its nothing too complex




$var = "ANYTHING YOU WANT";

header("location{$var}");

You can do anything you want above the header thats not an output to a browser. This means no other headers, echoing things out etc...

More processing power with the var surely? :P

DeejayMachoo$
08-01-2009, 10:44 AM
No use

header("location:http://google.com");


Mhmm i believe its Location :) I've always used...


<?php

header ("Location: http://google.com/");
?>


But this thread gave me second thoughts so i read the bible...

http://uk2.php.net/header

its Location


Haha i use capital L :P

Correct amondo ;)

(Y) I don't see why you all need to give the guy 50 answers, one is good enough and there both right!

Calon
09-01-2009, 09:25 AM
<?php

echo "Single quotes are normally for 1 word strings";
header( "location:http://blah.com/" );

//the above won't work

header( "location:http://www.ggg.com/" );
echo "Single quotes are normally for 1 word strings";

// won't work as the page is terminated after the headers are sent
// you can however do it this way

if( $variable !== NULL ) {
echo "somethingbing";
} else {
header( "location:http://www.ggg.com/" );
}

?>
Welcome to the world of indentation calon, ref strings/variables I always think its better to use "" on strings with more than a single word etc, I may be mis-informed. Location though, does not have a capitol L and looks extremly messy.
I never indent in browsers, because when I use Tab it leaves the textbox. Already explained from other threads ;), I usually indent like this: http://forum.sa-mp.com/index.php?topic=61893.0



Uhh so who's right? Calon or Source?
We're both right, location:url or Location: url works too. location:url is just a messier way and Source explained it better.

Trigs
10-01-2009, 12:39 AM
Okay I get it already

Someone close this.

Moh
10-01-2009, 12:50 AM
You can't use headers if there's any HTML about the php.

Want to hide these adverts? Register an account for free!