Jump to content

Can PHP Take The Place Of JavaScript Page Redirects?


JustinK101

Recommended Posts

Hello All,

I am wondering if you guys know of a way to do page redirects with purely php? Currently I do all my redirects with javascript:

[code]

  document.location = 'my_new_url';

[/code]

I do redirects a lot, for example in scripts that preform a delete action of a record in the database. I usually have a link that points to a page of almost purely PHP, which after it does the mysql delete query it simply redirects page to the previous page. I do this a lot.

Firstly, is this bad technique? Do you guys find yourself doing a decent amount of page redirects?

Secondly, is there a solution in php that is easy to do redirects?

Thanks much.
Yeah that's what I have seen before, but that solution doesnt work for me. It is no good. Often times I do If statements and conditionals and decide to do the redirect depending. Also, often I do work, such as update a database, or create a record in a database, and then want to redirect.

Example:
if(mysql_num_rows($result) > 0)
{
   echo 'DO JAVA SCRIPT REDIRECT CODE';
}
else
{
   echo 'DO JAVA SCRIPT REDIRECT CODE DIFFERENT PAGE';
}
:) LOL Ok my example did'nt show that there is generally HTML above that. Ok, I suppose I have my answer gotta use JavaScript. I understand why PHP can only interact with the header, server sided. Javascript still cant be beat for some features, such as this, and alert(), and some error checking.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.