Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , ,

Sponsored Links


How to Redirect to New WebPage in PHP

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 19-04-2012
Member
 
Join Date: Aug 2010
Posts: 39
How to Redirect to New WebPage in PHP

Sponsored Links
Hello I have created subscribers script with the help of PHP on mine website and I am experiencing one issue with this code. I wanted to redirect to new webpage after submitting form but when user click on the submit I get “Thank you for subscribing with us” message and wont redirect to another website. On subscribers script I have user Name and Email, and submit button. When user click on the submit button this has to be redirect to another website. So can anyone suggest on this issue and so that I can solve mine issue. Here is my subscribers script code:

Code:
<?php
extract($HTTP_GET_VARS);
extract($HTTP_POST_VARS);
if($action=="subscribe"){
$id=time();
$rand=rand(10000,1000000000);
if($group!="" && $name!="" && $email!=""){
$vef=explode("@",$email);
if(strlen($vef[0])>="2"&&strlen($vef[1])>="2"){
$lday =date("D d");
$lmonth =date("M");
$lyear =date("Y");
$sdate="$lday-$lmonth-$lyear";
$g=fopen("subscribers/$group/$id$rand&~@&.php","w");
fwrite($g,"<?php \n");
fwrite ($g, '$content="');
fwrite ($g, $name);
fwrite ($g, "|Ä0_è|");
fwrite ($g, $email);
fwrite ($g, "|Ä0_è|");
fwrite ($g, $sdate);
fwrite ($g, "|Ä0_è|");
fwrite ($g, "\"; ?>");
fclose ($g);
echo"<FONT COLOR=blue face=arial>Thank you for subscribing with us</FONT><BR>";
}
}else{
echo"<FONT COLOR=red face=arial>Please fill in the form properly.</FONT><BR>";
}
}
echo "<form method=post action=?action=subscribe>";
echo "<Table width=80%><TR><TD width=15%></TD>
    <TD width=80%>Name
      <input type='text' name='name' title='Enter Your Name' style='font-size:12px'></TD></TR><TR><TD width=15%>&nbsp;</TD><TD width=80%>Email:
        <input type='text' name='email' title='Enter Email Address' style='font-size:12px'></TD></TR><TR><TD width=15%><input type=hidden name=group 

value='$group'><BR><BR></TD><TD width=80%><input type='submit' value='Submit Your Information' style='font-size:18px'></TD></TR></Table>
</form>";

?>

Reply With Quote
  #2  
Old 19-04-2012
Member
 
Join Date: Jul 2011
Posts: 375
re: How to Redirect to New WebPage in PHP

Hello I have seen your code and I think you have not entered the redirect code and so therefore you should try to add proper redirect code on your subscriber’s script and after that let me:
Code:
$url = 'thepageyouwanttogoto.html';
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
Byy doing this you ca solve your issue and when user click on the submit button this will redirect to new webpage which you want.
Reply With Quote
  #3  
Old 19-04-2012
Member
 
Join Date: Aug 2010
Posts: 39
re: How to Redirect to New WebPage in PHP

Hello thanks for the reply and I have tried your code and this helped me with only one browser. After trying your code I have tested with Google chrome and working perfectly without any issue but when I have tried with the Firefox and Internet explorer nothing happens. I have tried the lots of solution but nothing helped me to solve mien issue, I have removed all my cookies and history but doesn’t helped me to solve mine issue. Please suggest me what should I do here is my PHP code:
Code:
<?php

if(!$_POST) exit;

$email = $_POST['email'];
//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    $error.="Invalid email address entered";
    $errors=1;
}
if($errors==1) echo $error;
else{
    $values = array ('name','email','subject','message');
    $required = array('name','email','subject','message');
     
    $your_email = "me@mine.co.uk";
    $email_subject = "Enquiry: ".$_POST['subject'];
    $email_content = "Enquiry message:\n";
    
    foreach($values as $key => $value){
      if(in_array($value,$required)){
        if ($key != 'company') {
          if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
        }
        $email_content .= $value.': '.$_POST[$value]."\n";
      }
    }
     
    if(@mail($your_email,$email_subject,$email_content)) 
    {   
        $url = 'http://www.mine.co.uk/thankyou.html"';
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    } else {
        echo 'ERROR!';
    
    }
}
?>
Reply With Quote
  #4  
Old 19-04-2012
Member
 
