Jump to content

Page Control


OldManRiver

Recommended Posts

All,

Trying to read through all the manuals to determine how control is returned to the calling page for the following scenario:

[code]<form method=post action=myproc.php>[/code]

without using the

[code]header(Location:mypage.php)[/code]

in the myproc.php file.

Not finding anything!  Anybody help please!

OMR
Link to comment
Share on other sites

[quote author=acdx link=topic=109870.msg443232#msg443232 date=1159470871]
What's the problem with using header()?

Also, you could simply use the form page itself to process the form data.

You're missing some quotation marks there btw.
[/quote]

Well everytime I've tried to use the [b]header[/b] command, the page re-inits and my var values get scrubbed, so can't transfer processed var values, even with [b]global[/b] on for that vars I'm trying to tranfer.

If you have a better way, let me know!

OMR
Link to comment
Share on other sites

[quote author=HuggieBear link=topic=109870.msg443303#msg443303 date=1159478178]
Sorry, I'm lost.  You want to return to the form page after submitting the form?

Regards
Huggie
[/quote]

What I have is:

[b]First Pass:[/b]
[code]          $display_block = "<form action='../scripts/login.php' method='POST'><p><strong>User Login:</strong><br>
            <INPUT TYPE='text' NAME='username'></p><p><strong>Password:</strong><br>
            <INPUT TYPE='password' NAME='password'></p><p>&nbsp;<br>
            <input type=image src='../Images/btn-pale(log).jpg' name=log value=log width=120>
            </form>";[/code]

[b]Second Pass with Success:[/b]
[code]              $display_block = "<font size=-1><b>Welcome $f_name $l_name.
                                <br>Thank you for logging in!</b></font>";[/code]

[b]Second Pass with Failure:[/b]
[code]          $display_block = "<font size=-1><b>Login not successful!</b></font>";[/code]

The $display_block sets on first pass, but does not set on second.  When I use [b]header[/b] it sees the runs as first pass and resets everything, so can not get the transfer.

Should be simple, but it isn't.

OMR
Link to comment
Share on other sites

OK, you're possibly best using just one page here...

Call the page something like login.php and set it up a little like this...

[code]
<?php

// Set any default variables, I've put these here to show you as an example
$username = "HuggieBear";
$password = "myPassword";

// Work out what to do next
if (!isset($_GET['submit'])){ // if it's the first time the page has been called then display the form
  showForm(); // Just a call to the function further down
}
else { // if the submit button's been pushed
  if (($_POST['user'] == $username) && ($_POST['pass'] == $password)){
      echo "Authenticated OK"; // Show this if the submitted username and password match up with what we have
  }
  else {
      echo "We couldn't authenticate you, please try again"; // Show this and the form if they failed to enter the correct details
      showForm();
  }
}

// Function to show the form 
function showForm {
  echo <<<HTML
  <h1>$message</h1>
  <form name="login" action="{$_SERVER['PHP_SELF']}" method="POST">
  <input type="text" name="user">
  <input type="password" name="pass">
  <input type="submit" name="submit" value="submit">
HTML;
}
[/code]

Regards
Huggie

[size=8pt][color=red][b]Note:[/b][/color] This was written on the fly, so may not be 100% accurate but should give you an idea.[/size]
Link to comment
Share on other sites

[quote author=acdx link=topic=109870.msg443326#msg443326 date=1159480915]
How do you know whether a user is logged on or off anyway?
[/quote]

Per complete code as follows:[code]<?php
  // check for required fields from the form
  if (isset($_POST['log'])) {
  //connection to server and select database
require ('../scripts/db_connect.php');
        // create and issue the query
      $sql = "select usr_id, usr_name, usr_pwd from log_user where usr_name =
        '$_POST[username]' AND usr_pwd = '$_POST[password]'";
  $result = mysql_query($sql,$conn) or die(mysql_error());
  if (mysql_num_rows($result) == 1) {
              $f_uid = mysql_result($result, 0, 'usr_id');
            $sql = "select inf_id from user_idx where usr_id=$f_uid";
        $residx = mysql_query($sql,$conn) or die(mysql_error());
              if (mysql_num_rows($residx) == 1) {
                $f_inf = mysql_result($residx, 0, 'inf_id');
              $sql = "select inf_fnam, inf_lnam from user_info where inf_id=$f_inf";
          $resinf = mysql_query($sql,$conn) or die(mysql_error());
              }
              // if authorized, get the value of f_name l_name
              $f_name = mysql_result($resinf, 0, 'inf_fnam');
              $l_name = mysql_result($resinf, 0, 'inf_lnam');
              // set authorization cookie
              setcookie("auth", "1", 0, "/", "localhost @mydomain.com", 0);
              //create display string
              $display_block = "<font size=-1><b>Welcome $f_name $l_name.
                                <br>Thank you for logging in!</b></font>";
echo $display_block;
} else {         
          $display_block = "<font size=-1><b>Login not successful!</b></font>";
//          return;
//          exit;
}
  } else {
          $display_block = "<form action='../scripts/login.php' method='POST'><p><strong>User Login:</strong><br>
            <INPUT TYPE='text' NAME='username'></p><p><strong>Password:</strong><br>
            <INPUT TYPE='password' NAME='password'></p><p>&nbsp;<br>
            <input type=image src='../Images/btn-pale(log).jpg' name=log value=log width=120>
            </form>";
}
?>[/code]

SQL code is working fine, but can't return the $display_block to the calling form!

OMR
Link to comment
Share on other sites

[quote author=HuggieBear link=topic=109870.msg443329#msg443329 date=1159481214]
OK, you're possibly best using just one page here...

Call the page something like login.php and set it up a little like this...

Regards
Huggie

[size=8pt][color=red][b]Note:[/b][/color] This was written on the fly, so may not be 100% accurate but should give you an idea.[/size]
[/quote]

Huggie,

Page is a little more complex. See the page at:

http://www.cleanpoliticalclassifiedrevolution.com/CTest/cleanpcr.php

Just running test there.

OMR
Link to comment
Share on other sites

[quote author=businessman332211 link=topic=109870.msg443338#msg443338 date=1159481915]
Off topic- the site has a good idea, I would suggest unpixelating your image though.

On topic- have no idea
[/quote]

Not a graphics geek, so don't know how!

There is another site along this line at:

www.e-worldpeace.com

But no front page to it, just a forum in the back.

OMR
Link to comment
Share on other sites

OK, you're missing the echo statements... See the comments I've made in your code... marked like this [b]// <----[/b]

[code]<?php
  // check for required fields from the form
  if (isset($_POST['log'])) {
  //connection to server and select database
require ('../scripts/db_connect.php');
        // create and issue the query
      $sql = "select usr_id, usr_name, usr_pwd from log_user where usr_name =
        '$_POST[username]' AND usr_pwd = '$_POST[password]'";
  $result = mysql_query($sql,$conn) or die(mysql_error());
  if (mysql_num_rows($result) == 1) {
              $f_uid = mysql_result($result, 0, 'usr_id');
            $sql = "select inf_id from user_idx where usr_id=$f_uid";
        $residx = mysql_query($sql,$conn) or die(mysql_error());
              if (mysql_num_rows($residx) == 1) {
                $f_inf = mysql_result($residx, 0, 'inf_id');
              $sql = "select inf_fnam, inf_lnam from user_info where inf_id=$f_inf";
          $resinf = mysql_query($sql,$conn) or die(mysql_error());
              }
              // if authorized, get the value of f_name l_name
              $f_name = mysql_result($resinf, 0, 'inf_fnam');
              $l_name = mysql_result($resinf, 0, 'inf_lnam');
              // set authorization cookie
              setcookie("auth", "1", 0, "/", "localhost @mydomain.com", 0);
              //create display string
              $display_block = "<font size=-1><b>Welcome $f_name $l_name.
                                <br>Thank you for logging in!</b></font>";
echo $display_block;
} else {         
          $display_block = "<font size=-1><b>Login not successful!</b></font>";
          echo $display_block; // <---- This was missing
//          return;
//          exit;
}
  } else {
          $display_block = "<form action='../scripts/login.php' method='POST'><p><strong>User Login:</strong><br>
            <INPUT TYPE='text' NAME='username'></p><p><strong>Password:</strong><br>
            <INPUT TYPE='password' NAME='password'></p><p>&nbsp;<br>
            <input type=image src='../Images/btn-pale(log).jpg' name=log value=log width=120>
            </form>";
            echo $display_block; // <---- This was also missing
}
?>[/code]

Does that help at all?

Huggie
Link to comment
Share on other sites

[quote author=HuggieBear link=topic=109870.msg443333#msg443333 date=1159481525]
I didn't realise you had code already written  :D lol

I'll take a look now.

Regards
Huggie
[/quote]

H,

Echo statements are in the [b]form[/b] file!  Do you need source or can you glean from URL?

You can see the $display_block sets in the first pass and you see the input fields and the Login button.

OMR
Link to comment
Share on other sites

it would be easier for you to get this to work if you would just write out the form in html, maybe even php, but you are making almost everything that is going to hit the screen into a function, it would be easier to keep it simple, for what you are trying to do you could rewrite it in a neater, simpler way and chances are you would fix all of your problems.
Link to comment
Share on other sites

Ohhhh.... Lost my head for a minute.

In that case add the following to the top of every page before you output anything to the browser:
[code=php:0]session_start();
[/code]

Change each instance of $display_block to $_SESSION['display_block'];

Then on the form page type:
[code=php:0]echo $_SESSION['display_block'];
[/code]

Easiest way to take things like that between pages is through session variables.

Regards
Huggie
Link to comment
Share on other sites

[quote author=businessman332211 link=topic=109870.msg443344#msg443344 date=1159482173]
off topic again- I saw your other site, I am amazed at one thing, you have some good ideas behind the sites you are building.
[/quote]
Trying to get both these working right.

Forum works good at e-worldpeace.com, but need more substance.

Substance is OK on cleanpoliticalclassifiedrevolution.com, but code bombs.

Need to fix both, so all are happy!

OMR
Link to comment
Share on other sites

Huggie,

Followed your advise, but now getting an error, which I'm lost on.

Take a look at the error from the URL and please advise!

I put the session_start(); in the [b]form[/b] file but must not be at the right place or maybe it conflicts with something [b]godaddy[/b] is putting up there?

Uploaded the form file, so you can look!

Had it in the proc file at first, and that blew chunks too!

Thanks!

OMR

[attachment deleted by admin]
Link to comment
Share on other sites

ok, is session_start() at the top of all the pages?

This error is common if you're sending something to the browser before you call session_start().

I tend to make it the first thing on every page by default, e.g.

[code]
<?php
session_start();
include('header.php');
include_once('connect.php')

echo <<<HTML
<html>
<head>
  .....
?>
[/code]

If that's not the case, then maybe you could post the first say 25 lines of code for me.

Regards
Huggie
Link to comment
Share on other sites

[quote author=HuggieBear link=topic=109870.msg443367#msg443367 date=1159484599]
ok, is session_start() at the top of all the pages?

This error is common if you're sending something to the browser before you call session_start().

I tend to make it the first thing on every page by default, e.g.

[code]
<?php
session_start();
include('header.php');
include_once('connect.php')

echo <<<HTML
<html>
<head>
  .....
?>
[/code]

Regards
Huggie
[/quote]

Huggie,

Made it the first line in the code, and now get a blank page, basically.  Look and see!

OMR
Link to comment
Share on other sites

[quote author=HuggieBear link=topic=109870.msg443369#msg443369 date=1159485032]
Is that a frame at the top of the page?

Huggie
[/quote]
H,

Naw! Customer signed this up with GoDaddy on a paid account, so not supposed to have the ads, but won't kick there butt for config'ing the domain wrong to get a clean page.

Think it's a javascript!

OMR
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.