Jagarm Posted October 27, 2008 Share Posted October 27, 2008 Hello, Having the following php code: if(!is_numeric($_GET['n'])) { header("Location: /movies"); } I am checking if the value I get is numeric, and if is not then redirect user to a specified page. But for some reason it does not work, the if statement does get executed because I tried with an echo and it works, but no redirection. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/ Share on other sites More sharing options...
The Little Guy Posted October 27, 2008 Share Posted October 27, 2008 is this file in the same directory as this executing file? Yes: if(!is_numeric($_GET['n'])) { header("Location: movies"); } No: if(!is_numeric($_GET['n'])) { header("Location: ../../movies"); // each "../" stands for: up one level } Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675609 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 Ok, first off show us all the code , second off i think you have errors suppressed and have html before this header therefore it wont work, add error_reporting(E_ALL); to the top of the page and ini_set("errors",1); (i think) Edit: Little guy , i think he said it isn't redirecting, not that it is redirecting to a 404 Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675610 Share on other sites More sharing options...
revraz Posted October 27, 2008 Share Posted October 27, 2008 Hard to say if he isn't displaying errors. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675613 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 is this file in the same directory as this executing file? Yes: if(!is_numeric($_GET['n'])) { header("Location: movies"); } No: if(!is_numeric($_GET['n'])) { header("Location: ../../movies"); // each "../" stands for: up one level } Thanks a lot for your replies First the reason is /movies is because it becomes like this http://beta.berwari.net/movies so when doing /movies that is assumed. and yes that is on the same folder. <?php if(!is_numeric($_GET['n'])) { header("Location: http://beta.berwari.net"); } That is the very top of the file. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675618 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 Please read my post if you want the help Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675623 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 Yes that is right, it does not redirect, it's like that doesn't exist. I tried to put a echo there and it does go into that statement. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675624 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 Hi Blade280891, Thanks for helping me, I did add that error stuff at the top and I don't see anything about header and redirection Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675625 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 Ok, can you post the whole code for the page so we can see what the error might be. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675629 Share on other sites More sharing options...
The Little Guy Posted October 27, 2008 Share Posted October 27, 2008 Ok, can you post the whole code for the page so we can see what the error might be. or at least the stuff above the code. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675637 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 here is the code minus header and footer. <?php if(!is_numeric($_GET['n'])) { header("Location: /movies"); }else { @require_once(ROOT."/inc/config.php"); $id = $_GET['n']; $result = mysql_query("SELECT * FROM movies WHERE id=$id"); if($row=mysql_fetch_array($result)){ }else { header("Location: /"); } } ?> <h1>Manage Movies</h1> <br /> <form name="editmovies" method="post" action="/manage_movies"> <table cellspacing="0" cellpadding="0" class="frame"> <tr> <td colspan="2" class="name" style="text-align:center"><input name="name" type="text" size="40" maxlength="100" value="<?=$row['moviename']?>" /></td> </tr> <tr> <td colspan="2" class="description" style="text-align:center"><textarea name="desc" id="desc" cols="45" rows="3"><?=$row['moviedesc']?></textarea></td> </tr> <tr> <td class="duration" style="text-align:left"><input type="text" name="duration" id="duration" /></td> <td class="date" style="text-align:right"><input type="text" name="date" id="date" value="<?=$row['postdate']?>" /></td> </tr> <tr> <td colspan="2" style="text-align:center"><input type="submit" name="btnEdit" id="btnEdit" value="Edit Movie" /></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675656 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 Lolz, sorry to say that it is most likely the header that is causing the problem, move your code to the top of the page. There can't be any HTML before the code if there is it won't work and should produce an error (if you turned error reporting on) Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675663 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 That's all right, Thanks a lot for trying. I'll find another way Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675673 Share on other sites More sharing options...
revraz Posted October 27, 2008 Share Posted October 27, 2008 HTML or Javascript Redirect. But with errors being displayed, it would tell you that a header can't be sent. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675761 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 revraz you just gave me an idea. I haven't tried using javascript, and I'm using javascript and works. Thanks for reminding me Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675822 Share on other sites More sharing options...
Andy-H Posted October 27, 2008 Share Posted October 27, 2008 javascript can easily be disabled... Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675828 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 oh yea, ur right, damn lol. Anyways we'll have it like that for now, until there is a solution to this. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675831 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 here is a cheat put ob_start(); at the top of the code in the header. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-675869 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 here is a cheat put ob_start(); at the top of the code in the header. I tried that, but I think how my site is setup, it goes in a never ending loop, so I can't use that. Index.php is the controller of the web site, so any request goes through index.php. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-676045 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 You will need to re think your coding logic then. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-676048 Share on other sites More sharing options...
Jagarm Posted October 27, 2008 Author Share Posted October 27, 2008 I'm trying to change the logic by avoiding the loop when using the ob_start but I don't know what to do anymore. I've tried almost everything. Here are my stuff... Following is my htaccess code. The following code redirects everything to index.php, so if I do berwari.net/music it just like berwari.net/index.php?display=music. So therefore index.php is the controller. RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^(.*)$ index.php?display=$1 [L,QSA] The controller. <?php session_start(); ob_start(); error_reporting(E_ALL); ini_set("errors",1); if (!isset($_GET['display'])){$_GET['display']="";} switch(strtolower($_GET['display'])){ case "music": define("ADMIN",false); define("TITLE","Berwari.net > Music"); define("FILE","music.php"); break; case "contact": define("ADMIN",false); define("TITLE","Berwari.net > Contact Us"); define("FILE","contact.php"); break; case "about": define("ADMIN",false); define("TITLE","Berwari.net > About Us"); define("FILE","aboutus.php"); break; case "movies": define("ADMIN",false); define("TITLE","Berwari.net > Movies"); define("FILE","movies.php"); break; case "downloads": define("ADMIN",false); define("TITLE","Berwari.net > Downloads"); define("FILE","downloads.php"); break; case "links": define("ADMIN",false); define("TITLE","Berwari.net > Useful Links"); define("FILE","links.php"); break; #---- Admin Stuff Begins ---- case "admin": define("TITLE","Berwari.net > Admin Section"); define("FILE","admin/main.php"); break; case "manage_movies": define("ADMIN",true); define("TITLE","Berwari.net > Admin Section > Manage Movies"); define("FILE","admin/manage_movies.php"); break; case "manage_downloads": define("ADMIN",true); define("TITLE","Berwari.net > Admin Section > Manage Movies"); define("FILE","admin/manage_downloads.php"); break; case "admin_logs": define("ADMIN",true); define("TITLE","Berwari.net > Admin Section > Logs"); define("FILE","admin/logs.php"); break; #---- Admin Stuff Ends ---- case "": define("ADMIN",false); define("TITLE","Berwari.net > Home"); define("FILE","main.php"); break; } //if the user tries to get into admin area that //has admin as true then they'll be taken to /admin where they have to login if (ADMIN==1){ if ($_SESSION['ADMINL']!=md5('Secret')){ header("Location: /admin",); } } @include_once(ROOT."/inc/head.php"); //header @include_once(ROOT."/inc/sidebar.php"); //sibemenu echo "<div id=\"column2\">"; @require_once(FILE); //the body ?> </div> <?php @include_once(ROOT."/inc/footer.php"); //Footer?> Thank you all! Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-676151 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 From near the first line i noticed if (!isset($_GET['display'])){$_GET['display']="";} Wtf? It doesn't make sense you are not doing anything in that line, except it should produce an error. I changed your code a bit <?php error_reporting(E_ALL); ini_set("errors",1); ob_start(); session_start(); //if (!isset($_GET['display'])){$_GET['display']="";} It does nothing if(isset($_GET['display']))//check if the get var display is present, to stop errors { switch(strtolower($_GET['display'])){ case "music": define("ADMIN",false); define("TITLE","Berwari.net > Music"); define("FILE","music.php"); break; case "contact": define("ADMIN",false); define("TITLE","Berwari.net > Contact Us"); define("FILE","contact.php"); break; case "about": define("ADMIN",false); define("TITLE","Berwari.net > About Us"); define("FILE","aboutus.php"); break; case "movies": define("ADMIN",false); define("TITLE","Berwari.net > Movies"); define("FILE","movies.php"); break; case "downloads": define("ADMIN",false); define("TITLE","Berwari.net > Downloads"); define("FILE","downloads.php"); break; case "links": define("ADMIN",false); define("TITLE","Berwari.net > Useful Links"); define("FILE","links.php"); break; #---- Admin Stuff Begins ---- case "admin": define("TITLE","Berwari.net > Admin Section"); define("FILE","admin/main.php"); break; case "manage_movies": define("ADMIN",true); define("TITLE","Berwari.net > Admin Section > Manage Movies"); define("FILE","admin/manage_movies.php"); break; case "manage_downloads": define("ADMIN",true); define("TITLE","Berwari.net > Admin Section > Manage Movies"); define("FILE","admin/manage_downloads.php"); break; case "admin_logs": define("ADMIN",true); define("TITLE","Berwari.net > Admin Section > Logs"); define("FILE","admin/logs.php"); break; #---- Admin Stuff Ends ---- case "": define("ADMIN",false); define("TITLE","Berwari.net > Home"); define("FILE","main.php"); break; } } //if the user tries to get into admin area that //has admin as true then they'll be taken to /admin where they have to login if (ADMIN==1) { if ($_SESSION['ADMINL']!= md5('Secret')) { header("Location: /admin",); } } include_once(ROOT."/inc/head.php"); //header include_once(ROOT."/inc/sidebar.php"); //sibemenu echo "<div id=\"column2\">"; require_once(FILE); //the body echo "</div>"; include_once(ROOT."/inc/footer.php"); //Footer ?> Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-676168 Share on other sites More sharing options...
Jagarm Posted October 28, 2008 Author Share Posted October 28, 2008 Blade280891 Thanks a lot I'll give that a try, about //if (!isset($_GET['display'])){$_GET['display']="";} I was testing something out apparently I forgot to remove it Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-676194 Share on other sites More sharing options...
DeanWhitehouse Posted October 28, 2008 Share Posted October 28, 2008 Ok,it still would of done nothing lolz. But i think my code will show any errors now. Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-676200 Share on other sites More sharing options...
Jagarm Posted October 28, 2008 Author Share Posted October 28, 2008 While capturing the http header when the site goes in a loop: I get the following: HTTP/1.1 302 Moved Temporarily Date: Tue, 28 Oct 2008 00:16:57 GMT Server: Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 X-Powered-By: PHP/5.2.6 Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Location: /music Keep-Alive: timeout=15, max=100 Connection: Keep-Alive Transfer-Encoding: chunked Content-Type: text/html The expiry date has not been specified anywhere and also the response from server is 302. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/130281-solved-php-header-regirect/#findComment-676203 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.