Join Date: Mar 2010
Posts: 138
Re: How to Redirect to New WebPage in PHP

Ok I have created the PHP Redirect Script from below method and you can implement this:
First of all You can easily redirect using following code:
Code:
<?php
/* Redirect browser */
header("Location: http://theos.in/");
/* Make sure that code below does not get executed when we redirect. */
exit;
?>
The header() is help send a raw HTTP/1.1 proper and correct header. Header() function. And this function must call after called before any actual output is sent. So therefore the following example will not work:

Code:
<?php
$var="something";
echo "Hello world";
echo $var;
/****************************************************
* Remember that header() must be called before any actual output is sent,
* either by normal HTML tags, blank lines in a file, or from PHP.
*****************************************************/
header("Location: http://theos.in/");
exit;
?>
To create PHP Redirect Code you need to create function called movePage() on sitefunctions.php page. So open the sitefunctions.php file from your website and under that crate the below function and code for:
Code:
function movePage($num,$url){
   static $http = array (
       100 => "HTTP/1.1 100 Continue",
       101 => "HTTP/1.1 101 Switching Protocols",
       200 => "HTTP/1.1 200 OK",
       201 => "HTTP/1.1 201 Created",
       202 => "HTTP/1.1 202 Accepted",
       203 => "HTTP/1.1 203 Non-Authoritative Information",
       204 => "HTTP/1.1 204 No Content",
       205 => "HTTP/1.1 205 Reset Content",
       206 => "HTTP/1.1 206 Partial Content",
       300 => "HTTP/1.1 300 Multiple Choices",
       301 => "HTTP/1.1 301 Moved Permanently",
       302 => "HTTP/1.1 302 Found",
       303 => "HTTP/1.1 303 See Other",
       304 => "HTTP/1.1 304 Not Modified",
       305 => "HTTP/1.1 305 Use Proxy",
       307 => "HTTP/1.1 307 Temporary Redirect",
       400 => "HTTP/1.1 400 Bad Request",
       401 => "HTTP/1.1 401 Unauthorized",
       402 => "HTTP/1.1 402 Payment Required",
       403 => "HTTP/1.1 403 Forbidden",
       404 => "HTTP/1.1 404 Not Found",
       405 => "HTTP/1.1 405 Method Not Allowed",
       406 => "HTTP/1.1 406 Not Acceptable",
       407 => "HTTP/1.1 407 Proxy Authentication Required",
       408 => "HTTP/1.1 408 Request Time-out",
       409 => "HTTP/1.1 409 Conflict",
       410 => "HTTP/1.1 410 Gone",
       411 => "HTTP/1.1 411 Length Required",
       412 => "HTTP/1.1 412 Precondition Failed",
       413 => "HTTP/1.1 413 Request Entity Too Large",
       414 => "HTTP/1.1 414 Request-URI Too Large",
       415 => "HTTP/1.1 415 Unsupported Media Type",
       416 => "HTTP/1.1 416 Requested range not satisfiable",
       417 => "HTTP/1.1 417 Expectation Failed",
       500 => "HTTP/1.1 500 Internal Server Error",
       501 => "HTTP/1.1 501 Not Implemented",
       502 => "HTTP/1.1 502 Bad Gateway",
       503 => "HTTP/1.1 503 Service Unavailable",
       504 => "HTTP/1.1 504 Gateway Time-out"
   );
   header($http[$num]);
   header ("Location: $url");
}
Once done and after that First include sitefunctions.php and then call movePage () as follows:

Code:
<?php
@include("/path/to/sitefunctions.php");
movePage(403,"http://www.cyberciti.biz/");
?>
This has been helped me to solve mine issue and I hope this will help you to solve your issue.
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Redirect to New WebPage in PHP"
Thread Thread Starter Forum Replies Last Post
How to use a url to redirect to different url Harold Elwin Technology & Internet 5 23-01-2011 11:08 PM
How can i redirect the video to a URL? M. Rafi Software Development 4 12-06-2009 11:57 AM
To display webpage inside another webpage Faakhir Technology & Internet 3 24-03-2009 10:59 AM
DNS / redirect email grudge Networking & Security 2 24-09-2008 07:00 PM
Redirect dns or iis? The_cobra666 Windows Server Help 4 05-12-2007 05:47 PM


All times are GMT +5.5. The time now is 07:26 PM.