PHP Redirect Function
After form submission or a page redirect is triggered, it's commonplace to redirect the user to a different page or to the same page, formatted in a different way. Usually, you'd complete this by coding:
header('Location: destination.php');
exit();
This is a completely acceptable way to code your pages, but I prefer to use a redirect function instead. Why? It's much more readable, and quite honestly, I'm tired of writing the header('Location: ...');
code.
function redirect($url, $permanent = false) {
if($permanent) {
header('HTTP/1.1 301 Moved Permanently');
}
header('Location: '.$url);
exit();
}
This function is incredibly easy to use and saves a lot of code.
![7 Essential JavaScript Functions]()
I remember the early days of JavaScript where you needed a simple function for just about everything because the browser vendors implemented features differently, and not just edge features, basic features, like addEventListener
and attachEvent
. Times have changed but there are still a few functions each developer should...
![Create a CSS Flipping Animation]()
CSS animations are a lot of fun; the beauty of them is that through many simple properties, you can create anything from an elegant fade in to a WTF-Pixar-would-be-proud effect. One CSS effect somewhere in between is the CSS flip effect, whereby there's...
![Detect DOM Node Insertions with JavaScript and CSS Animations]()
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API.
![Create Tiny URLs with TinyURL, MooTools, and PHP]()
Since we've already figured out how to create TinyURL URLs remotely using PHP, we may as well create a small AJAX-enabled tiny URL creator. Using MooTools to do so is almost too easy.
The XHTML (Form)
We need an input box where the user will enter...
Do you use a plugin to highlight and format your php code?
I’m pretty sure he uses:
http://code.google.com/p/syntaxhighlighter/
Shawn’s correct — you can go to the URL above to download the javascript and CSS files. I’m not using a WordPress plugin though — it’s easy to install on your own.
Cool, I like the features it has over my current solution that I am using.
Thanks.
Ahm… As you’re already talking about the syntaxhighlighter… Why is the little “copy code”-snippet copying code AFTER it says “the code is in your clipboard now”!? Wouldn’t it make sense to copy it before the JS alert?
Well, anyway – nice website Dave! I like it – and all the little code snippets are really nice. So simple, but helping a lot. Sometimes it’s harder to create them “the easy way”, so this really comes in handy. Thanks!
Nice and thanx
You can use highlight_string() in PHP to hightligt your code, or highlight_file()…
http://php.net/manual/en/function.highlight-string.php
when i use this–>
it respondes like
Warning: Cannot modify header information – headers already sent by (output started at C:\wamp\www\New2\4.php:1) in C:\wamp\www\New2\4.php on line 3
what shall i do
hey,thats ok
how i moust do if i want to run one of may actions in classes
for example=>
http://localhost:8007/frontend_dev.php/rmsSetupReservation/create
i get this errror message…what is the problem please help me…
Warning: Cannot modify header information – headers already sent by (output started at C:\wamp\www\bv\bookinsert.php:1) in C:\wamp\www\bv\bookinsert.php on line 139
If you have problems with header function :
you can use this line if you are fans of JavaScript ( client side ):
OR , use this line if are not ( server side ):
Sorry for my English :-)
You can run into trouble if you redirect using relative URLs. It should also be noted that
RFC1945 requires a complete absolute URI for redirection, see: http://tools.ietf.org/html/rfc1945
i have problem when i redirect the header location:-
Warning: Cannot modify header information – headers already sent by (output started at /home/adnanakh/public_html/dcncaclub.org/admin/website_insert_back1.php:3) in /home/adnanakh/public_html/dcncaclub.org/admin/website_insert_back1.php on line 18
What’s problem here. anybody can solve this problem.
It’s still working fine.