markyoung1984 Posted May 7, 2008 Share Posted May 7, 2008 I have a PHP page called login and there is a function in there that (subject to certain conditions), I want to navigate to another PHP page automatically, as if clicking a href link. I have no idea how to do this. Can anyone help? Link to comment https://forums.phpfreaks.com/topic/104537-navigating-to-a-new-php-page/ Share on other sites More sharing options...
sushant_d84 Posted May 7, 2008 Share Posted May 7, 2008 Hi you can use 1) Redirection using header function 2) You can use the JavaScript for redirecting 3) You can use the include function for including next/other php page in current page.!!! Try this and let me know whethere this works for you!? Regards Sushant Danekar Link to comment https://forums.phpfreaks.com/topic/104537-navigating-to-a-new-php-page/#findComment-535103 Share on other sites More sharing options...
markyoung1984 Posted May 7, 2008 Author Share Posted May 7, 2008 Basically whats happening is the following: - A user goes to adminctrl.php This script checks if they are logged in using session variables. If they are not logged in, the user is taken to login.html - The user enters their details on login.html and clicks the LOGON button, which then calls the login.php script. - The login.php script checks the database to validate they are a user (which all works). If they are not a user the login.html is displayed again and the cycle repeats. That is not a problem. However, when they are a valid user, I want to go back to adminctrl.php When I use header ("Location: adminctrl.php"); nothing happens, same with include_once. Code in login.php that checks if the user can login to the database: $gateway = new DatabaseGateway($username, $password); //form new db constructor $logonCheck = $gateway->attemptLogon(); //attempt to logon to the database if($logonCheck == 0) //then login was successful { //echo ('Logon to database was successful'); //I WANT THE ADMINCTRL.PHP TO LOAD HERE } else { echo ("You have not entered the correct username and password"); } However, when I uncomment the echo statement and use the header() function, I get the following: Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\vdtwebexperimentation\login.php:23) in C:\xampp\htdocs\vdtwebexperimentation\login.php on line 24 I have no idea what is going on! Please help. Link to comment https://forums.phpfreaks.com/topic/104537-navigating-to-a-new-php-page/#findComment-535106 Share on other sites More sharing options...
gnawz Posted May 7, 2008 Share Posted May 7, 2008 Hi I wonder why you would want the user to go to adimctrl.php after successful log in, any way: You can put a link for them to click on successful login or (automatically) u can use HTML meta tags for redirecting the user. get back if you get into trouble Link to comment https://forums.phpfreaks.com/topic/104537-navigating-to-a-new-php-page/#findComment-535113 Share on other sites More sharing options...
markyoung1984 Posted May 7, 2008 Author Share Posted May 7, 2008 How could I have been so stupid???? It didn't even occur to me to put a link in and then link back. That works fine now. However, I would like to know how I could do this using the META tags you mentioned... Link to comment https://forums.phpfreaks.com/topic/104537-navigating-to-a-new-php-page/#findComment-535137 Share on other sites More sharing options...
saint959 Posted May 7, 2008 Share Posted May 7, 2008 hi, you could do it this way. the content is the amount of time to refresh. so you could display a message saying "You have logged in successfully, you will now be directed to the secure site" or something <?php print "<meta http-equiv=\"refresh\" content=\"2; url=http://www....\">"; ?> Link to comment https://forums.phpfreaks.com/topic/104537-navigating-to-a-new-php-page/#findComment-535148 Share on other sites More sharing options...
gnawz Posted May 7, 2008 Share Posted May 7, 2008 Hi, There are a couple of meta tags. These tags are placed in the head section of an HTML page. thay are sued to decribe metadata of a web page' they are useful in SEO or telling web page robots how they should behave. The structure of a meta tag is name, content,action(or description). For example a meta tag to describe the various keywords you want a page to be referenced with in a search eg google is conctructed as follows: let's say the site is about relationships; <meta name="keywords" content="love, lovelife, sextime, the beautiful,kiss her, kiss him"/> These are the words that will return that particular page with that meta description should one search.. ANYWAY There is one meta tag that is defined with a "refresh" For your case you could echo it php after successful login thus: <?php echo ' <http-equiv="refresh" content="2";URL="adminctrl.php">'; ?> You can even add a mesasge <? echo' Login successful! You will now be redirected to the ........ page now'; echo ' <http-equiv="refresh" content="2;URL="adminctrl.php">'; ?> Note: Content defines the re-direct delay in seconds. In some PHP versions, 5 or lower you write secods with 2 zeros ie content ="500" for 5 seconds Play around with this.. I hope it helps Get back if you run into trouble. Cheers Link to comment https://forums.phpfreaks.com/topic/104537-navigating-to-a-new-php-page/#findComment-535169 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.