Jump to content

cookies/session


neverbegosu

Recommended Posts

Ok guys heres the deal.  I have been struggling on this for about two weeks and am giving up.

Because I'm giving up, I would like to throw this up to you guys to help me out.

 

I am trying to build a login

I tried learning sessions but they make no sense to me whatsoever on how the information passes from one to another.  So i created my own sessions database, where im uploading the data i need to pass page to page to my db, and repulling it on the next page.  In order to do this i needed to create a cookie so I can refrence that data on the next page, main.php.

When I run main.php i get an the echo of. "THIS COOKIE AINT FUCKING WORKING". which to me means one of two things.  One is either im not creating the cookie right, or two, im not accessing it correctly.  But to widdle that down I created the testpoint on if cookie is created and it seems to work fine, cuase im not getting the die().

 

Im not an advance php programmer by any means,  just been self learning for a few months, so bear with me and please break it down as much as possible.  I feel that if i can just get a userid created on one page, put it into a cookie, send it, and retreive it when on the next page, i can do the rest from there.  If you can see why that is happening then let me know.

 

Thanks in advance. 

NEVERBEGOSU

 

 

----------------------------------

index.php

-------------

<?php
include ('srvdbcon.php');
include ('functions/sitebuild.php');
include ('functions/functions.php');
setcookie('user', 'mike');
login();

headcontent();

headermain();

leftcontent();
?>


<div id="content">
   <div class="post">   
   <h1 class="title"><a href="#">Welcome to  </a></h1><p class="byline">21 April 2011 by <a href="#"></a></p>
      <div class="entry">
      <p><strong></strong> is a free, 100% Starcraft 2 Replay Center. Our goal is to provide the ability to UPLOAD replays with detailed data, as well as to DOWNLOAD those replays.  Our Replay Search function is one of a kind, designed by hand to help you find replays that you are looking for.</p>
      <p class="links"><a href="#" class="more">About Us</a></p>
      </div>
   </div>
      
      
   <div class="post">
   <h2 class="title"><a href="#">Latest News</a></h2>
   <p class="byline">Working hard to get the site up and running. <a href="#"></a></p>
      <div class="entry">
      <h3>Looking for late May Release:</h3>
      <blockquote>
      <p>Im working really hard guys. Forgive me for the pushback.</p>
      </blockquote>
      <h3>In Production:</h3>
      <ul>
      <li>Working on a new template for the site.</li>
      <li>Continuing developing the search function for replays.</li>
      <li>In the middle of moving in RL so working hard when I can.</li>
      <li>Working hard on the member login/registration pages.</li>
      <li>Started working on the forums</li>
      </ul>
      <h3>Finished:</h3>
      <ul>
      <li>Got the Upload Page working.</li>
      <li>Completed the Download style for the site.</li>
      <li>Finished a few other smaller aspects.</li>
      </ul>
      <p class="links"><a href="#" class="more">Read More</a></p>
      </div>
   </div>
         
   <div class="post">
   <h2 class="title"><a href="#">LOOKING FOR HELP </a></h2>
   <p class="byline"><small>Posted on 22 Aprl 2011 by <a href="#">SCG.Admin</a></small></p>
      <div class="entry">
      <p> is looking for a few people, if willig, to help design the site. The following positions are needed. </p>
      <ul>
      <li>Graphics Designer</li>
      <li>PHP/MYSQL Programmer</li>
      </ul>
      <p>If anyone is intrested please contact me at .</p>
      <p class="links"><a href="#" class="more">Read More</a></p>
      </div>
   </div>
</div>

<?php

rightcontent1();

echo "<center><h2>Login</h2></center> ";
echo "<form name='log' method='POST' action='" . $PHP_SELF . "'>";
echo "Username:";
echo "<p><input type='text' name='username'>";
echo "<p>Password:";
echo "<p><input type='password' name='password'>";
echo "<p><input type='submit' id='log' name='log' value='Login'>";
echo "<br>";
echo "<h2> Not a Member </h2>";
echo "<p><a href='register.php'>Register</a></p>";
echo "</center>";

rightcontent2();

footerdiv();
?>

