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.
Link to comment
Share on other sites

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';
}
Link to comment
Share on other sites

:) 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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.