play_
-
Posts
717 -
Joined
-
Last visited
-
Days Won
1
Posts posted by play_
-
-
[quote author=kenrbnsn link=topic=100247.msg395492#msg395492 date=1152662141]
Why don't you put the session_start() at the very start of the header.php, that way you don't even need the ob_start().
Ken
[/quote]
I actuall just tried that. and took out the header() in the login, and put index.php in the form action. but it is still not working. -
[quote author=ShogunWarrior link=topic=100247.msg395489#msg395489 date=1152661923]
I think (think) that there may (may) be a conflict between session_start() and ob_start() but that's speculation, plucking at straws here.
[/quote]
I has never given me a problem though. I don't think that is it.
::edit::
I took out ob_start() and still a no-go. -
god, i really hope it isnt something too simple that'll make me feel stupid.
-
header:
[code]
<?php
ob_start();
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="includes/pirate.css" />
<script type="text/JavaScript">
<!-- AJAX call -->
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP")
}
function getData(datafile, divID) {
if (XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", datafile);
XMLHttpRequestObject.onreadystatechange = function() {
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
<!-- Menu RollOver Images
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="top" height="136" colspan="10"> header </td>
</tr>
<tr>
<td valign="top" class="menu"> <!--menu -->
<center>
<div class="menu_header"></div>
<a href="index.php?content=home" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('home','','images/menu/home_hover.jpg',1)"><img src="images/menu/home.jpg" alt="Home" name="home" width="67" height="26" border="0" id="home" /></a><br />
<a href="index.php?content=news" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('news','','images/menu/news_hover.jpg',1)"><img src="images/menu/news.jpg" name="news" width="55" height="21" border="0" id="news" /></a><br />
<a href="index.php?content=about" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('about','','images/menu/about_hover.jpg',1)"><img src="images/menu/about.jpg" name="about" width="47" height="20" border="0" id="about" /></a><br />
<a href="#" onclick="getData('about.php', 'main_content')" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('calendar','','images/menu/calendar_hover.jpg',1)"><img src="images/menu/calendar.jpg" name="calendar" width="67" height="20" border="0" id="calendar" /></a><br />
<a href="index.php?content=forums" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('forums','','images/menu/forums_hover.jpg',1)"><img src="images/menu/forums.jpg" name="forums" width="59" height="19" border="0" id="forums" /></a><br />
<a href="index.php?content=email" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('email','','images/menu/email_hover.jpg',1)"><img src="images/menu/email.jpg" name="email" width="50" height="19" border="0" id="email" /></a><br />
<a href="index.php?content=crew" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('crew','','images/menu/crew_hover.jpg',1)"><img src="images/menu/crew.jpg" name="crew" width="84" height="24" border="0" id="crew" /></a><br />
<a href="index.php?content=extras" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('extra','','images/menu/extrastuff_hover.jpg',1)"><img src="images/menu/extrastuff.jpg" name="extra" width="102" height="20" border="0" id="extra" /></a>
</center>
<div class="menu_footer"></div>
</td><!--/menu -->
<td valign="top">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 82px; height: 65px; background-image: url('images/main content/main_content_top_left.jpg');"></td>
<td align="left" style="height: 65px; background-image: url('images/main content/top_span.jpg');"></td>
<td style="width: 82px; height: 65px; background-image: url('images/main content/main_content_top_right.jpg');"></td>
</tr>
<tr>
<td style="width: 82px; background-image: url('images/main content/vertical_span_left.jpg');"></td>
<td id="main_content">[/code]
Index:
[code]
<?php
require_once('./includes/header.php');
@$id = $_GET['content'];
switch ($id) {
case 'home':
include('./home.html');
break;
case 'news':
include('./news.php');
break;
case 'about':
include('./about.html');
break;
case 'calendar':
include('./calendar.html');
break;
case 'home':
include('./forums.forums');
break;
case 'email':
include('./email.html');
break;
case 'crew':
include('./crew.html');
break;
case 'extras':
include('./extra.html');
break;
default:
include('./home.html');
break;
}
echo $_SESSION['username'];
require_once('./includes/footer.php');
?>[/code]
and i use ob_end_flush() in the footer.
ps: i know the use of tables for layout is lame/looked down on. but trust me, i had to use tables because css was in no way, shape or form cooperating. -
hehe. yes ive tried refreshing.
but still. ive never had this problem, i dont know why its happening now. -
Yes. I have session_start(); in the header.php which is included in index.php.
according to php.net, "Use of session_register() is deprecated" so i try not to use it. But i used it for testing and no luck.
Now, if i take out the header() and echo the session on the same (login) page, it works. like this:
[code]
if ( ($num >= 1) && ($row[1] === $username) && ($row[2] === $password) ) {
$_SESSION['username'] = $username;
$_SESSION['user_id'] = $row[0];
echo $_SESSION['username'];
#header("Location: index.php");
} else {
echo 'Log-in failed';
}[/code]
-
Ok.
I've done this alot, and it always worked beautifully, but this time it isnt working.
A log in form, and if all is correct, sessions are started.
[code]if (isset($_POST['submit'])) {
require ('connection script');
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT user_id, username, password FROM table WHERE username = '$username' AND password = '$password'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$num = mysql_num_rows($result);
if ( ($num >= 1) && ($row[1] === $username) && ($row[2] === $password) ) {
session_start();
$_SESSION['username'] = $username;
$_SESSION['user_id'] = $row[0];
header("Location: index.php");
} else {
echo 'Log-in failed';
}
}[/code]
I get redirected to index.php.
But in index.php, i try echoing $_SESSION['username'] but i get:"Notice: Undefined index" error
It's probably something minimal im missing, but it isn't working.
Sorry if it's too simple. I've actually been reading books in python lately and my php got rusty.
-
HI Barand.
Quick question.
"$tmp = explode('|', wordwrap($text[$i], ceil($l/2), '|'));"
Why explode on | ? -
Thanks red. however, you lost the word "and" in there.
the original array contanis "and i like php freaks"
but "and" isn't in the final array.
Anyhow, here' what im trying to do pretty much.
[code]
$all = array();
// $text is an exploded array with tons of elements inside,
for( $i = 0; $i < count($text); $i++) {
if (strlen($text[$i]) >= 70) {
$text[$i] = chunk_split($text[$i], 70, "\n");
}
$all[] = $text[$i];
};
[/code]
So, what it's doing is, it loops through each element in the $text array, and adds them to the $all array. In the middle of this, it checks every element's length. If an element is larger than 70 characters, i split it with a "\n".
However, what i want to do is split it in 2 and add both halves to the $all array. -
[quote author=AV1611 link=topic=100029.msg394307#msg394307 date=1152524803]
not an expert at this but couldn't you explode the string the resave the array?
[/quote]
I dont think if i did that, they would be inserted at the end of of the array -
Well, you could assign a variable something and check it on validation.php.
so on register.php, you could do something like
$a = "this var must be set";
then on validation.php, you could check if $a exists, and if it does, does it hold the string "this var must be set".
and you could also do sessions.
or, do all 3 for maximum security. -
Few questions.
1) Is there a function to "flatten" a multidimensional array?
2) is there a way to split an array element into two, giving each its own key?
so for example, if i have:
$a = array( 0 => "hi", 1 => "really long string i need to split into two parts", 2 => "next element", 3 => "etc");
How could i make it so that it turns into:
$a = array( 0 => "hi", 1 => "really long string i", 2 => "need to split into two parts", 3 => "next element", 4 => "etc");
Can it be done?
Using php4 here. so str_split() is not an option for #2 =/ -
Thanks ginger.
I Just actually went to read the manual (function by function in the 'strings' category) until i reached chunk_split() and it seems to work fine so far. -
I need to insert some characters at a certain position in a string.
for example:
$str = "12345678";
so at position 8, i would want to insert a '9'.
i've tried str_pad() but it isn't doing the job.
and substr_replace() would work fine IF it didn't actually replace the other charatcers, just inserted them in there.
ps: i just noticed how the title of this thread doesn't make much sense. sorry about that. it's 8:30am and i have yet to sleep.
-
Yes Ken, Thank you.
The only thing is, when you hightlite the code with the mouse, the numbers on the left get highlited too.
So, since i am almost done with my version of this, ill try to finish it (plus, feels better when you make something 100% yourself you know). But if i can't, then i will use your version. Indeed it is smaller and simpler.
Thanks again ken.
::edit::
Yea, ill use this with some modifications.
Thanks again. -
[quote author=Crayon Violent link=topic=99597.msg392310#msg392310 date=1152160131]
i think because here:
$number = substr_count($text, $words); // number of times $words(<br />) occurs in $text (text pulled from d...
$number isn't counting your \n's?
[/quote]
it because when it outputs, the text is longer than the <div> holding it, therefore it creates a new line on the fly, adding on to the ones being pulled from the database.
Im gonna try to find a fix for this, if anyone knows, let me know. =D -
Also, i tried what you said, putting double quotes around \n.
it ALMOST worked, here's the result
[img]http://img.photobucket.com/albums/v425/play/help/b84005ba.jpg[/img]
the last few lines aren't showing numbers. -
Hello Ken,
On my site, i plan on posting the sourcecode of some scripts i have made.
I have a form that sends it right to the database.
When retrieved from the database, i'd like to have it formatted like in the pictures above.
the number of lines on the left, and the script on the right. -
back. It doesn't work quite as expected. I am using highlight_string(), here's whats happening.
this script:
[code]$text = $news;
$words_to_count = array('\n');
echo'
<table border=1 width=100%>
<tr>
<td valign=top>';
$found = 1;
foreach($words_to_count as $words) {
// the $number + 1 part is so the numbers on the left align the lines on the right.
// if it wasn't there, there would be one more line than a number.
// take it out and see what happens.
$number = substr_count($text, $words); // number of times $words(<br />) occurs in $text (text pulled from db).
while ($found <= $number + 1) {
echo $found++ . '<br />';
}
}
echo '
</td>
<td>' . highlight_string($text,1) . '</td>
</tr>
</table>';[/code]
outputs this:
[img]http://img.photobucket.com/albums/v425/play/help/f187b70d.jpg[/img]
So what is a fix to this?
I need to find \n instead of <br />'s... -
Ok i got it.
here's what i wanted to do:
[code]
$text = nl2br($news);
$words_to_count = array('<br />');
echo'
<table border=1 width=100%>
<tr>
<td valign=top>';
$i = 1;
foreach($words_to_count as $words) {
$number = substr_count($text, $words);
while ($i <= $number + 1) {
echo $i++ . '<br />';
}
}
echo '
</td>
<td>' . $text . '</td>
</tr>
</table>';[/code]
Here's what it does:
[img]http://img.photobucket.com/albums/v425/play/help/fff97c1b.jpg[/img]
It adds a number to the left after each line.
Perfect if you plan on posting a script of yours on your site.
However, if anyone knows of a simpler way of doing this, let me know.
Thanks -
Hi!
I pulled an entry from the database, and i need to count how many \n or <br />'s there are.
I've tried using this:
[code]
$text = row['news'];
$chart = count_chars($text, 1);
foreach($chart as $letter=>$frequency) {
echo "Character ".chr($letter). "<br />";
}
[/code]
Jus to display each character. I get this result:
Character
Character
Character
Character a
Character b
Character d
Character e
Character f
Character h
Character i
Character k
Character l
Character n
Character o
Character p
Character r
Character s
Character t
Character u
Character y
As you can see, the first two are spaces. So i am guessing the first one is regular space ( ) and the other one is a new line or <br />.
Kinda lost where to go from here. :(
so let's say i wanna do a loop of how many times <br /> or \n was found.
$i = 0;
loop {
if found, $i++;
}
-
Ah, it worked.
Thanks wildteen. =) -
thanks. i think i have tried that but i dont think it worked. ill go try.
-
say you have:
.div_name a {
... ...
}
which would set properties for the links in that div.
but, can you do the same thing with images?
Form Validation with Preg_Match getting an error at the end
in PHP Coding Help
Posted
take out the ; before the echo