-------------------------------------------------------------------------------------------

 

main.php

---------

<?php
include ('srvdbcon.php');
include ('functions/sitebuild.php');

if(!isset($_COOKIE['userid']));
{
die ('CANT GET THE FUKCING COOKIE TO WORK');
}

headcontent();
headermain();
leftcontent();
?>


<div id="content">
   <div class="post">   
   <h1 class="title"><a href="#">Welcome to  </a></h1><p class="byline">21 April 2011 by <a href="#">SCG.Admin</a></p>
      <div class="entry">
      <p><strong></strong> is a free, 100% Starcraft 2 Replay Center. Our goal is to provide the ability to UPLOAD replays with detailed data, as well as to DOWNLOAD those replays.  Our Replay Search function is one of a kind, designed by hand to help you find replays that you are looking for.</p>
      <p class="links"><a href="#" class="more">About Us</a></p>
      </div>
   </div>
      
      
   <div class="post">
   <h2 class="title"><a href="#">Latest News</a></h2>
   <p class="byline">Working hard to get the site up and running. <a href="#">SCG.Admin</a></p>
      <div class="entry">
      <h3>Looking for late May Release:</h3>
      <blockquote>
      <p>Im working really hard guys. Forgive me for the pushback.</p>
      </blockquote>
      <h3>In Production:</h3>
      <ul>
      <li>Working on a new template for the site.</li>
      <li>Continuing developing the search function for replays.</li>
      <li>In the middle of moving in RL so working hard when I can.</li>
      <li>Working hard on the member login/registration pages.</li>
      <li>Started working on the forums</li>
      </ul>
      <h3>Finished:</h3>
      <ul>
      <li>Got the Upload Page working.</li>
      <li>Completed the Download style for the site.</li>
      <li>Finished a few other smaller aspects.</li>
      </ul>
      <p class="links"><a href="#" class="more">Read More</a></p>
      </div>
   </div>
         
   <div class="post">
   <h2 class="title"><a href="#">LOOKING FOR HELP </a></h2>
   <p class="byline"><small>Posted on 22 Aprl 2011 by <a href="#">SCG.Admin</a></small></p>
      <div class="entry">
      <p>SCG.O is looking for a few people, if willig, to help design the site. The following positions are needed. </p>
      <ul>
      <li>Graphics Designer</li>
      <li>PHP/MYSQL Programmer</li>
      </ul>
      <p>If anyone is intrested please contact me at </p>
      <p class="links"><a href="#" class="more">Read More</a></p>
      </div>
   </div>
</div>

<?php
rightcontent1();
rightcontent2();

footerdiv();
?>

----------------

functions.php

<?php

function verifylogin()
{

}

function login()
{
$Login=$_POST['log'];
if ($Login)
{
$username=$_POST['username'];
$password=($_POST['password']);
$verlogin="SELECT * FROM user WHERE user='$username' AND password='$password'";
$verloginq=mysql_query($verlogin);
   if(mysql_num_rows($verloginq)!='0')
   {
   setcookie('userid' , 'mike');
      if (setcookie)
      {   
      $ip = getenv("REMOTE_ADDR"); 
      $time=time();
      $loginquery="INSERT INTO login (id,user,date,ip) VALUES ('','$username','$time','$ip')";
      $loginqueryr=mysql_query($loginquery);
         if ($loginqueryr)
         {
         header("location:testmain.php");
         }
         else
         {
         die('There was a problem sending info to database: LOGIN.');
         }
      }
      else
      {
      die ('Cookie wont set for some damn reason.');}
   }
   else
   {die ('username/password error');}
}
else
{

}
}


function logout()
{

}

function logcook()
{

}

function logsess()
{

}
?>

 

MOD EDIT:

 . . . 

BBCode tags added.

Link to comment
Share on other sites

hey, 

This is a much harder way of doing things.  The best thing to do is use sessions, when you understand them, they are much easier than cookies.

 

have a look at this tutorial on building registration form, inserting the data to a database and then the oher parts look at creating a login page.

 

if you need specific help then get back in touch but this might work better as this tells you how to do.

 

:)

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.